Merge branch 'refs/heads/dev_xml-importer-changes' into dev

# Conflicts:
#	clearing-parent/xml-exporter/src/main/java/ru/spcex/clearing/xml/exporter/logic/stages/ExportFromHazelcast.java
#	clearing-parent/xml-exporter/src/test/java/ru/spcex/clearing/xml/exporter/logic/stages/ExportFromHazelcastTest.java
This commit is contained in:
etreschenkov 2024-11-27 14:51:52 +03:00
commit e8c6f1cb48
33 changed files with 376 additions and 644 deletions

View file

@ -1,5 +1,6 @@
package ru.spcex.clearing.xml.exporter.config;
import com.ctc.wstx.api.WstxOutputProperties;
import com.ctc.wstx.stax.WstxInputFactory;
import com.ctc.wstx.stax.WstxOutputFactory;
import com.fasterxml.jackson.databind.SerializationFeature;
@ -57,6 +58,7 @@ public class XMLExporterConfig {
xmlMapper.registerModule(new JavaTimeModule());
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
xmlMapper.getFactory().getXMLOutputFactory().setProperty(WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true);
return xmlMapper;
}

View file

@ -1,6 +1,7 @@
package ru.spcex.clearing.xml.exporter.config.settings;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import ru.spcex.clearing.platform.messaging.config.element.KafkaConsumerSettings;
@ -11,13 +12,23 @@ import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
@PropertySource("file:${spring.config.location}/application.properties")
@ConfigurationProperties("export-xml-service")
public class ExportXMLServiceSettings {
@NestedConfigurationProperty
private HazelcastClientParams hazelcast;
@NestedConfigurationProperty
private KafkaConsumerSettings kafkaConsumer;
@NestedConfigurationProperty
private KafkaProducerSettings kafkaProducer;
@NestedConfigurationProperty
private Common common;
@NestedConfigurationProperty
private Store store;
@NestedConfigurationProperty
private Cron cron;
private String section;
private String sender;
private String receiver;
public HazelcastClientParams getHazelcast() {
return hazelcast;
}
@ -65,4 +76,28 @@ public class ExportXMLServiceSettings {
public void setKafkaProducer(KafkaProducerSettings kafkaProducer) {
this.kafkaProducer = kafkaProducer;
}
public String getSection() {
return section;
}
public void setSection(String section) {
this.section = section;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
}

View file

@ -17,10 +17,12 @@ public class ResultContainer {
private LocalDateTime registrationDateTime;
private String memberCode;
private DocumentTag documentTag;
private String section;
public ResultContainer(Table tableForExport) {
public ResultContainer(Table tableForExport, String section) {
this.tableForExport = tableForExport;
this.uuid = UUID.randomUUID();
this.section = section;
}
public Table getTableForExport() {
@ -94,4 +96,12 @@ public class ResultContainer {
public void setDocumentTag(DocumentTag documentTag) {
this.documentTag = documentTag;
}
public String getSection() {
return section;
}
public void setSection(String section) {
this.section = section;
}
}

View file

@ -1,6 +1,5 @@
package ru.spcex.clearing.xml.exporter.logic.data.enums;
import static ru.spcex.clearing.xml.exporter.logic.stages.PrepareXMLFile.SECTION;
import static ru.spcex.clearing.xml.exporter.logic.stages.PrepareXMLFile.outDir;
import java.io.File;
@ -46,7 +45,7 @@ public enum FilenameTemplate {
name.substring(i);
}
},
df_section_dateTime_counter_mamberCode {
df_section_dateTime_counter_memberCode {
@Override
public String getFileName(ResultContainer resultContainer, List<SftpFileInfo> files) {
return appendSection(resultContainer)
@ -63,7 +62,7 @@ public enum FilenameTemplate {
result.append(File.separator);
result.append(resultContainer.getTableForExport().getFilePrefix().toUpperCase(Locale.ROOT));
result.append('_');
result.append(SECTION);
result.append(resultContainer.getSection());
return result;
}

View file

@ -0,0 +1,16 @@
package ru.spcex.clearing.xml.exporter.logic.data.enums;
public enum Sender {
LCC("ЛЦК"),
SPVB("СПВБ");
Sender(String text) {
this.text = text;
}
private String text;
public String getText() {
return text;
}
}

View file

@ -33,7 +33,7 @@ public class DocumentTag {
@JacksonXmlProperty(isAttribute = true, localName = "SENDER")
private String sender;
@JacksonXmlProperty(isAttribute = true, localName = "RECEIVER")
@JacksonXmlProperty(isAttribute = true, localName = "RECIEVER")
private String receiver;
@JacksonXmlProperty(localName = "PARENTDOC")

View file

@ -5,7 +5,6 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import org.springframework.format.annotation.DateTimeFormat;
import ru.clearing.classes.statics.data.sdf.SDf56;
@ -48,8 +47,8 @@ public class DF56ObjectTag extends ObjectTag<SDf56> {
this.startDatetime = Instant.ofEpochMilli(this.startUnixtime).atZone(ZoneId.systemDefault()).toLocalDateTime();
this.endUnixtime = Long.valueOf(entity.getEnd_datetime());
this.endDatetime = Instant.ofEpochMilli(this.endUnixtime).atZone(ZoneId.systemDefault()).toLocalDateTime();
this.account = entity.getAccount();
this.deal = entity.getDeal();
this.account = entity.getAccount() == null ? "" : entity.getAccount();
this.deal = entity.getDeal() == null ? "" : entity.getDeal();
}
@Override

View file

@ -1,6 +1,11 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static ru.spcex.clearing.platform.messaging.domain.Consts.PAIR_SDF;
import static ru.spcex.clearing.xml.exporter.logic.data.tags.objects.ObjectTag.ruCurrency;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
@ -30,6 +35,7 @@ import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.xml.exporter.config.SFTPConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Sender;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.DocumentTag;
@ -49,6 +55,7 @@ public class ExportFromHazelcast {
private final Map<Table, ObjectTag<? extends SpcexObjectBase>> objectTagMap;
private final Supplier<KafkaSender> kafkaSender;
private final ExportXMLServiceSettings settings;
private final XmlMapper xmlMapper;
private final Imdg<SDf01> sDf01Imdg;
private final Imdg<SDf52> sDf52Imdg;
@ -58,7 +65,8 @@ public class ExportFromHazelcast {
SFTPConfig.XmlGateway gateway,
@Qualifier("mapOfTable") Map<Table, ObjectTag<? extends SpcexObjectBase>> objectTagMap,
Supplier<KafkaSender> kafkaSender,
ExportXMLServiceSettings settings) {
ExportXMLServiceSettings settings,
XmlMapper xmlMapper) {
this.imdgProvider = imdgProvider;
this.gateway = gateway;
this.objectTagMap = objectTagMap;
@ -68,6 +76,7 @@ public class ExportFromHazelcast {
this.sDf01Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class);
this.sDf52Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf52, SDf52.class);
this.sDf06Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf06, SDf06.class);
this.xmlMapper = xmlMapper;
}
public StageResult process(ResultContainer resultContainer) {
@ -75,15 +84,25 @@ public class ExportFromHazelcast {
Table table = Objects.requireNonNull(resultContainer.getTableForExport());
File xmlFile = Objects.requireNonNull(resultContainer.getFileForExport());
String path;
String currency = ruCurrency; //todo: rewrite currency logic
if (CurrencyCode.isRub(currency)) {
path = settings.getStore().getOutPayValDir().get(ruCurrency);
} else {
path = settings.getStore().getOutPayValDir().get(currency);
}
DocumentTag documentTag = new DocumentTag();
ParentDocTag parentDocTag = new ParentDocTag();
parentDocTag.setParentId("");
// todo: Добавить данные DocumentTag'а
documentTag.setMessageId(String.valueOf(resultContainer.getGroupId()));
documentTag.setMessageType(table.getFilePrefix().replace("-", ""));
documentTag.setMessageName("");
documentTag.setMessageDate(LocalDate.now());
documentTag.setMessageTime(LocalTime.now());
documentTag.setSender("");
documentTag.setReceiver("");
documentTag.setSender(settings.getSender() != null ? Sender.valueOf(settings.getSender().toUpperCase()).getText() : "");
documentTag.setReceiver(settings.getReceiver() != null ? settings.getReceiver() : "");
documentTag.setParentDoc(parentDocTag);
Imdg<? extends SpcexObjectBase> map = imdgProvider.getImdg(table.getHazelcastMapName(), table.getEntityClass());
@ -97,7 +116,19 @@ public class ExportFromHazelcast {
}
if (tableRows.isEmpty()) {
log.info("uuid {}. Map {} is empty, generationId {}", resultContainer.getUuid(), resultContainer.getTableForExport().getHazelcastMapName(), resultContainer.getGroupId());
return StageResult.COMPLETE;
log.debug("uuid {}, send to SFTP path \"{}\"", resultContainer.getUuid(), path);
documentTag.setObjects(List.of());
resultContainer.setDocumentTag(documentTag);
try {
xmlMapper.writeValue(xmlFile, documentTag);
} catch (IOException e) {
log.error(String.format("uuid %s. Can't export table %s (map %s) to file %s. Table was skipped.",
resultContainer.getUuid(), table, table.getHazelcastMapName(), xmlFile), e);
return StageResult.ERROR;
}
gateway.sendToSftp(xmlFile, path);
return StageResult.OK;
} else {
log.debug("uuid {}. Selected {} records from map {}, generationId {}", resultContainer.getUuid(),
tableRows.size(), resultContainer.getTableForExport().getHazelcastMapName(), resultContainer.getGroupId());
@ -120,28 +151,18 @@ public class ExportFromHazelcast {
documentTag.setObjects(addObjectTags(tableRows, table));
resultContainer.setDocumentTag(documentTag);
boolean emptyMap = tableRows.isEmpty();
String path;
String currency = ruCurrency; //todo: rewrite currency logic
if (CurrencyCode.isRub(currency)) {
path = settings.getStore().getOutPayValDir().get(ruCurrency);
} else {
path = settings.getStore().getOutPayValDir().get(currency);
try {
xmlMapper.writeValue(xmlFile, documentTag);
} catch (IOException e) {
log.error(String.format("uuid %s. Can't export table %s (map %s) to file %s. Table was skipped.",
resultContainer.getUuid(), table, table.getHazelcastMapName(), xmlFile), e);
return StageResult.ERROR;
}
if (emptyMap) {
log.debug("Delete empty XML temp file \"{}\"", resultContainer.getFileForExport());
boolean deleteOk = resultContainer.getFileForExport().delete();
if (!deleteOk) {
log.warn("Can't delete file {}", resultContainer.getFileForExport().getName());
}
} else {
log.debug("uuid {}, send to SFTP path \"{}\"", resultContainer.getUuid(), path);
gateway.sendToSftp(xmlFile, path);
if (Table.S_DF02.equals(resultContainer.getTableForExport())) {
sendPairSdfRequest(resultContainer);
}
log.debug("uuid {}, send to SFTP path \"{}\"", resultContainer.getUuid(), path);
gateway.sendToSftp(xmlFile, path);
if (Table.S_DF02.equals(resultContainer.getTableForExport())) {
sendPairSdfRequest(resultContainer);
}
return StageResult.OK;

View file

@ -25,7 +25,6 @@ import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
@Component
public class PrepareXMLFile implements InitializingBean {
private final Logger log = LoggerFactory.getLogger(getClass());
public static final String SECTION = "S";
private final ExportXMLServiceSettings settings;
public static String outDir;
private final SFTPConfig.XmlGateway gateway;
@ -83,12 +82,12 @@ public class PrepareXMLFile implements InitializingBean {
private static final Map<Table, FilenameTemplate> nameTemplates = new EnumMap<>(Table.class);
static {
nameTemplates.put(Table.S_DF02, FilenameTemplate.df_section_sameName);
nameTemplates.put(Table.S_DF02, FilenameTemplate.df_section_dateTime_counter); // df_section_sameName
nameTemplates.put(Table.S_DF03, FilenameTemplate.df_section_dateTime_counter);
nameTemplates.put(Table.S_DF05, FilenameTemplate.df_section_dateTime);
nameTemplates.put(Table.S_DF07, FilenameTemplate.df_section_sameName);
nameTemplates.put(Table.S_DF05, FilenameTemplate.df_section_dateTime_counter); // df_section_dateTime
nameTemplates.put(Table.S_DF07, FilenameTemplate.df_section_dateTime_counter); // df_section_sameName
nameTemplates.put(Table.S_DF51, FilenameTemplate.df_section_dateTime_counter);
nameTemplates.put(Table.S_DF53, FilenameTemplate.df_section_sameName);
nameTemplates.put(Table.S_DF53, FilenameTemplate.df_section_dateTime_counter); // df_section_sameName
nameTemplates.put(Table.S_DF54, FilenameTemplate.df_section_dateTime_counter);
nameTemplates.put(Table.S_DF56, FilenameTemplate.df_section_dateTime_counter);
}

View file

@ -1,42 +0,0 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.DocumentTag;
@Component
public class WriteXMLFile {
private final Logger log = LoggerFactory.getLogger(getClass());
private final XmlMapper xmlMapper;
public WriteXMLFile(@Qualifier("xmlMapper") XmlMapper xmlMapper) {
this.xmlMapper = xmlMapper;
}
public StageResult process(ResultContainer resultContainer) {
log.info("uuid {}. Stage: {}", resultContainer.getUuid(), this.getClass().getSimpleName());
Table table = Objects.requireNonNull(resultContainer.getTableForExport());
File xmlFile = Objects.requireNonNull(resultContainer.getFileForExport());
DocumentTag documentTag = Objects.requireNonNull(resultContainer.getDocumentTag());
log.info("DOCUMENT TAG = {}", documentTag);
try {
xmlMapper.writeValue(xmlFile, documentTag);
} catch (Exception e) {
log.error(String.format("uuid %s. Can't export table %s (map %s) to file %s. Table was skipped.",
resultContainer.getUuid(), table, table.getHazelcastMapName(), xmlFile), e);
return StageResult.ERROR;
}
return StageResult.OK;
}
}

View file

@ -6,6 +6,7 @@ import org.apache.kafka.clients.consumer.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
@ -20,7 +21,6 @@ import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.stages.ExportFromHazelcast;
import ru.spcex.clearing.xml.exporter.logic.stages.Journal;
import ru.spcex.clearing.xml.exporter.logic.stages.PrepareXMLFile;
import ru.spcex.clearing.xml.exporter.logic.stages.WriteXMLFile;
import ru.spcex.platform.enumeration.Task;
@Service
@ -29,19 +29,19 @@ public class CommandService extends QueueConsumer implements InitializingBean {
private final PrepareXMLFile prepareXMLFile;
private final ExportFromHazelcast exportFromHazelcast;
private final WriteXMLFile writeXMLFile;
private final Journal journal;
private final String section;
public CommandService(Consumer<String, Object> kafkaQueue,
PrepareXMLFile prepareXMLFile,
ExportFromHazelcast exportFromHazelcast,
WriteXMLFile writeXMLFile,
Journal journal) {
Journal journal,
@Value("${export-xml-service.section:S}") String section) {
super(kafkaQueue);
this.prepareXMLFile = prepareXMLFile;
this.exportFromHazelcast = exportFromHazelcast;
this.writeXMLFile = writeXMLFile;
this.journal = journal;
this.section = section;
}
@Override
@ -88,7 +88,7 @@ public class CommandService extends QueueConsumer implements InitializingBean {
if (tableForExport.isEmpty()) {
throw new IllegalStateException(String.format("Unsupported table prefix: %s", request.getNameOfTable()));
}
ResultContainer resultContainer = new ResultContainer(tableForExport.get());
ResultContainer resultContainer = new ResultContainer(tableForExport.get(), section);
resultContainer.setGroupId(request.getSdfGroupId());
resultContainer.setSourceName(request.getFileName());
runProcess(resultContainer);
@ -96,7 +96,7 @@ public class CommandService extends QueueConsumer implements InitializingBean {
private void processSpecial(Table table, BaseRequest<SdfClearingRequest> systemRequest) {
SdfClearingRequest request = systemRequest.getRequestPayload();
ResultContainer resultContainer = new ResultContainer(table);
ResultContainer resultContainer = new ResultContainer(table, section);
resultContainer.setGroupId(request.getGroupId());
resultContainer.setSourceName(null);
runProcess(resultContainer);
@ -105,7 +105,7 @@ public class CommandService extends QueueConsumer implements InitializingBean {
private void processByLauncher(Table table, BaseRequest<LauncherCommandRequest> systemRequest) {
LauncherCommandRequest request = systemRequest.getRequestPayload();
log.info("RequestId={}, LauncherCommandRequest task={}. Table {}", systemRequest.getId(), request.getTaskName(), table);
ResultContainer resultContainer = new ResultContainer(table);
ResultContainer resultContainer = new ResultContainer(table, section);
resultContainer.setGroupId(null);
resultContainer.setSourceName(null);
runProcess(resultContainer);
@ -123,10 +123,6 @@ public class CommandService extends QueueConsumer implements InitializingBean {
result = exportFromHazelcast.process(resultContainer);
resultContainer.setLastStageResult(result);
}
if (result == StageResult.OK) {
result = writeXMLFile.process(resultContainer);
resultContainer.setLastStageResult(result);
}
if (result == StageResult.OK) {
result = journal.process(resultContainer);
resultContainer.setLastStageResult(result);

View file

@ -8,7 +8,7 @@ export-xml-service.common.encoding=cp866
export-xml-service.common.threads-count=10
export-xml-service.store.local-temp-dir=D:\\docs and T3\\clearing\\xml\\
# код валюты должен быть в верхнем регистре, например для рублей - "RUB" (*.RUB=export/rub/).RUB=export/rub/
# \u043A\u043E\u0434 \u0432\u0430\u043B\u044E\u0442\u044B \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u0432 \u0432\u0435\u0440\u0445\u043D\u0435\u043C \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435, \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 \u0434\u043B\u044F \u0440\u0443\u0431\u043B\u0435\u0439 - "RUB" (*.RUB=export/rub/).RUB=export/rub/
export-xml-service.store.out-pay-val-dir.RUB=export/rub/
export-xml-service.store.out-pay-val-dir.EUR=export/eur/
export-xml-service.store.user:tester
@ -30,3 +30,7 @@ export-xml-service.kafka-producer.retries=0
export-xml-service.kafka-producer.batch-size=16384
export-xml-service.kafka-producer.linger-ms=1
export-xml-service.kafka-producer.buffer-memory=33554432
export-xml-service.section=S
export-xml-service.sender=LCC
export-xml-service.receiver=\u0422\u0435\u0441\u0442

View file

@ -1,8 +1,13 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
@ -12,6 +17,7 @@ import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@ -93,6 +99,22 @@ class ExportFromHazelcastTest {
new TestObjectCreator(hazelcastService).createUserAdmin(1000L);
}
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldExportSDf02ToObjectTag() {
SDf02 expectedSDf02 = new SDf02();
@ -121,7 +143,7 @@ class ExportFromHazelcastTest {
Imdg<SDf01> sDf01Imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class);
sDf01Imdg.insert(forParentId);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02, "S");
actualResultContainer.setGroupId(1777L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
@ -144,6 +166,35 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getSumengage()).isEqualTo(expectedSDf02.getSumengage());
Assertions.assertThat(actualObjectTag.getSumunblock()).isEqualTo(expectedSDf02.getSumunblock());
Assertions.assertThat(actualObjectTag.getFileType()).isEqualTo(expectedSDf02.getFile_type());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldExportEmptySDf02ToObjectTag() {
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
DF02ObjectTag actualObjectTag = (DF02ObjectTag) actualResultContainer.getDocumentTag().getObjects();
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
Assertions.assertThat(actualResultContainer.getDocumentTag().getMessageType()).isEqualTo("DF02");
Assertions.assertThat(actualObjectTag).isEqualTo(null);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -166,7 +217,7 @@ class ExportFromHazelcastTest {
Imdg<SDf03> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
imdg.insert(expectedSDf03);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF03);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF03, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
@ -187,6 +238,14 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getSumDeb()).isEqualTo(expectedSDf03.getSum_deb());
Assertions.assertThat(actualObjectTag.getSpecif1()).isEqualTo(expectedSDf03.getSpecif_1());
Assertions.assertThat(actualObjectTag.getImpResult()).isEqualTo(expectedSDf03.getImp_result());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-03_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -200,7 +259,7 @@ class ExportFromHazelcastTest {
Imdg<SDf05> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf05, SDf05.class);
imdg.insert(expectedSDf05);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF05);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF05, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
@ -212,6 +271,14 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getDt()).isEqualTo(expectedSDf05.getDt());
Assertions.assertThat(actualObjectTag.getTm()).isEqualTo(expectedSDf05.getTm());
Assertions.assertThat(actualObjectTag.getPr()).isEqualTo(expectedSDf05.getPr());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-05_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -242,7 +309,7 @@ class ExportFromHazelcastTest {
Imdg<SDf06> sDf06Imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf06, SDf06.class);
sDf06Imdg.insert(forParentId);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF07);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF07, "S");
actualResultContainer.setGroupId(3775L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
@ -266,6 +333,14 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getDocNum()).isEqualTo(expectedSDf07.getDoc_num());
Assertions.assertThat(actualObjectTag.getDocDate().format(formatter)).isEqualTo(expectedSDf07.getDoc_date());
Assertions.assertThat(actualObjectTag.getPayVal()).isEqualTo(expectedSDf07.getPay_val());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-07_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -277,7 +352,7 @@ class ExportFromHazelcastTest {
Imdg<SDf51> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf51, SDf51.class);
imdg.insert(expectedSDf51);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF51);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF51, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
@ -288,6 +363,14 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getNumber()).isEqualTo(expectedSDf51.getNumber());
Assertions.assertThat(actualObjectTag.getUnixtime()).isEqualTo(Long.parseLong(expectedSDf51.getDatetime()));
Assertions.assertThat(actualObjectTag.getDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf51.getDatetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-51_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -312,7 +395,7 @@ class ExportFromHazelcastTest {
Imdg<SDf52> sDf52Imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf52, SDf52.class);
sDf52Imdg.insert(forParentId);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF53);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF53, "S");
actualResultContainer.setGroupId(2776L);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
@ -330,6 +413,14 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getStatus()).isEqualTo(expectedSDf53.getStatus());
Assertions.assertThat(actualObjectTag.getAccType()).isEqualTo(expectedSDf53.getAccType());
Assertions.assertThat(actualObjectTag.getResult()).isEqualTo(expectedSDf53.getResult());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-53_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -370,7 +461,7 @@ class ExportFromHazelcastTest {
Imdg<SDf54> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf54, SDf54.class);
imdg.insert(expectedSDf54);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF54);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF54, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
@ -409,6 +500,14 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getValueDate().format(formatter)).isEqualTo(expectedSDf54.getValue_date());
Assertions.assertThat(actualObjectTag.getSwiftBen()).isEqualTo(expectedSDf54.getSwift_ben());
Assertions.assertThat(actualObjectTag.getSwiftInt()).isEqualTo(expectedSDf54.getSwift_int());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-54_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
@ -423,7 +522,7 @@ class ExportFromHazelcastTest {
Imdg<SDf56> imdg = hazelcastService.getImdg(IMDGDistributedNames.Map_SDf56, SDf56.class);
imdg.insert(expectedSDf56);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF56);
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF56, "S");
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
StageResult stageResult = exportFromHazelcast.process(actualResultContainer);
@ -438,5 +537,13 @@ class ExportFromHazelcastTest {
Assertions.assertThat(actualObjectTag.getEndDatetime()).isEqualTo(Instant.ofEpochMilli(Long.parseLong(expectedSDf56.getEnd_datetime())).atZone(ZoneId.systemDefault()).toLocalDateTime());
Assertions.assertThat(actualObjectTag.getAccount()).isEqualTo(expectedSDf56.getAccount());
Assertions.assertThat(actualObjectTag.getDeal()).isEqualTo(expectedSDf56.getDeal());
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-56_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -1,433 +0,0 @@
package ru.spcex.clearing.xml.exporter.logic.stages;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestPropertySource;
import ru.spcex.clearing.test.config.ImdgTestConfig;
import ru.spcex.clearing.xml.exporter.config.XMLExporterConfig;
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
import ru.spcex.clearing.xml.exporter.logic.data.ResultContainer;
import ru.spcex.clearing.xml.exporter.logic.data.enums.StageResult;
import ru.spcex.clearing.xml.exporter.logic.data.enums.Table;
import ru.spcex.clearing.xml.exporter.logic.data.tags.DocumentTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.ParentDocTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF02ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF03ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF05ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF07ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF51ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF53ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF54ObjectTag;
import ru.spcex.clearing.xml.exporter.logic.data.tags.objects.DF56ObjectTag;
@SpringBootTest(classes = {
WriteXMLFile.class,
ExportXMLServiceSettings.class,
XMLExporterConfig.class,
ImdgTestConfig.class,
})
@TestPropertySource(properties = {"spring.config.location=./src/test/resources/"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class WriteXMLFileTest {
private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private WriteXMLFile writeXMLFile;
@AfterEach
void tearDown() {
try {
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
Files.deleteIfExists(Path.of("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
void process_shouldWriteSDf02ToXMLFile() {
DF02ObjectTag expectedObjectTag = new DF02ObjectTag();
expectedObjectTag.setCurrCode("test1");
expectedObjectTag.setAccount("test2");
expectedObjectTag.setRemainder("test3");
expectedObjectTag.setDeal("test4");
expectedObjectTag.setAccCode("test5");
expectedObjectTag.setDat(LocalDate.parse("2024-03-14"));
expectedObjectTag.setMarket("test6");
expectedObjectTag.setAccName("test7");
expectedObjectTag.setAccType("test8");
expectedObjectTag.setSumengage("test9");
expectedObjectTag.setSumunblock("test10");
expectedObjectTag.setFileType("test11");
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF02");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF02);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-02_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-02_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf03ToXMLFile() {
DF03ObjectTag expectedObjectTag = new DF03ObjectTag();
expectedObjectTag.setSegType("test1");
expectedObjectTag.setDocType("test2");
expectedObjectTag.setDocnmRef("test3");
expectedObjectTag.setDocnmprev("test4");
expectedObjectTag.setcAccDeb("test5");
expectedObjectTag.setSbanknam1("test6");
expectedObjectTag.setcAccCred("test7");
expectedObjectTag.setRbanknam1("test8");
expectedObjectTag.setPayDate(LocalDate.parse("2024-03-14"));
expectedObjectTag.setPayVal("test9");
expectedObjectTag.setSumDeb("test10");
expectedObjectTag.setSpecif1("test11");
expectedObjectTag.setImpResult("test12");
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF03");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF03);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-03_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-03_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf05ToXMLFile() {
DF05ObjectTag expectedObjectTag = new DF05ObjectTag();
expectedObjectTag.setTp(BigDecimal.TEN);
expectedObjectTag.setDt(LocalDate.parse("2024-03-14"));
expectedObjectTag.setTm(LocalTime.parse("09:22:12"));
expectedObjectTag.setPr("test2");
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF05");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF05);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-05_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-05_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf07ToXMLFile() {
DF07ObjectTag expectedObjectTag = new DF07ObjectTag();
expectedObjectTag.setAccount("test1");
expectedObjectTag.setSum(new BigDecimal(BigInteger.TEN));
expectedObjectTag.setMarket("test3");
expectedObjectTag.setType("test4");
expectedObjectTag.setDeal("test5");
expectedObjectTag.setClientN("test6");
expectedObjectTag.setInn("test7");
expectedObjectTag.setBic("test8");
expectedObjectTag.setSpec("test9");
expectedObjectTag.setNumber(new BigDecimal(BigInteger.TWO));
expectedObjectTag.setDocNum("test11");
expectedObjectTag.setDocDate(LocalDate.parse("2024-03-14"));
expectedObjectTag.setPayVal("test12");
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF07");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF07);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-07_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-07_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf51ToXMLFile() {
DF51ObjectTag expectedObjectTag = new DF51ObjectTag();
expectedObjectTag.setNumber("1234");
expectedObjectTag.setDatetime(LocalDateTime.parse("2024-03-14T09:03:11"));
expectedObjectTag.setUnixtime(expectedObjectTag.getDatetime().atZone(ZoneId.systemDefault()).toEpochSecond());
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF51");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF51);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-51_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-51_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf53ToXMLFile() {
DF53ObjectTag expectedObjectTag = new DF53ObjectTag();
expectedObjectTag.setAccount("test1");
expectedObjectTag.setAccName("test2");
expectedObjectTag.setDeal("test3");
expectedObjectTag.setDate(LocalDate.parse("2024-03-14"));
expectedObjectTag.setStatus(1L);
expectedObjectTag.setAccType("test4");
expectedObjectTag.setResult("test5");
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF53");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF53);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-53_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-53_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf54ToXMLFile() {
DF54ObjectTag expectedObjectTag = new DF54ObjectTag();
expectedObjectTag.setSegType("test1");
expectedObjectTag.setDocType("test2");
expectedObjectTag.setDocnmRef("test3");
expectedObjectTag.setDocnmprev("test4");
expectedObjectTag.setSbankcode("test5");
expectedObjectTag.setcAccDeb("test6");
expectedObjectTag.setSbanknam1("test7");
expectedObjectTag.setRbankcode("test8");
expectedObjectTag.setcAccCred("test9");
expectedObjectTag.setRbanknam1("test10");
expectedObjectTag.setOpType("test11");
expectedObjectTag.setOpOrder("test12");
expectedObjectTag.setPayDate(LocalDate.parse("2024-03-14"));
expectedObjectTag.setPayVal("test13");
expectedObjectTag.setSumDeb("test14");
expectedObjectTag.setSclientn1("test15");
expectedObjectTag.setInnDeb("test16");
expectedObjectTag.setKppDeb("test17");
expectedObjectTag.setAccDeb("test18");
expectedObjectTag.setRclientn1("test19");
expectedObjectTag.setInnCred("test20");
expectedObjectTag.setKppCred("test21");
expectedObjectTag.setAccKr1("test22");
expectedObjectTag.setSpecif1("test23");
expectedObjectTag.setSendType("test24");
expectedObjectTag.setDocResult("test25");
expectedObjectTag.setDocNum("test26");
expectedObjectTag.setDocDate(LocalDate.parse("2024-03-15"));
expectedObjectTag.setValueDate(LocalDate.parse("2024-03-16"));
expectedObjectTag.setSwiftBen("test27");
expectedObjectTag.setSwiftInt("test28");
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF54");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF54);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-54_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-54_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
@Test
void process_shouldWriteSDf56ToXMLFile() {
DF56ObjectTag expectedObjectTag = new DF56ObjectTag();
expectedObjectTag.setNumber("test1");
expectedObjectTag.setStartDatetime(LocalDateTime.parse("2024-03-14T09:03:11"));
expectedObjectTag.setEndDatetime(LocalDateTime.parse("2024-04-15T11:03:11"));
expectedObjectTag.setAccount("test4");
expectedObjectTag.setDeal("test5");
expectedObjectTag.setStartUnixtime(expectedObjectTag.getStartDatetime().atZone(ZoneId.systemDefault()).toEpochSecond());
expectedObjectTag.setEndUnixtime(expectedObjectTag.getEndDatetime().atZone(ZoneId.systemDefault()).toEpochSecond());
ParentDocTag expectedParentDocTag = new ParentDocTag();
expectedParentDocTag.setParentId("");
DocumentTag expectedDocumentTag = new DocumentTag();
expectedDocumentTag.setMessageId("");
expectedDocumentTag.setMessageType("DF56");
expectedDocumentTag.setMessageName("");
expectedDocumentTag.setMessageDate(LocalDate.parse("2024-03-14"));
expectedDocumentTag.setMessageTime(LocalTime.parse("09:15:31"));
expectedDocumentTag.setSender("");
expectedDocumentTag.setReceiver("");
expectedDocumentTag.setParentDoc(expectedParentDocTag);
expectedDocumentTag.setObjects(List.of(expectedObjectTag));
ResultContainer actualResultContainer = new ResultContainer(Table.S_DF56);
actualResultContainer.setFileForExport(new File("./src/test/resources/xml/DF-56_S_PRC1604240915_1.xml"));
actualResultContainer.setDocumentTag(expectedDocumentTag);
StageResult stageResult = writeXMLFile.process(actualResultContainer);
Assertions.assertThat(stageResult).isEqualTo(StageResult.OK);
try {
Assertions.assertThat(Files.mismatch(actualResultContainer.getFileForExport().toPath(),
Path.of("./src/test/resources/xml-original/DF-56_S_PRC1604240915_1.xml")))
.isEqualTo(-1L);
} catch (IOException e) {
fail("File comparison failed!");
}
}
}

View file

@ -8,7 +8,7 @@ export-xml-service.common.encoding=cp866
export-xml-service.common.threads-count=10
export-xml-service.store.local-temp-dir=D:\\docs and T3\\clearing\\xml\\
# код валюты должен быть в верхнем регистре, например для рублей - "RUB" (*.RUB=export/rub/).RUB=export/rub/
# \u043A\u043E\u0434 \u0432\u0430\u043B\u044E\u0442\u044B \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u0432 \u0432\u0435\u0440\u0445\u043D\u0435\u043C \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435, \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 \u0434\u043B\u044F \u0440\u0443\u0431\u043B\u0435\u0439 - "RUB" (*.RUB=export/rub/).RUB=export/rub/
export-xml-service.store.out-pay-val-dir.RUB=export/rub/
export-xml-service.store.out-pay-val-dir.EUR=export/eur/
export-xml-service.store.user:tester
@ -29,4 +29,4 @@ export-xml-service.kafka-producer.acks=all
export-xml-service.kafka-producer.retries=0
export-xml-service.kafka-producer.batch-size=16384
export-xml-service.kafka-producer.linger-ms=1
export-xml-service.kafka-producer.buffer-memory=33554432
export-xml-service.kafka-producer.buffer-memory=33554432

View file

@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF02" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF02" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT CURR_CODE="test1" ACCOUNT="test2" REMAINDER="test3" DEAL="test4" ACC_CODE="test5" DAT="2024-03-14" MARKET="test6" ACC_NAME="test7" ACC_TYPE="test8" SUMENGAGE="test9" SUMUNBLOK="test10" FILE_TYPE="test11"/>
<OBJECT CURR_CODE="test1" ACCOUNT="test2" REMAINDER="test3" DEAL="test4" ACC_CODE="test5" DAT="2024-03-14" MARKET="test6" ACC_NAME="test7" ACC_TYPE="test8" SUMENGAGE="test9" SUMUNBLOK="test10" FILE_TYPE="test11" RESULT="test12"/>
</OBJECTS>
</DOCUMENT>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF03" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF03" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT SEG_TYPE="test1" DOC_TYPE="test2" DOCNM_REF="test3" DOCNMPREV="test4" C_ACC_DEB="test5" SBANKNAM="test6" C_ACC_CRED="test7" RBANKNAM="test8" PAY_DATE="2024-03-14" PAY_VAL="test9" SUM_DEB="test10" SPECIF_1="test11" IMP_RESULT="test12"/>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF05" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF05" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT TP="10" DT="2024-03-14" TM="09:22:12" PR="test2"/>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF07" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF07" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT ACCOUNT="test1" SUM="10" MARKET="test3" TYPE="test4" DEAL="test5" CLIENTN="test6" INN="test7" BIC="test8" SPEC="test9" NUMBER="2" DOC_NUM="test11" DOC_DATE="2024-03-14" PAY_VAL="test12"/>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF51" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF51" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT NUMBER="1234" UNIXTIME="1710396191" DATETIME="2024-03-14T09:03:11"/>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF53" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF53" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT ACCOUNT="test1" ACC_NAME="test2" DEAL="test3" DATE="2024-03-14" STATUS="1" ACC_TYPE="test4" RESULT="test5"/>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF54" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF54" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT SEG_TYPE="test1" DOC_TYPE="test2" DOCNM_REF="test3" DOCNMPREV="test4" SBANKCODE="test5" C_ACC_DEB="test6" SBANKNAM="test7" RBANKCODE="test8" C_ACC_CRED="test9" RBANKNAM="test10" OP_TYPE="test11" OP_ORDER="test12" PAY_DATE="2024-03-14" PAY_VAL="test13" SUM_DEB="test14" SCLIENTN="test15" INN_DEB="test16" KPP_DEB="test17" ACC_DEB="test18" RCLIENTN="test19" INN_CRED="test20" KPP_CRED="test21" ACC_KR_1="test22" SPECIF_1="test23" SEND_TYPE="test24" DOC_RESULT="test25" DOC_NUM="test26" DOC_DATE="2024-03-15" VALUE_DATE="2024-03-16" SWIFT_BEN="test27" SWIFT_INT="test28"/>

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<DOCUMENT MESSAGEID="" MESSAGETYPE="DF56" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECEIVER="">
<DOCUMENT MESSAGEID="null" MESSAGETYPE="DF56" MESSAGENAME="" MESSAGEDATE="2024-03-14" MESSAGETIME="09:15:31" SENDER="" RECIEVER="">
<PARENTDOC PARENTID=""/>
<OBJECTS>
<OBJECT NUMBER="test1" SUNIXTIME="1710396191" SDATETIME="2024-03-14T09:03:11" EUNIXTIME="1713168191" EDATETIME="2024-04-15T11:03:11" ACCOUNT="test4" DEAL="test5"/>

View file

@ -31,13 +31,13 @@ public class SFTPConfig {
private final Logger log = LoggerFactory.getLogger(getClass());
@Bean("sftpSessionFactorySdf")
@ConditionalOnProperty(value = "import-xml-service.process-sdf-files", havingValue = "true")
@ConditionalOnProperty(value = "import-xml-service.process-files", havingValue = "true")
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactorySdf(ImportXMLServiceSettings settings) {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(settings.getStoreSdf().getSftpIn().getServerIp());
factory.setPort(settings.getStoreSdf().getSftpIn().getServerPort());
factory.setUser(settings.getStoreSdf().getSftpIn().getUser());
factory.setPassword(settings.getStoreSdf().getSftpIn().getPassword());
factory.setHost(settings.getStore().getSftpIn().getServerIp());
factory.setPort(settings.getStore().getSftpIn().getServerPort());
factory.setUser(settings.getStore().getSftpIn().getUser());
factory.setPassword(settings.getStore().getSftpIn().getPassword());
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<>(factory);
}
@ -66,7 +66,7 @@ public class SFTPConfig {
}
@Bean("xmlGatewaySdf")
@ConditionalOnProperty(value = "import-xml-service.process-sdf-files", havingValue = "true")
@ConditionalOnProperty(value = "import-xml-service.process-files", havingValue = "true")
public AnnotationGatewayProxyFactoryBean xmlGatewaySdf() {
return new AnnotationGatewayProxyFactoryBean(XmlGatewaySdf.class);
}
@ -78,7 +78,7 @@ public class SFTPConfig {
}
@Bean("listSftpChannelSdf")
@ConditionalOnProperty(value = "import-xml-service.process-sdf-files", havingValue = "true")
@ConditionalOnProperty(value = "import-xml-service.process-files", havingValue = "true")
public MessageChannel listSftpChannelSdf(@Qualifier("sftpSessionFactorySdf") SessionFactory<ChannelSftp.LsEntry> sessionFactory,
ImportXMLServiceSettings settings) {
DirectChannel dc = new DirectChannel();
@ -96,12 +96,17 @@ public class SFTPConfig {
}
@Bean
@ConditionalOnProperty(value = "import-xml-service.process-sdf-files", havingValue = "true")
@ConditionalOnProperty(value = "import-xml-service.process-files", havingValue = "true")
@ServiceActivator(inputChannel = "listSftpChannelSdf")
public MessageHandler handlerListSdf(@Qualifier("sftpSessionFactorySdf") SessionFactory<ChannelSftp.LsEntry> sessionFactory,
ImportXMLServiceSettings settings) {
String localDirLocation = settings.getStore().getSrcDir();
if (!List.of("/", "\\").contains(localDirLocation.substring(localDirLocation.length() - 1))) {
localDirLocation += File.separator;
}
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sessionFactory, MGET.getCommand(), null);
sftpOutboundGateway.setLocalDirectory(new File(settings.getStoreSdf().getSrcDir()));
sftpOutboundGateway.setLocalDirectory(new File(localDirLocation));
sftpOutboundGateway.setAutoCreateLocalDirectory(true);
sftpOutboundGateway.setOption(AbstractRemoteFileOutboundGateway.Option.DELETE);
return sftpOutboundGateway;
@ -112,8 +117,13 @@ public class SFTPConfig {
@ServiceActivator(inputChannel = "listSftpChannelLks")
public MessageHandler handlerListLks(@Qualifier("sftpSessionFactoryLks") SessionFactory<ChannelSftp.LsEntry> sessionFactory,
ImportXMLServiceSettings settings) {
String localDirLocation = settings.getStore().getSrcDir();
if (!List.of("/", "\\").contains(localDirLocation.substring(localDirLocation.length() - 1))) {
localDirLocation += File.separator;
}
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sessionFactory, MGET.getCommand(), null);
sftpOutboundGateway.setLocalDirectory(new File(settings.getStoreLks().getSrcDir()));
sftpOutboundGateway.setLocalDirectory(new File(localDirLocation));
sftpOutboundGateway.setAutoCreateLocalDirectory(true);
sftpOutboundGateway.setOption(AbstractRemoteFileOutboundGateway.Option.DELETE);
return sftpOutboundGateway;

View file

@ -12,7 +12,7 @@ import org.springframework.context.annotation.Profile;
@Configuration
public class SFTPMockConfig {
@Bean("xmlGatewaySdf")
@ConditionalOnProperty(value = "import-xml-service.process-sdf-files", havingValue = "true")
@ConditionalOnProperty(value = "import-xml-service.process-files", havingValue = "true")
public SFTPConfig.XmlGatewaySdf xmlGatewaySdf(){
return new XGatewaySdf();
}

View file

@ -60,7 +60,7 @@ public class XMLImporterConfig {
}
@Bean("mapOfTable")
@ConditionalOnProperty(value = "import-xml-service.process-sdf-files", havingValue = "true")
@ConditionalOnProperty(value = "import-xml-service.process-files", havingValue = "true")
public Map<ETable, ImdgHazelcast<? extends SpcexObjectBase>> getMapOfTables() {
Map<ETable, ImdgHazelcast<? extends SpcexObjectBase>> map = new HashMap<>();
map.put(ETable.DF_01, (ImdgHazelcast<? extends SpcexObjectBase>) hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));

View file

@ -20,7 +20,7 @@ public class ImportXMLServiceSettings {
private KafkaConsumerSettings kafkaConsumer;
@NestedConfigurationProperty
private StoreSettings storeSdf;
private StoreSettings store;
@NestedConfigurationProperty
private StoreSettings storeLks;
@ -29,7 +29,7 @@ public class ImportXMLServiceSettings {
@NestedConfigurationProperty
private Cron cron;
private boolean processSdfFiles;
private boolean processFiles;
private boolean processLksFiles;
public HazelcastClientParams getHazelcast() {
@ -56,12 +56,12 @@ public class ImportXMLServiceSettings {
this.kafkaConsumer = kafkaConsumer;
}
public StoreSettings getStoreSdf() {
return storeSdf;
public StoreSettings getStore() {
return store;
}
public void setStoreSdf(StoreSettings storeSdf) {
this.storeSdf = storeSdf;
public void setStore(StoreSettings store) {
this.store = store;
}
public StoreSettings getStoreLks() {
@ -88,12 +88,12 @@ public class ImportXMLServiceSettings {
this.cron = cron;
}
public boolean isProcessSdfFiles() {
return processSdfFiles;
public boolean isProcessFiles() {
return processFiles;
}
public void setProcessSdfFiles(boolean processSdfFiles) {
this.processSdfFiles = processSdfFiles;
public void setProcessFiles(boolean processFiles) {
this.processFiles = processFiles;
}
public boolean isProcessLksFiles() {

View file

@ -33,7 +33,7 @@ public class DocumentTag implements ru.spcex.clearing.xml.importer.logic.data.ta
@JacksonXmlProperty(isAttribute = true, localName = "SENDER")
private String sender;
@JacksonXmlProperty(isAttribute = true, localName = "RECEIVER")
@JacksonXmlProperty(isAttribute = true, localName = "RECIEVER")
private String receiver;
@JacksonXmlProperty(localName = "PARENTDOC")

View file

@ -30,16 +30,16 @@ public class ChangeDirOfFileStage {
log.info("uuid {}. Stage: Change directory of file", resultContainer.getUuid());
File srcDir = new File(resultContainer.getXmlTable().getFileType().equals(FileType.SDF) ?
settings.getStoreSdf().getSrcDir() :
settings.getStore().getSrcDir() :
settings.getStoreLks().getSrcDir());
File outDir;
if (resultContainer.getLastStageStatus().equals(StageResult.ERROR)) {
outDir = new File(resultContainer.getXmlTable().getFileType().equals(FileType.SDF) ?
settings.getStoreSdf().getOutDirError() :
settings.getStore().getOutDirError() :
settings.getStoreLks().getOutDirError());
} else {
outDir = new File(resultContainer.getXmlTable().getFileType().equals(FileType.SDF) ?
settings.getStoreSdf().getOutDir() :
settings.getStore().getOutDir() :
settings.getStoreLks().getOutDir());
}
File xmlFile = resultContainer.getXmlFilePath();

View file

@ -12,6 +12,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,12 +27,12 @@ import ru.spcex.platform.utils.log.ExceptionUtils;
public class FileChecker {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final ImportXMLServiceSettings settings;
private final SFTPConfig.XmlGatewaySdf gatewaySdf;
private final SFTPConfig.XmlGatewayLks gatewayLks;
private final Optional<SFTPConfig.XmlGatewaySdf> gatewaySdf;
private final Optional<SFTPConfig.XmlGatewayLks> gatewayLks;
public FileChecker(ImportXMLServiceSettings settings,
SFTPConfig.XmlGatewaySdf gatewaySdf,
SFTPConfig.XmlGatewayLks gatewayLks) {
Optional<SFTPConfig.XmlGatewaySdf> gatewaySdf,
Optional<SFTPConfig.XmlGatewayLks> gatewayLks) {
this.settings = settings;
this.gatewaySdf = gatewaySdf;
this.gatewayLks = gatewayLks;
@ -42,15 +43,15 @@ public class FileChecker {
List<String> srcDir = new ArrayList<>();
if (specificTable == null) {
if (settings.isProcessSdfFiles()) {
srcDir.add(settings.getStoreSdf().getSrcDir());
if (settings.isProcessFiles()) {
srcDir.add(settings.getStore().getSrcDir());
}
if (settings.isProcessLksFiles()) {
srcDir.add(settings.getStoreLks().getSrcDir());
}
} else {
srcDir.add(specificTable.getFileType().equals(FileType.SDF) ?
settings.getStoreSdf().getSrcDir() :
settings.getStore().getSrcDir() :
settings.getStoreLks().getSrcDir());
}
@ -90,7 +91,7 @@ public class FileChecker {
}
public void checkAndLoadSFTP() {
if (settings.isProcessSdfFiles() && (settings.getStoreSdf().getSftpIn().getSftpSrcPayValDir() == null || settings.getStoreSdf().getSftpIn().getSftpSrcPayValDir().isEmpty())) {
if (settings.isProcessFiles() && (settings.getStore().getSftpIn().getSftpSrcPayValDir() == null || settings.getStore().getSftpIn().getSftpSrcPayValDir().isEmpty())) {
log.error("No SFTP scanning directories, need will be adding setting like 'import-xml-service.store-sdf.sftp-in.sftp-src-pay-val-dir.VAL=/VAL' and restart app");
return;
}
@ -100,19 +101,27 @@ public class FileChecker {
}
List<File> files = new ArrayList<>();
if (settings.isProcessSdfFiles()) {
log.trace("Load from SFTP paths: {}", settings.getStoreSdf().getSftpIn().getSftpSrcPayValDir().values());
for (String path : settings.getStoreSdf().getSftpIn().getSftpSrcPayValDir().values()) {
files.addAll(gatewaySdf.listFiles(path));
}
if (settings.isProcessFiles()) {
log.trace("Load from SFTP paths: {}", settings.getStore().getSftpIn().getSftpSrcPayValDir().values());
gatewaySdf.ifPresent(gateway -> {
for (String path : settings.getStore().getSftpIn().getSftpSrcPayValDir().values()) {
files.addAll(gateway.listFiles(path));
}
});
if (!files.isEmpty())
log.info("Loaded from SFTP SDF files count={}", files.size());
}
if (settings.isProcessLksFiles()) {
log.trace("Load from SFTP paths: {}", settings.getStoreLks().getSftpIn().getSftpSrcPayValDir().values());
for (String path : settings.getStoreLks().getSftpIn().getSftpSrcPayValDir().values()) {
files.addAll(gatewayLks.listFiles(path));
}
gatewayLks.ifPresent(gateway -> {
for (String path : settings.getStoreLks().getSftpIn().getSftpSrcPayValDir().values()) {
files.addAll(gateway.listFiles(path));
}
});
if (!files.isEmpty())
log.info("Loaded from SFTP LKS files count={}", files.size());
}

View file

@ -59,9 +59,9 @@ public class XMLImporterService {
this.filesCurrentlyInProcess = new HashSet<>();
}
@Scheduled(cron = "${import-xml-service.cron.check-src-dir-cron}")
@Scheduled(cron = "${import-xml-service.scheduler.check-src-dir-cron}")
public void run() {
if (settings.isProcessSdfFiles() || settings.isProcessLksFiles()) {
if (settings.isProcessFiles() || settings.isProcessLksFiles()) {
processTable(null);
} else {
log.warn("Turn on SDF or LKS file processing in application.properties!");

View file

@ -2,44 +2,44 @@ server.port=8081
server.servlet.context-path=/xml-importer
spring.main.web-application-type=servlet
import-xml-service.process-sdf-files=true
import-xml-service.process-lks-files=true
import-xml-service.process-files=true
import-xml-service.process-lks-files=false
import-xml-service.cron.check-src-dir-cron=* * * * 1 ?
import-xml-service.scheduler.check-src-dir-cron=* * * * 1 ?
import-xml-service.common.encoding-source=cp866
import-xml-service.common.insert-batch-size=100
import-xml-service.common.threads-count=10
# Store directories for SDf
import-xml-service.store-sdf.delete-src-files=false
import-xml-service.store-sdf.src-dir=/opt/clearing/file/xml-importer/
import-xml-service.store-sdf.out-dir=/opt/clearing/file/xml-importer/loaded/
import-xml-service.store-sdf.out-dir-error=/opt/clearing/file/xml-importer/error/
import-xml-service.store.delete-src-files=false
import-xml-service.store.src-dir=/opt/clearing/file/xml-importer/
import-xml-service.store.out-dir=/opt/clearing/file/xml-importer/loaded/
import-xml-service.store.out-dir-error=/opt/clearing/file/xml-importer/error/
# Sftp directories and credentials for SDf
import-xml-service.store-sdf.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
import-xml-service.store-sdf.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
import-xml-service.store-sdf.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
import-xml-service.store-sdf.sftp-in.user=user
import-xml-service.store-sdf.sftp-in.password=*********
import-xml-service.store-sdf.sftp-in.server-ip=127.0.0.1
import-xml-service.store-sdf.sftp-in.server-port=22
import-xml-service.store.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
import-xml-service.store.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
import-xml-service.store.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
import-xml-service.store.sftp-in.user=user
import-xml-service.store.sftp-in.password=*********
import-xml-service.store.sftp-in.server-ip=127.0.0.1
import-xml-service.store.sftp-in.server-port=22
# Store directories for LKS
import-xml-service.store-lks.delete-src-files=false
import-xml-service.store-lks.src-dir=/opt/clearing/file/xml-importer/
import-xml-service.store-lks.out-dir=/opt/clearing/file/xml-importer/loaded/
import-xml-service.store-lks.out-dir-error=/opt/clearing/file/xml-importer/error/
# Sftp directories and credentials for LKS
import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
import-xml-service.store-lks.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
import-xml-service.store-lks.sftp-in.user=user
import-xml-service.store-lks.sftp-in.password=*********
import-xml-service.store-lks.sftp-in.server-ip=127.0.0.1
import-xml-service.store-lks.sftp-in.server-port=22
## Store directories for LKS
#import-xml-service.store-lks.delete-src-files=false
#import-xml-service.store-lks.src-dir=/opt/clearing/file/xml-importer/
#import-xml-service.store-lks.out-dir=/opt/clearing/file/xml-importer/loaded/
#import-xml-service.store-lks.out-dir-error=/opt/clearing/file/xml-importer/error/
#
## Sftp directories and credentials for LKS
#import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
#import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
#import-xml-service.store-lks.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
#import-xml-service.store-lks.sftp-in.user=user
#import-xml-service.store-lks.sftp-in.password=*********
#import-xml-service.store-lks.sftp-in.server-ip=127.0.0.1
#import-xml-service.store-lks.sftp-in.server-port=22
# Hazelcast cluster
import-xml-service.hazelcast.cluster-members=10.200.200.181:5701

View file

@ -2,44 +2,44 @@ server.port=8081
server.servlet.context-path=/xml-importer
spring.main.web-application-type=servlet
import-xml-service.process-sdf-files=true
import-xml-service.process-lks-files=true
import-xml-service.process-files=true
import-xml-service.process-lks-files=false
import-xml-service.cron.check-src-dir-cron=* * * * 1 ?
import-xml-service.scheduler.check-src-dir-cron=* * * * 1 ?
import-xml-service.common.encoding-source=cp866
import-xml-service.common.insert-batch-size=100
import-xml-service.common.threads-count=10
# Store directories for SDf
import-xml-service.store-sdf.delete-src-files=false
import-xml-service.store-sdf.src-dir=/opt/clearing/file/xml-importer/
import-xml-service.store-sdf.out-dir=/opt/clearing/file/xml-importer/loaded/
import-xml-service.store-sdf.out-dir-error=/opt/clearing/file/xml-importer/error/
import-xml-service.store.delete-src-files=false
import-xml-service.store.src-dir=/opt/clearing/file/xml-importer/
import-xml-service.store.out-dir=/opt/clearing/file/xml-importer/loaded/
import-xml-service.store.out-dir-error=/opt/clearing/file/xml-importer/error/
# Sftp directories and credentials for SDf
import-xml-service.store-sdf.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
import-xml-service.store-sdf.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
import-xml-service.store-sdf.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
import-xml-service.store-sdf.sftp-in.user=user
import-xml-service.store-sdf.sftp-in.password=*********
import-xml-service.store-sdf.sftp-in.server-ip=127.0.0.1
import-xml-service.store-sdf.sftp-in.server-port=22
import-xml-service.store.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
import-xml-service.store.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
import-xml-service.store.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
import-xml-service.store.sftp-in.user=user
import-xml-service.store.sftp-in.password=*********
import-xml-service.store.sftp-in.server-ip=127.0.0.1
import-xml-service.store.sftp-in.server-port=22
# Store directories for LKS
import-xml-service.store-lks.delete-src-files=false
import-xml-service.store-lks.src-dir=/opt/clearing/file/xml-importer/
import-xml-service.store-lks.out-dir=/opt/clearing/file/xml-importer/loaded/
import-xml-service.store-lks.out-dir-error=/opt/clearing/file/xml-importer/error/
# Sftp directories and credentials for LKS
import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
import-xml-service.store-lks.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
import-xml-service.store-lks.sftp-in.user=user
import-xml-service.store-lks.sftp-in.password=*********
import-xml-service.store-lks.sftp-in.server-ip=127.0.0.1
import-xml-service.store-lks.sftp-in.server-port=22
## Store directories for LKS
#import-xml-service.store-lks.delete-src-files=false
#import-xml-service.store-lks.src-dir=/opt/clearing/file/xml-importer/
#import-xml-service.store-lks.out-dir=/opt/clearing/file/xml-importer/loaded/
#import-xml-service.store-lks.out-dir-error=/opt/clearing/file/xml-importer/error/
#
## Sftp directories and credentials for LKS
#import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.rub=clearing_xml-importer_sftp/rub/
#import-xml-service.store-lks.sftp-in.sftp-src-pay-val-dir.eur=clearing_xml-importer_sftp/eur/
#import-xml-service.store-lks.sftp-in.sftp-src-dir=clearing_xml-importer_sftp
#import-xml-service.store-lks.sftp-in.user=user
#import-xml-service.store-lks.sftp-in.password=*********
#import-xml-service.store-lks.sftp-in.server-ip=127.0.0.1
#import-xml-service.store-lks.sftp-in.server-port=22
# Hazelcast cluster
import-xml-service.hazelcast.cluster-members=10.200.200.181:5701