SFTP connection mocked, currency logic fixed
This commit is contained in:
parent
ffa3098650
commit
491577b6f8
13 changed files with 66 additions and 20 deletions
|
|
@ -9,6 +9,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.integration.annotation.Gateway;
|
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;
|
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@Profile("!test")
|
||||||
public class SFTPConfig {
|
public class SFTPConfig {
|
||||||
protected Logger log = LoggerFactory.getLogger(getClass());
|
protected Logger log = LoggerFactory.getLogger(getClass());
|
||||||
protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -71,8 +71,8 @@ public class DF02ObjectTag extends ObjectTag<SDf02> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf02 entity) {
|
public String getCurrency() {
|
||||||
return entity.getCurr_code();
|
return this.currCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrCode() {
|
public String getCurrCode() {
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,8 @@ public class DF03ObjectTag extends ObjectTag<SDf03> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf03 entity) {
|
public String getCurrency() {
|
||||||
return entity.getPay_val();
|
return this.payVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSegType() {
|
public String getSegType() {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class DF05ObjectTag extends ObjectTag<SDf05> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf05 entity) {
|
public String getCurrency() {
|
||||||
return ruCurrency;
|
return ruCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ public class DF07ObjectTag extends ObjectTag<SDf07> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf07 entity) {
|
public String getCurrency() {
|
||||||
return entity.getPay_val();
|
return this.payVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccount() {
|
public String getAccount() {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public class DF51ObjectTag extends ObjectTag<SDf51> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf51 entity) {
|
public String getCurrency() {
|
||||||
return ruCurrency;
|
return ruCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ public class DF53ObjectTag extends ObjectTag<SDf53> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf53 entity) {
|
public String getCurrency() {
|
||||||
return ruCurrency;
|
return ruCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,8 +174,8 @@ public class DF54ObjectTag extends ObjectTag<SDf54> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf54 entity) {
|
public String getCurrency() {
|
||||||
return entity.getPay_val();
|
return this.payVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSegType() {
|
public String getSegType() {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public class DF56ObjectTag extends ObjectTag<SDf56> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCurrency(SDf56 entity) {
|
public String getCurrency() {
|
||||||
return ruCurrency;
|
return ruCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.spcex.clearing.xml.exporter.logic.data.tags.objects;
|
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.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||||
|
|
@ -16,6 +17,7 @@ import ru.spcex.platform.enumeration.CurrencyCode;
|
||||||
@JsonSubTypes.Type(DF54ObjectTag.class),
|
@JsonSubTypes.Type(DF54ObjectTag.class),
|
||||||
@JsonSubTypes.Type(DF56ObjectTag.class),
|
@JsonSubTypes.Type(DF56ObjectTag.class),
|
||||||
})
|
})
|
||||||
|
@JsonIgnoreProperties(value = { "clazz", "currency" })
|
||||||
public abstract class ObjectTag<T1 extends SpcexObjectBase> {
|
public abstract class ObjectTag<T1 extends SpcexObjectBase> {
|
||||||
public final static String ruCurrency = CurrencyCode.RUB.getKey();
|
public final static String ruCurrency = CurrencyCode.RUB.getKey();
|
||||||
public Class<T1> clazz;
|
public Class<T1> clazz;
|
||||||
|
|
@ -26,5 +28,5 @@ public abstract class ObjectTag<T1 extends SpcexObjectBase> {
|
||||||
|
|
||||||
public abstract void setData(T1 entity);
|
public abstract void setData(T1 entity);
|
||||||
|
|
||||||
public abstract String getCurrency(T1 entity);
|
public abstract String getCurrency();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class ExportFromHazelcast extends Stage {
|
||||||
|
|
||||||
public ExportFromHazelcast(ExportXMLServiceSettings settings,
|
public ExportFromHazelcast(ExportXMLServiceSettings settings,
|
||||||
ImdgProvider imdgProvider,
|
ImdgProvider imdgProvider,
|
||||||
SFTPConfig.XmlGateway gateway,
|
@Qualifier("mockSFTP") SFTPConfig.XmlGateway gateway,
|
||||||
@Qualifier("xmlMapper") XmlMapper xmlMapper,
|
@Qualifier("xmlMapper") XmlMapper xmlMapper,
|
||||||
@Qualifier("mapOfTable") Map<Table, ObjectTag<? extends SpcexObjectBase>> objectTagMap,
|
@Qualifier("mapOfTable") Map<Table, ObjectTag<? extends SpcexObjectBase>> objectTagMap,
|
||||||
Supplier<KafkaSender> kafkaSender) {
|
Supplier<KafkaSender> kafkaSender) {
|
||||||
|
|
@ -103,6 +103,9 @@ public class ExportFromHazelcast extends Stage {
|
||||||
}
|
}
|
||||||
|
|
||||||
documentTag.setObjects(addObjectTags(tableRows, table));
|
documentTag.setObjects(addObjectTags(tableRows, table));
|
||||||
|
|
||||||
|
//todo: rewrite currency logic
|
||||||
|
currency = ruCurrency;
|
||||||
log.info("DOCUMENT TAG = {}", documentTag);
|
log.info("DOCUMENT TAG = {}", documentTag);
|
||||||
xmlMapper.writeValue(xmlFile, documentTag);
|
xmlMapper.writeValue(xmlFile, documentTag);
|
||||||
|
|
||||||
|
|
@ -110,6 +113,9 @@ public class ExportFromHazelcast extends Stage {
|
||||||
path = settings.getStore().getOutPayValDir().get(ruCurrency);
|
path = settings.getStore().getOutPayValDir().get(ruCurrency);
|
||||||
else path = settings.getStore().getOutPayValDir().get(currency);
|
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)
|
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");
|
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;
|
writeOk = true;
|
||||||
|
|
@ -129,7 +135,7 @@ public class ExportFromHazelcast extends Stage {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("uuid {}, send to SFTP path \"{}\"", resultContainer.getUuid(), path);
|
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())) {
|
if (Table.S_DF02.equals(resultContainer.getTableForExport())) {
|
||||||
sendPairSdfRequest(resultContainer);
|
sendPairSdfRequest(resultContainer);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.integration.sftp.session.SftpFileInfo;
|
import org.springframework.integration.sftp.session.SftpFileInfo;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import ru.spcex.clearing.xml.exporter.config.SFTPConfig;
|
import ru.spcex.clearing.xml.exporter.config.SFTPConfig;
|
||||||
|
|
@ -27,7 +28,8 @@ public class PrepareXMLFile extends Stage implements InitializingBean {
|
||||||
public static String outDir;
|
public static String outDir;
|
||||||
private final SFTPConfig.XmlGateway gateway;
|
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.settings = settings;
|
||||||
this.gateway = gateway;
|
this.gateway = gateway;
|
||||||
}
|
}
|
||||||
|
|
@ -41,14 +43,15 @@ public class PrepareXMLFile extends Stage implements InitializingBean {
|
||||||
}
|
}
|
||||||
List<SftpFileInfo> files = new ArrayList<>();
|
List<SftpFileInfo> files = new ArrayList<>();
|
||||||
log.trace("Get files from SFTP paths: {}", settings.getStore().getOutPayValDir().values());
|
log.trace("Get files from SFTP paths: {}", settings.getStore().getOutPayValDir().values());
|
||||||
for (String path : settings.getStore().getOutPayValDir().values()) {
|
// for (String path : settings.getStore().getOutPayValDir().values()) {
|
||||||
files.addAll(gateway.listFiles(path));
|
// files.addAll(gateway.listFiles(path));
|
||||||
}
|
// }
|
||||||
log.info("There are {} files on the sFTP server in the search directories.", files.size());
|
// log.info("There are {} files on the sFTP server in the search directories.", files.size());
|
||||||
Table table = resultContainer.getTableForExport();
|
Table table = resultContainer.getTableForExport();
|
||||||
LocalDateTime currentDateTime = LocalDateTime.now();
|
LocalDateTime currentDateTime = LocalDateTime.now();
|
||||||
resultContainer.setRegistrationDateTime(currentDateTime);
|
resultContainer.setRegistrationDateTime(currentDateTime);
|
||||||
File xmlFile = new File(nameTemplates.get(table).getFileName(resultContainer, files));
|
File xmlFile = new File(nameTemplates.get(table).getFileName(resultContainer, files));
|
||||||
|
log.info("XML FILE = {}", xmlFile.toPath());
|
||||||
try {
|
try {
|
||||||
Path xmlFilePath = xmlFile.toPath();
|
Path xmlFilePath = xmlFile.toPath();
|
||||||
Files.deleteIfExists(xmlFilePath);
|
Files.deleteIfExists(xmlFilePath);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue