SFTP connection mocked, currency logic fixed

This commit is contained in:
Ivan Nikolaev-Axenov 2024-05-27 18:45:02 +03:00
parent ffa3098650
commit 491577b6f8
13 changed files with 66 additions and 20 deletions

View file

@ -9,6 +9,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.annotation.Gateway;
@ -29,6 +30,7 @@ import org.springframework.messaging.handler.annotation.Payload;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
@Configuration
@Profile("!test")
public class SFTPConfig {
protected Logger log = LoggerFactory.getLogger(getClass());
protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();

View file

@ -0,0 +1,33 @@
package ru.spcex.clearing.xml.exporter.config;
import java.io.File;
import java.util.List;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.integration.sftp.session.SftpFileInfo;
@Configuration
@Profile("test")
public class SFTPTestConfig {
@Bean
@Qualifier("mockSFTP")
public SFTPConfig.XmlGateway xmlGateway(){
return new XGateway();
}
public static class XGateway implements SFTPConfig.XmlGateway{
@Override
public void sendToSftp(File file, String path) {
}
@Override
public List<SftpFileInfo> listFiles(String dir) {
return null;
}
}
}

View file

@ -71,8 +71,8 @@ public class DF02ObjectTag extends ObjectTag<SDf02> {
}
@Override
public String getCurrency(SDf02 entity) {
return entity.getCurr_code();
public String getCurrency() {
return this.currCode;
}
public String getCurrCode() {

View file

@ -88,8 +88,8 @@ public class DF03ObjectTag extends ObjectTag<SDf03> {
}
@Override
public String getCurrency(SDf03 entity) {
return entity.getPay_val();
public String getCurrency() {
return this.payVal;
}
public String getSegType() {

View file

@ -38,7 +38,7 @@ public class DF05ObjectTag extends ObjectTag<SDf05> {
}
@Override
public String getCurrency(SDf05 entity) {
public String getCurrency() {
return ruCurrency;
}

View file

@ -77,8 +77,8 @@ public class DF07ObjectTag extends ObjectTag<SDf07> {
}
@Override
public String getCurrency(SDf07 entity) {
return entity.getPay_val();
public String getCurrency() {
return this.payVal;
}
public String getAccount() {

View file

@ -35,7 +35,7 @@ public class DF51ObjectTag extends ObjectTag<SDf51> {
}
@Override
public String getCurrency(SDf51 entity) {
public String getCurrency() {
return ruCurrency;
}

View file

@ -48,7 +48,7 @@ public class DF53ObjectTag extends ObjectTag<SDf53> {
}
@Override
public String getCurrency(SDf53 entity) {
public String getCurrency() {
return ruCurrency;
}

View file

@ -174,8 +174,8 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
}
@Override
public String getCurrency(SDf54 entity) {
return entity.getPay_val();
public String getCurrency() {
return this.payVal;
}
public String getSegType() {

View file

@ -56,7 +56,7 @@ public class DF56ObjectTag extends ObjectTag<SDf56> {
}
@Override
public String getCurrency(SDf56 entity) {
public String getCurrency() {
return ruCurrency;
}

View file

@ -1,5 +1,6 @@
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import ru.spcex.platform.classes.base.SpcexObjectBase;
@ -16,6 +17,7 @@ import ru.spcex.platform.enumeration.CurrencyCode;
@JsonSubTypes.Type(DF54ObjectTag.class),
@JsonSubTypes.Type(DF56ObjectTag.class),
})
@JsonIgnoreProperties(value = { "clazz", "currency" })
public abstract class ObjectTag<T1 extends SpcexObjectBase> {
public final static String ruCurrency = CurrencyCode.RUB.getKey();
public Class<T1> clazz;
@ -26,5 +28,5 @@ public abstract class ObjectTag<T1 extends SpcexObjectBase> {
public abstract void setData(T1 entity);
public abstract String getCurrency(T1 entity);
public abstract String getCurrency();
}

View file

@ -43,7 +43,7 @@ public class ExportFromHazelcast extends Stage {
public ExportFromHazelcast(ExportXMLServiceSettings settings,
ImdgProvider imdgProvider,
SFTPConfig.XmlGateway gateway,
@Qualifier("mockSFTP") SFTPConfig.XmlGateway gateway,
@Qualifier("xmlMapper") XmlMapper xmlMapper,
@Qualifier("mapOfTable") Map<Table, ObjectTag<? extends SpcexObjectBase>> objectTagMap,
Supplier<KafkaSender> kafkaSender) {
@ -103,6 +103,9 @@ public class ExportFromHazelcast extends Stage {
}
documentTag.setObjects(addObjectTags(tableRows, table));
//todo: rewrite currency logic
currency = ruCurrency;
log.info("DOCUMENT TAG = {}", documentTag);
xmlMapper.writeValue(xmlFile, documentTag);
@ -110,6 +113,9 @@ public class ExportFromHazelcast extends Stage {
path = settings.getStore().getOutPayValDir().get(ruCurrency);
else path = settings.getStore().getOutPayValDir().get(currency);
log.info("settings.getStore().getOutPayValDir().get(ruCurrency): {}", settings.getStore().getOutPayValDir().get(ruCurrency));
log.info("settings.getStore().getOutPayValDir().get(currency): {}", settings.getStore().getOutPayValDir().get(currency));
if (path == null)
throw new Exception("Get unknown currency=" + currency + ", need will be adding settings like 'export-xml-service.store.out-pay-val-dir.RUB=/RUB' and restart app");
writeOk = true;
@ -129,7 +135,7 @@ public class ExportFromHazelcast extends Stage {
}
} else {
log.debug("uuid {}, send to SFTP path \"{}\"", resultContainer.getUuid(), path);
//gateway.sendToSftp(xmlFile, path);
gateway.sendToSftp(xmlFile, path);
if (Table.S_DF02.equals(resultContainer.getTableForExport())) {
sendPairSdfRequest(resultContainer);
}

View file

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.sftp.session.SftpFileInfo;
import org.springframework.stereotype.Component;
import ru.spcex.clearing.xml.exporter.config.SFTPConfig;
@ -27,7 +28,8 @@ public class PrepareXMLFile extends Stage implements InitializingBean {
public static String outDir;
private final SFTPConfig.XmlGateway gateway;
public PrepareXMLFile(ExportXMLServiceSettings settings, SFTPConfig.XmlGateway gateway) {
public PrepareXMLFile(ExportXMLServiceSettings settings,
@Qualifier("mockSFTP") SFTPConfig.XmlGateway gateway) {
this.settings = settings;
this.gateway = gateway;
}
@ -41,14 +43,15 @@ public class PrepareXMLFile extends Stage implements InitializingBean {
}
List<SftpFileInfo> files = new ArrayList<>();
log.trace("Get files from SFTP paths: {}", settings.getStore().getOutPayValDir().values());
for (String path : settings.getStore().getOutPayValDir().values()) {
files.addAll(gateway.listFiles(path));
}
log.info("There are {} files on the sFTP server in the search directories.", files.size());
// for (String path : settings.getStore().getOutPayValDir().values()) {
// files.addAll(gateway.listFiles(path));
// }
// log.info("There are {} files on the sFTP server in the search directories.", files.size());
Table table = resultContainer.getTableForExport();
LocalDateTime currentDateTime = LocalDateTime.now();
resultContainer.setRegistrationDateTime(currentDateTime);
File xmlFile = new File(nameTemplates.get(table).getFileName(resultContainer, files));
log.info("XML FILE = {}", xmlFile.toPath());
try {
Path xmlFilePath = xmlFile.toPath();
Files.deleteIfExists(xmlFilePath);