swt-exporter http://jira.mfd.msk:8088/browse/CLS-478 windows rn line separator

This commit is contained in:
AKurakin 2023-08-09 10:43:58 +03:00
parent 475c3f99ac
commit 31e8a7af86
7 changed files with 39 additions and 34 deletions

View file

@ -34,7 +34,6 @@ public abstract class AbstractExporterService<T extends SpcexObjectBase> {
private final KafkaSender kafkaSender; private final KafkaSender kafkaSender;
protected final FileStorage fileStorage; protected final FileStorage fileStorage;
protected final Class<T> mapClass; protected final Class<T> mapClass;
protected final String lineSeparator = "\n";
protected AbstractExporterService(FileStorage fileStorage, protected AbstractExporterService(FileStorage fileStorage,
KafkaSender kafkaSender, ImdgProvider imdgProvider, KafkaSender kafkaSender, ImdgProvider imdgProvider,

View file

@ -68,7 +68,7 @@ public class DF09Exporter extends AbstractExporterService<SDf09> {
stringBuilder.append(record.getQuantity()).append(':'); stringBuilder.append(record.getQuantity()).append(':');
stringBuilder.append(record.getSecurityCode()).append(':'); stringBuilder.append(record.getSecurityCode()).append(':');
stringBuilder.append(record.getClientName()).append(':'); stringBuilder.append(record.getClientName()).append(':');
stringBuilder.append(record.getResult()).append(lineSeparator); stringBuilder.append(record.getResult()).append(SWTHeaderData.LINE_SEPARATOR);
return stringBuilder.toString(); return stringBuilder.toString();
} }

View file

@ -55,7 +55,7 @@ public class DF11Exporter extends AbstractExporterService<SDf11> {
stringBuilder.append(record.getQuantity()).append(':'); stringBuilder.append(record.getQuantity()).append(':');
stringBuilder.append(record.getSecurityCode()).append(':'); stringBuilder.append(record.getSecurityCode()).append(':');
stringBuilder.append(record.getClientName()).append(':'); stringBuilder.append(record.getClientName()).append(':');
stringBuilder.append(record.getResult()).append(lineSeparator); stringBuilder.append(record.getResult()).append(SWTHeaderData.LINE_SEPARATOR);
return stringBuilder.toString(); return stringBuilder.toString();
} }

View file

@ -59,17 +59,17 @@ public class DF12Exporter extends AbstractExporterService<SDf12> {
protected String convertRecord(SDf12 record, ConvertionContext context) { protected String convertRecord(SDf12 record, ConvertionContext context) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
if (!Objects.equals(lastHeader20, record.getOutDocument())) { // header if (!Objects.equals(lastHeader20, record.getOutDocument())) { // header
stringBuilder.append(":20:").append(record.getOutDocument()).append(lineSeparator); stringBuilder.append(":20:").append(record.getOutDocument()).append(SWTHeaderData.LINE_SEPARATOR);
lastHeader20 = record.getOutDocument(); lastHeader20 = record.getOutDocument();
} }
stringBuilder.append(":23:").append(record.getDirection()).append(lineSeparator); stringBuilder.append(":23:").append(record.getDirection()).append(SWTHeaderData.LINE_SEPARATOR);
String quantity = record.getQuantity() == null ? "" : record.getQuantity().split("\\.")[0] + ","; String quantity = record.getQuantity() == null ? "" : record.getQuantity().split("\\.")[0] + ",";
stringBuilder.append(":35A:SHS").append(quantity).append(lineSeparator); stringBuilder.append(":35A:SHS").append(quantity).append(SWTHeaderData.LINE_SEPARATOR);
stringBuilder.append(":35B:ISIN ").append(record.getSecurityCode()).append(lineSeparator); stringBuilder.append(":35B:ISIN ").append(record.getSecurityCode()).append(SWTHeaderData.LINE_SEPARATOR);
stringBuilder.append(":82D:").append(record.getDepoCodeSender()).append(lineSeparator); stringBuilder.append(":82D:").append(record.getDepoCodeSender()).append(SWTHeaderData.LINE_SEPARATOR);
stringBuilder.append(":87C:").append(record.getDepoCodeAdressee()).append(lineSeparator); stringBuilder.append(":87C:").append(record.getDepoCodeAdressee()).append(SWTHeaderData.LINE_SEPARATOR);
stringBuilder.append(context.getCountOfRecord()).append(lineSeparator); stringBuilder.append(context.getCountOfRecord()).append(SWTHeaderData.LINE_SEPARATOR);
stringBuilder.append(context.getTotalCountOfRecords()).append(lineSeparator); stringBuilder.append(context.getTotalCountOfRecords()).append(SWTHeaderData.LINE_SEPARATOR);
return stringBuilder.toString(); return stringBuilder.toString();
} }

View file

@ -1,8 +1,6 @@
package ru.spcex.clearing.swt.exporter.services.exportimpl; package ru.spcex.clearing.swt.exporter.services.exportimpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.clearing.classes.statics.data.sdf.SDf11;
import ru.clearing.classes.statics.data.sdf.SDf12;
import ru.clearing.classes.statics.data.sdf.SDf14; import ru.clearing.classes.statics.data.sdf.SDf14;
import ru.spcex.clearing.imdg.IMDGDistributedNames; import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender; import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
@ -58,7 +56,7 @@ public class DF14Exporter extends AbstractExporterService<SDf14> {
@Override @Override
protected String convertRecord(SDf14 record, ConvertionContext context) { protected String convertRecord(SDf14 record, ConvertionContext context) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(RESULT_CONST).append(lineSeparator); stringBuilder.append(RESULT_CONST).append(SWTHeaderData.LINE_SEPARATOR);
return stringBuilder.toString(); return stringBuilder.toString();
} }

View file

@ -4,6 +4,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
public class SWTHeaderData { public class SWTHeaderData {
public static final String LINE_SEPARATOR = "\r\n";
private static final DateTimeFormatter dtInFileHeaderFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'/'HHmm"); private static final DateTimeFormatter dtInFileHeaderFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'/'HHmm");
private String to; private String to;
private String from; private String from;
@ -135,38 +136,38 @@ public class SWTHeaderData {
public String buildString() { public String buildString() {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
if (to != null) { if (to != null) {
stringBuilder.append("To:").append(to).append('\n'); stringBuilder.append("To:").append(to).append(LINE_SEPARATOR);
} }
if (from != null) { if (from != null) {
stringBuilder.append("From:").append(from).append('\n'); stringBuilder.append("From:").append(from).append(LINE_SEPARATOR);
} }
if (type != null) if (type != null)
stringBuilder.append("Type:").append(type).append('\n'); stringBuilder.append("Type:").append(type).append(LINE_SEPARATOR);
if (dateTime != null) { if (dateTime != null) {
String timeS = dtInFileHeaderFormatter.format(dateTime); String timeS = dtInFileHeaderFormatter.format(dateTime);
stringBuilder.append("Date/Time:").append(timeS).append('\n'); stringBuilder.append("Date/Time:").append(timeS).append(LINE_SEPARATOR);
} }
if (valFor20Tag != null) { if (valFor20Tag != null) {
stringBuilder.append(":20:").append(valFor20Tag).append('\n'); stringBuilder.append(":20:").append(valFor20Tag).append(LINE_SEPARATOR);
} }
if (valFor21Tag != null) { if (valFor21Tag != null) {
stringBuilder.append(":21:").append(valFor21Tag).append('\n'); stringBuilder.append(":21:").append(valFor21Tag).append(LINE_SEPARATOR);
} }
if (valFor23Tag != null) { if (valFor23Tag != null) {
stringBuilder.append(":23:").append(valFor23Tag).append('\n'); stringBuilder.append(":23:").append(valFor23Tag).append(LINE_SEPARATOR);
} }
if (valFor35ATag != null) { if (valFor35ATag != null) {
String val = valFor35ATag.split("\\.")[0] + ","; String val = valFor35ATag.split("\\.")[0] + ",";
stringBuilder.append(":35A:SHS").append(val).append('\n'); stringBuilder.append(":35A:SHS").append(val).append(LINE_SEPARATOR);
} }
if (valFor35BTag != null) { if (valFor35BTag != null) {
stringBuilder.append(":35B:ISIN ").append(valFor35BTag).append('\n'); stringBuilder.append(":35B:ISIN ").append(valFor35BTag).append(LINE_SEPARATOR);
} }
if (valFor82DTag != null) { if (valFor82DTag != null) {
stringBuilder.append(":82D:").append(valFor82DTag).append('\n'); stringBuilder.append(":82D:").append(valFor82DTag).append(LINE_SEPARATOR);
} }
if (valFor87CTag != null) { if (valFor87CTag != null) {
stringBuilder.append(":87C:").append(valFor87CTag).append('\n'); stringBuilder.append(":87C:").append(valFor87CTag).append(LINE_SEPARATOR);
} }
return stringBuilder.toString(); return stringBuilder.toString();
} }

View file

@ -1,5 +1,6 @@
package ru.spcex.clearing.swt.exporter.services.exportimpl; package ru.spcex.clearing.swt.exporter.services.exportimpl;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import ru.clearing.classes.statics.data.sdf.SDf09; import ru.clearing.classes.statics.data.sdf.SDf09;
@ -10,6 +11,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.time.TimeUtil; import ru.spcex.platform.utils.time.TimeUtil;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream; import java.io.OutputStream;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
@ -27,7 +29,7 @@ class DF09ExporterTest {
rec1.setOutDocument("test1"); rec1.setOutDocument("test1");
rec1.setInDocument("test2"); rec1.setInDocument("test2");
rec1.setDepoCode("test3"); rec1.setDepoCode("test3");
rec1.setQuantity("test4"); rec1.setQuantity("4567");
rec1.setSecurityCode("test5"); rec1.setSecurityCode("test5");
rec1.setClientName("test6"); rec1.setClientName("test6");
rec1.setResult("test7"); rec1.setResult("test7");
@ -45,15 +47,20 @@ class DF09ExporterTest {
ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
exporter.makeSWTData(header, records, outBytes); exporter.makeSWTData(header, records, outBytes);
String out = outBytes.toString(); String out = outBytes.toString();
// try {
// FileUtils.write(new File("E:\\test_encode.txt"), out, "windows-1251");
// } catch (Exception e){}
assertTrue(out.length() > 35); assertTrue(out.length() > 35);
// assertEquals("To:CSO\n" + out=out.replaceAll("Date/Time.*","Date/Time:XXXX");
// "From:SPCE\n" + out=out.replaceAll(":20:.*",":20:XXXX");
// "Type:009\n" + assertEquals("To:CSO\r\n" +
// "Date/Time:20230530/1457\n" + "From:SPCE\r\n" +
// ":20:7cf8af93-1a5e-456e-85c7-bca92dd36797\n" + // random UUID "Type:009\r\n" +
// ":21:test2\n" + "Date/Time:XXXX\r\n" +
// "test3:test4:test5:test6:test7\n" + ":20:XXXX\r\n" +
// "1\n", out); ":21:test2\r\n" +
"test3:4567:test5:test6:test7\r\n" +
"4567", out);
} }
private static class TestableExporter extends DF09Exporter { private static class TestableExporter extends DF09Exporter {