Commit a34eacc9 by zhanghou

Merge branch 'newMater' of http://114.115.138.98:8900//cheng/swiftMx2Mt into newMater

parents 91825a2d 01abda01
......@@ -4,69 +4,5 @@ public class Mt2MxContextIdentifier {
public static final String MT_TO_MX_OUTPUT_FILE_PATH = "mt.to.mx.output.filepath";
public static final String MT_TO_MX_XML = "mt.to.mx.xml";
public static final String MX_UETR = "mt.uetr";
public static final String MX_APP_HEADER = "mt.app.header";
/**
* 20
*/
public static final String MX_MSG_ID = "mx.msgid";
/**
* 13C
*/
public static final String MX_DEBIT_DATETIME = "mx.debit.datetime";
public static final String MX_CREDIT_DATETIME = "mx.credit.datetime";
public static final String MX_CLS_DATETIME = "mx.cls.datetime";
/**
* 23B
*/
public static final String MX_BUSINESS_CODE = "mx.business.code";
/**
* 23E
*/
public static final String MX_INSTRUCTION_CODE = "mx.Instruction.code.list";
/**
* 26T
*/
public static final String MX_TRANSACTION_TYPE_CODE = "mx.transaction.type.code";
/**
* 32A date
*/
public static final String MX_VALUE_DATE = "mx.value.date";
/**
* 32A ccy amt
*/
public static final String MX_SETTLE_CCY_AMOUNT = "mx.settle.ccy.amount";
/**
* 33B ccy amt
*/
public static final String MX_INSTRUCTED_CCY_AMOUNT = "mx.instructed.ccy.amount";
/**
* 36 exchangeRate
*/
public static final String MX_EXCHANGE_RATE = "mx.exchange.rate";
/**
* 70 Remittance Information
*/
public static final String MX_REMITTANCE_INFORMATION = "mx.remittance.information.list";
/**
* 71 ChargeFor
*/
public static final String MX_CHARGE_FOR = "mx.charge_for";
/**
* 71 chargeCcyAmount
*/
public static final String MX_CHARGE_CCY_AMOUNT = "mx.charge_ccy.amount";
/**
* 72 Sender to Receiver Information
*/
public static final String MX_SENDER_TO_RECEIVER_INFORMATION = "mx.sender.to.receiver.information.list";
/**
* 77 Regulatory Reporting
*/
public static final String MX_REGULATORY_REPORTING = "mx.regulatory.reporting.list";
public static final String MT_TO_SWIFTDTO_OBJ = "mt.to.swiftdto.obj";
}
......@@ -2,6 +2,8 @@ package com.brilliance.swift.mt2mx;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs008001.Mt2MxPacs00801Creator;
import com.brilliance.swift.mx.SwiftDto2MxCreatorManager;
import com.brilliance.swift.vo.SwiftDto;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import org.apache.commons.io.FileUtils;
......@@ -21,12 +23,22 @@ public class Mt2MxCreateManager {
}
}
public String mt2mx(File file, String outPutFilePath, Map<String, Object> extraMap) throws Exception {
public SwiftDto mt2SwiftDto(File file, String outPutFilePath, Map<String, Object> extraMap) throws Exception {
String mtStr = FileUtils.readFileToString(file);
init(mtStr);
return convert(outPutFilePath, extraMap);
}
public SwiftDto mt2SwiftDto(String mtStr, String outPutFilePath, Map<String, Object> extraMap) throws Exception {
init(mtStr);
return convert(outPutFilePath, extraMap);
}
public String mt2mx(File file, String outPutFilePath, Map<String, Object> extraMap) throws Exception {
SwiftDto swiftDto = mt2SwiftDto(file, outPutFilePath, extraMap);
return new SwiftDto2MxCreatorManager().swiftDto2Mx(swiftDto, outPutFilePath);
}
public String mt2mx(File file, String outPutFilePath) throws Exception {
return mt2mx(file, outPutFilePath, null);
}
......@@ -36,8 +48,8 @@ public class Mt2MxCreateManager {
}
public String mt2mx(String mtStr, String outPutFilePath, Map<String, Object> extraMap) throws Exception {
init(mtStr);
return convert(outPutFilePath, extraMap);
SwiftDto swiftDto = mt2SwiftDto(mtStr, outPutFilePath, extraMap);
return new SwiftDto2MxCreatorManager().swiftDto2Mx(swiftDto, outPutFilePath);
}
public String mt2mx(String mtStr, String outPutFilePath) throws Exception {
......@@ -48,7 +60,7 @@ public class Mt2MxCreateManager {
return mt2mx(mtStr, null, null);
}
public String convert(String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
public SwiftDto convert(String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
AbstractMt2MxCreator creator = getMt2MxCreator();
Mt2MxContext context = new Mt2MxContext();
context.set(AbstractMT.class, abstractMT);
......@@ -63,8 +75,7 @@ public class Mt2MxCreateManager {
parseField.parseFields();
}
creator.postProcess();
String xmlStr = (String)context.get(Mt2MxContextIdentifier.MT_TO_MX_XML);
return xmlStr;
return (SwiftDto) context.get(Mt2MxContextIdentifier.MT_TO_SWIFTDTO_OBJ);
}
public AbstractMt2MxCreator getMt2MxCreator() throws SwiftException {
......
......@@ -5,10 +5,11 @@ import com.brilliance.swift.mt2mx.AbstractMt2MxCreator;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.Mt2MxParseFields;
import com.brilliance.swift.mt2mx.pacs008001.impl.*;
import com.brilliance.swift.mx.SwiftDto2MxCreatorManager;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.SwiftDto;
import com.brilliance.swift.vo.VoCustomerCreditTransfer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
......@@ -27,6 +28,7 @@ public class Mt2MxPacs00801Creator extends AbstractMt2MxCreator {
customerCreditTransfer.setCreateDate(swiftDto.getCreateDate());
customerCreditTransfer.setMessagePriority(swiftDto.getMessagePriority());
customerCreditTransfer.setUetr(swiftDto.getUetr());
customerCreditTransfer.setMessageType("pacs.008.001");
context.set(customerCreditTransfer);
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......@@ -64,8 +66,10 @@ public class Mt2MxPacs00801Creator extends AbstractMt2MxCreator {
try {
String outputFilePath = (String)context.get(Mt2MxContextIdentifier.MT_TO_MX_OUTPUT_FILE_PATH, true);
VoCustomerCreditTransfer customerCreditTransfer = context.get(VoCustomerCreditTransfer.class);
String xmlStr = new SwiftDto2MxCreatorManager().swiftDto2Mx(customerCreditTransfer, outputFilePath);
context.set(Mt2MxContextIdentifier.MT_TO_MX_XML, xmlStr);
context.set(Mt2MxContextIdentifier.MT_TO_SWIFTDTO_OBJ, customerCreditTransfer);
if (StringUtil.isNotEmpty(outputFilePath)) {
customerCreditTransfer.write(new File(outputFilePath));
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
}
......
......@@ -3,12 +3,10 @@ package com.brilliance.swift.mt2mx.pacs008001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.AbstractMt2MxParseFields;
import com.brilliance.swift.vo.VoCustomerCreditTransfer;
import com.brilliance.swift.vo.common.InstructionCode;
import com.prowidesoftware.swift.model.field.Field23E;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.ArrayList;
import java.util.List;
public class Pacs00801Parse23EField extends AbstractMt2MxParseFields {
......@@ -21,10 +19,7 @@ public class Pacs00801Parse23EField extends AbstractMt2MxParseFields {
if (field23EList.size() > 0) {
for (int i=0; i<field23EList.size(); i++) {
Field23E field23E = field23EList.get(i);
InstructionCode instructionCode = new InstructionCode();
instructionCode.setCode(field23E.getCode());
instructionCode.setCode(field23E.getAdditionalInformation());
customerCreditTransfer.addInstructionCode(instructionCode);
customerCreditTransfer.addInstructionCode(field23E.getValue());
}
}
} catch (Exception e) {
......
......@@ -11,8 +11,6 @@ import com.prowidesoftware.swift.model.field.Field50K;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.List;
public class Pacs00801Parse50Field extends AbstractMt2MxParseFields {
@Override
public void parseFields() throws SwiftException {
......@@ -55,7 +53,7 @@ public class Pacs00801Parse50Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setDebitParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -11,8 +11,6 @@ import com.prowidesoftware.swift.model.field.Field52D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.List;
public class Pacs00801Parse52Field extends AbstractMt2MxParseFields {
@Override
public void parseFields() throws SwiftException {
......@@ -53,7 +51,7 @@ public class Pacs00801Parse52Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setDebitAgtParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -12,8 +12,6 @@ import com.prowidesoftware.swift.model.field.Field53D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.List;
public class Pacs00801Parse53Field extends AbstractMt2MxParseFields {
@Override
public void parseFields() throws SwiftException {
......@@ -57,7 +55,7 @@ public class Pacs00801Parse53Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setInstgAgtParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -12,8 +12,6 @@ import com.prowidesoftware.swift.model.field.Field54D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.List;
public class Pacs00801Parse54Field extends AbstractMt2MxParseFields {
@Override
public void parseFields() throws SwiftException {
......@@ -57,7 +55,7 @@ public class Pacs00801Parse54Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setInstdAgtParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -12,8 +12,6 @@ import com.prowidesoftware.swift.model.field.Field55D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.List;
public class Pacs00801Parse55Field extends AbstractMt2MxParseFields {
@Override
public void parseFields() throws SwiftException {
......@@ -57,7 +55,7 @@ public class Pacs00801Parse55Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setThridAgtParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -56,7 +56,7 @@ public class Pacs00801Parse56Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setIntrmyAgtParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -13,8 +13,6 @@ import com.prowidesoftware.swift.model.field.Field57D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import java.util.List;
public class Pacs00801Parse57Field extends AbstractMt2MxParseFields {
@Override
public void parseFields() throws SwiftException {
......@@ -62,7 +60,7 @@ public class Pacs00801Parse57Field extends AbstractMt2MxParseFields {
}
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setCreditAgtParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -55,7 +55,7 @@ public class Pacs00801Parse59Field extends AbstractMt2MxParseFields {
//TODO
}
if (partyDto != null) {
customerCreditTransfer.addPartyDto(partyDto);
customerCreditTransfer.setCreditParty(partyDto);
}
} catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage());
......
......@@ -3,8 +3,6 @@ package com.brilliance.swift.mt2mx.pacs008001.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.AbstractMt2MxParseFields;
import com.brilliance.swift.vo.VoCustomerCreditTransfer;
import com.brilliance.swift.vo.common.SenderToReceiverInformation;
import com.brilliance.swift.vo.common.SenderToReceiverInformationType;
import com.prowidesoftware.swift.model.field.Field72;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
......@@ -21,24 +19,14 @@ public class Pacs00801Parse72Field extends AbstractMt2MxParseFields {
String[] lines = field72Value.split("\r\n");
for (int i=0; i<lines.length; i++) {
String line = lines[i];
SenderToReceiverInformation strInfo = null;
if (line.startsWith("/INS/")) {
strInfo = new SenderToReceiverInformation();
strInfo.setType(SenderToReceiverInformationType.PIA);
strInfo.setInstructionInformation(line.substring(5));
customerCreditTransfer.setPreInstgAgtInfo(line.substring(5));
}
if (line.startsWith("/ACC/")) {
strInfo = new SenderToReceiverInformation();
strInfo.setType(SenderToReceiverInformationType.IFCA);
strInfo.setInstructionInformation(line.substring(5));
customerCreditTransfer.setInstForCrdAgtInfo(line.substring(5));
}
if (line.startsWith("/REC/")) {
strInfo = new SenderToReceiverInformation();
strInfo.setType(SenderToReceiverInformationType.IFNA);
strInfo.setInstructionInformation(line.substring(5));
}
if (strInfo != null) {
customerCreditTransfer.addSenderToReceiverInformation(strInfo);
customerCreditTransfer.setInstForNxtAgtInfo(line.substring(5));
}
}
}
......
......@@ -3,9 +3,23 @@ package com.brilliance.swift.mx;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx.pacs00801.SwiftDto2MxPacs008001Creator;
import com.brilliance.swift.vo.SwiftDto;
import org.apache.commons.io.FileUtils;
import java.io.File;
public class SwiftDto2MxCreatorManager {
public String swiftDto2Mx(File file, String fileOutputPath) throws Exception {
String gsonStr = FileUtils.readFileToString(file);
SwiftDto swiftDto = SwiftDto.fromJson(gsonStr);
return swiftDto2Mx(swiftDto, fileOutputPath);
}
public String swiftDto2Mx(String gsonStr, String fileOutputPath) {
SwiftDto swiftDto = SwiftDto.fromJson(gsonStr);
return swiftDto2Mx(swiftDto, fileOutputPath);
}
public String swiftDto2Mx(SwiftDto swiftDto, String fileOutputPath) throws SwiftException {
try {
SwiftDto2MxContext context = new SwiftDto2MxContext();
......
......@@ -26,42 +26,14 @@ public class SwiftDto2MxPacs008001Creator extends AbstractSwiftDto2MxCreator {
return;
}
MxPacs00800109 mxPacs00800109 = new MxPacs00800109();
List<PartyDto> partyDtos = customerCreditTransfer.getPartyDtoList();
PartyDto instructingReimbursementParty = null;//53
PartyDto instructedReimbursementParty = null;//54
PartyDto thirdReimbursementParty = null;//55
PartyDto dbtrParty = null;//50
PartyDto dbtrAgtParty = null;//52
PartyDto intrmyAgt1Party = null;//56
PartyDto cdtrAgtParty = null;//57
PartyDto cdtrParty = null;//59
for (PartyDto partyDto : partyDtos) {
if (PartyTypeEnum.SC.equals(partyDto.getPartyType())) {
instructingReimbursementParty = partyDto;
}
if (PartyTypeEnum.RC.equals(partyDto.getPartyType())) {
instructedReimbursementParty = partyDto;
}
if (PartyTypeEnum.RI.equals(partyDto.getPartyType())) {
thirdReimbursementParty = partyDto;
}
if (PartyTypeEnum.OC.equals(partyDto.getPartyType())) {
dbtrParty = partyDto;
}
if (PartyTypeEnum.OI.equals(partyDto.getPartyType())) {
dbtrAgtParty = partyDto;
}
if (PartyTypeEnum.II.equals(partyDto.getPartyType())) {
intrmyAgt1Party = partyDto;
}
if (PartyTypeEnum.AI.equals(partyDto.getPartyType())) {
cdtrAgtParty = partyDto;
}
if (PartyTypeEnum.BC.equals(partyDto.getPartyType())) {
cdtrParty = partyDto;
}
}
PartyDto instructingReimbursementParty = customerCreditTransfer.getInstgAgtParty();//53
PartyDto instructedReimbursementParty = customerCreditTransfer.getInstdAgtParty();//54
PartyDto thirdReimbursementParty = customerCreditTransfer.getThridAgtParty();//55
PartyDto dbtrParty = customerCreditTransfer.getDebitParty();//50
PartyDto dbtrAgtParty = customerCreditTransfer.getDebitAgtParty();//52
PartyDto intrmyAgt1Party = customerCreditTransfer.getIntrmyAgtParty();//56
PartyDto cdtrAgtParty = customerCreditTransfer.getCreditAgtParty();//57
PartyDto cdtrParty = customerCreditTransfer.getCreditParty();//59
//set AppHdr
BusinessAppHdrV02 businessAppHdrV02 = new BusinessAppHdrV02();
Party44Choice fr = new Party44Choice();
......@@ -284,35 +256,27 @@ public class SwiftDto2MxPacs008001Creator extends AbstractSwiftDto2MxCreator {
}
//PrvsInstgAgt1 InstrForCdtrAgt InstrForNxtAgt
List<SenderToReceiverInformation> strInfolist = customerCreditTransfer.getSenderToReceiverInformationList();
if (strInfolist != null && strInfolist.size() > 0) {
for (int i=0; i<strInfolist.size(); i++) {
SenderToReceiverInformation strInfo = strInfolist.get(i);
String instInfo = strInfo.getInstructionInformation();
if (SenderToReceiverInformationType.PIA.equals(strInfo.getType())) {
BranchAndFinancialInstitutionIdentification6 prvsInstgAgt1 = new BranchAndFinancialInstitutionIdentification6();
FinancialInstitutionIdentification18 finInstnId = new FinancialInstitutionIdentification18();
if (SwiftTransferUtil.isBIC(instInfo)) {
finInstnId.setBICFI(instInfo);
} else {
finInstnId.setNm(instInfo);
}
prvsInstgAgt1.setFinInstnId(finInstnId);
cdtTrfTxInf.setPrvsInstgAgt1(prvsInstgAgt1);
}
if (SenderToReceiverInformationType.IFCA.equals(strInfo.getType())) {
InstructionForCreditorAgent3 instructionForCreditorAgent3 = new InstructionForCreditorAgent3();
instructionForCreditorAgent3.setInstrInf(instInfo);
cdtTrfTxInf.addInstrForCdtrAgt(instructionForCreditorAgent3);
}
if (SenderToReceiverInformationType.IFNA.equals(strInfo.getType())) {
InstructionForNextAgent1 instructionForNextAgent1 = new InstructionForNextAgent1();
instructionForNextAgent1.setInstrInf(instInfo);
cdtTrfTxInf.addInstrForNxtAgt(instructionForNextAgent1);
}
if (StringUtil.isNotEmpty(customerCreditTransfer.getPreInstgAgtInfo())) {
BranchAndFinancialInstitutionIdentification6 prvsInstgAgt1 = new BranchAndFinancialInstitutionIdentification6();
FinancialInstitutionIdentification18 finInstnId = new FinancialInstitutionIdentification18();
if (SwiftTransferUtil.isBIC(customerCreditTransfer.getPreInstgAgtInfo())) {
finInstnId.setBICFI(customerCreditTransfer.getPreInstgAgtInfo());
} else {
finInstnId.setNm(customerCreditTransfer.getPreInstgAgtInfo());
}
prvsInstgAgt1.setFinInstnId(finInstnId);
cdtTrfTxInf.setPrvsInstgAgt1(prvsInstgAgt1);
}
if (StringUtil.isNotEmpty(customerCreditTransfer.getInstForCrdAgtInfo())) {
InstructionForCreditorAgent3 instructionForCreditorAgent3 = new InstructionForCreditorAgent3();
instructionForCreditorAgent3.setInstrInf(customerCreditTransfer.getInstForCrdAgtInfo());
cdtTrfTxInf.addInstrForCdtrAgt(instructionForCreditorAgent3);
}
if (StringUtil.isNotEmpty(customerCreditTransfer.getInstForNxtAgtInfo())) {
InstructionForNextAgent1 instructionForNextAgent1 = new InstructionForNextAgent1();
instructionForNextAgent1.setInstrInf(customerCreditTransfer.getInstForNxtAgtInfo());
cdtTrfTxInf.addInstrForNxtAgt(instructionForNextAgent1);
}
//RgltryRptg
List<String> rpList = customerCreditTransfer.getRegulatoryReportingList();
if (rpList != null && rpList.size() > 0) {
......
package com.brilliance.swift.vo;
import com.brilliance.swift.util.DateUtil;
import com.google.gson.*;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.util.Date;
public class DateAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> {
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss,SSS";
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
return DateUtil.parseDate(json.getAsString(), DATE_FORMAT);
} catch (ParseException e) {
throw new JsonParseException(e.getMessage());
}
}
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
String dateStr = DateUtil.format(src, DATE_FORMAT);
return new JsonPrimitive(dateStr);
}
}
package com.brilliance.swift.vo;
import com.brilliance.swift.vo.common.MessagePriority;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.Validate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
public class SwiftDto {
......@@ -75,4 +82,36 @@ public class SwiftDto {
public void setUetr(String uetr) {
this.uetr = uetr;
}
public String toJson() {
final Gson gson = new GsonBuilder()
.registerTypeAdapter(SwiftDto.class, new SwiftDtoAdapter())
.registerTypeAdapter(Date.class, new DateAdapter())
.setPrettyPrinting()
.create();
return gson.toJson(this, this.getClass());
}
public static SwiftDto fromJson(String json) {
final Gson gson = new GsonBuilder()
.registerTypeAdapter(SwiftDto.class, new SwiftDtoAdapter())
.registerTypeAdapter(Date.class, new DateAdapter())
.create();
return gson.fromJson(json, SwiftDto.class);
}
public void write(final File file) throws IOException {
Validate.notNull(file, "the file to write cannot be null");
if (!file.exists()) {
file.createNewFile();
}
final FileOutputStream stream = new FileOutputStream(file.getAbsoluteFile());
write(stream);
stream.close();
}
public void write(final OutputStream stream) throws IOException {
Validate.notNull(stream, "the stream to write cannot be null");
stream.write(toJson().getBytes("UTF-8"));
}
}
package com.brilliance.swift.vo;
import com.google.gson.*;
import java.lang.reflect.Type;
public class SwiftDtoAdapter implements JsonSerializer<SwiftDto>, JsonDeserializer<SwiftDto> {
private static final String MESSAGETYPE = "messageType";
@Override
public SwiftDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
JsonPrimitive prim = (JsonPrimitive) jsonObject.get(MESSAGETYPE);
if (prim == null) {
throw new JsonParseException("Missing " + MESSAGETYPE + " in JSON structure");
}
Class<?> klass = null;
try {
String className = "";
if ("pacs.008.001".equals(prim.getAsString())) {
className = "com.brilliance.swift.vo.VoCustomerCreditTransfer";
}
klass = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new JsonParseException("Cannot find MX implementation for " + e.getMessage());
}
return context.deserialize(json, klass);
}
@Override
public JsonElement serialize(SwiftDto src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject object = context.serialize(src).getAsJsonObject();
return object;
}
}
......@@ -20,7 +20,7 @@ public class VoCustomerCreditTransfer extends SwiftDto {
protected String bussinessCode;
protected List<InstructionCode> instructionCodes;
protected List<String> instructionCodes;
protected String txnTypeCode;
......@@ -32,7 +32,21 @@ public class VoCustomerCreditTransfer extends SwiftDto {
protected BigDecimal exchangeRate;
protected List<PartyDto> partyDtos;
protected PartyDto debitParty;
protected PartyDto debitAgtParty;
protected PartyDto instgAgtParty;
protected PartyDto instdAgtParty;
protected PartyDto thridAgtParty;
protected PartyDto intrmyAgtParty;
protected PartyDto creditAgtParty;
protected PartyDto creditParty;
protected List<String> remittanceInfos;
......@@ -40,7 +54,11 @@ public class VoCustomerCreditTransfer extends SwiftDto {
protected CcyFormatAmount chargeCcyFormatAmount;
protected List<SenderToReceiverInformation> senderToReceiverInformations;
protected String preInstgAgtInfo;
protected String instForCrdAgtInfo;
protected String instForNxtAgtInfo;
protected List<String> regulatoryReportings;
......@@ -132,30 +150,18 @@ public class VoCustomerCreditTransfer extends SwiftDto {
this.chargeCcyFormatAmount = chargeCcyFormatAmount;
}
public List<InstructionCode> getInstructionCodeList() {
public List<String> getInstructionCodeList() {
if (instructionCodes == null) {
instructionCodes = new ArrayList<>();
}
return this.instructionCodes;
}
public VoCustomerCreditTransfer addInstructionCode(InstructionCode instructionCode) {
public VoCustomerCreditTransfer addInstructionCode(String instructionCode) {
getInstructionCodeList().add(instructionCode);
return this;
}
public List<PartyDto> getPartyDtoList() {
if (partyDtos == null) {
partyDtos = new ArrayList<>();
}
return this.partyDtos;
}
public VoCustomerCreditTransfer addPartyDto(PartyDto partyDto) {
getPartyDtoList().add(partyDto);
return this;
}
public List<String> getRemittanceInfoList() {
if (remittanceInfos == null) {
remittanceInfos = new ArrayList<>();
......@@ -168,18 +174,6 @@ public class VoCustomerCreditTransfer extends SwiftDto {
return this;
}
public List<SenderToReceiverInformation> getSenderToReceiverInformationList() {
if (senderToReceiverInformations == null) {
senderToReceiverInformations = new ArrayList<>();
}
return this.senderToReceiverInformations;
}
public VoCustomerCreditTransfer addSenderToReceiverInformation(SenderToReceiverInformation senderToReceiverInformation) {
getSenderToReceiverInformationList().add(senderToReceiverInformation);
return this;
}
public List<String> getRegulatoryReportingList() {
if (regulatoryReportings == null) {
regulatoryReportings = new ArrayList<>();
......@@ -192,8 +186,122 @@ public class VoCustomerCreditTransfer extends SwiftDto {
return this;
}
public PartyDto getDebitParty() {
return debitParty;
}
public void setDebitParty(PartyDto debitParty) {
this.debitParty = debitParty;
}
public PartyDto getDebitAgtParty() {
return debitAgtParty;
}
public void setDebitAgtParty(PartyDto debitAgtParty) {
this.debitAgtParty = debitAgtParty;
}
public PartyDto getInstgAgtParty() {
return instgAgtParty;
}
public void setInstgAgtParty(PartyDto instgAgtParty) {
this.instgAgtParty = instgAgtParty;
}
public PartyDto getInstdAgtParty() {
return instdAgtParty;
}
public void setInstdAgtParty(PartyDto instdAgtParty) {
this.instdAgtParty = instdAgtParty;
}
public PartyDto getThridAgtParty() {
return thridAgtParty;
}
public void setThridAgtParty(PartyDto thridAgtParty) {
this.thridAgtParty = thridAgtParty;
}
public PartyDto getIntrmyAgtParty() {
return intrmyAgtParty;
}
public void setIntrmyAgtParty(PartyDto intrmyAgtParty) {
this.intrmyAgtParty = intrmyAgtParty;
}
public PartyDto getCreditAgtParty() {
return creditAgtParty;
}
public void setCreditAgtParty(PartyDto creditAgtParty) {
this.creditAgtParty = creditAgtParty;
}
public PartyDto getCreditParty() {
return creditParty;
}
public void setCreditParty(PartyDto creditParty) {
this.creditParty = creditParty;
}
public String getPreInstgAgtInfo() {
return preInstgAgtInfo;
}
public void setPreInstgAgtInfo(String preInstgAgtInfo) {
this.preInstgAgtInfo = preInstgAgtInfo;
}
public String getInstForCrdAgtInfo() {
return instForCrdAgtInfo;
}
public void setInstForCrdAgtInfo(String instForCrdAgtInfo) {
this.instForCrdAgtInfo = instForCrdAgtInfo;
}
public String getInstForNxtAgtInfo() {
return instForNxtAgtInfo;
}
public void setInstForNxtAgtInfo(String instForNxtAgtInfo) {
this.instForNxtAgtInfo = instForNxtAgtInfo;
}
@Override
public String getMessageType() {
return "pacs.008.001";
public String toString() {
return "VoCustomerCreditTransfer{" +
"debitDate=" + debitDate +
", creditDate=" + creditDate +
", clsDate=" + clsDate +
", bussinessCode='" + bussinessCode + '\'' +
", instructionCodes=" + instructionCodes +
", txnTypeCode='" + txnTypeCode + '\'' +
", settledDate=" + settledDate +
", settledCcyFormatAmount=" + settledCcyFormatAmount +
", InstructedCcyFormatAmount=" + InstructedCcyFormatAmount +
", exchangeRate=" + exchangeRate +
", debitParty=" + debitParty +
", debitAgtParty=" + debitAgtParty +
", instgAgtParty=" + instgAgtParty +
", instdAgtParty=" + instdAgtParty +
", thridAgtParty=" + thridAgtParty +
", intrmyAgtParty=" + intrmyAgtParty +
", creditAgtParty=" + creditAgtParty +
", creditParty=" + creditParty +
", remittanceInfos=" + remittanceInfos +
", chargeFor=" + chargeFor +
", chargeCcyFormatAmount=" + chargeCcyFormatAmount +
", preInstgAgtInfo='" + preInstgAgtInfo + '\'' +
", instForCrdAgtInfo='" + instForCrdAgtInfo + '\'' +
", instForNxtAgtInfo='" + instForNxtAgtInfo + '\'' +
", regulatoryReportings=" + regulatoryReportings +
'}';
}
}
package com.brilliance.swift.vo.common;
public class InstructionCode{
private String code;
private String additionalInformation;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getAdditionalInformation() {
return additionalInformation;
}
public void setAdditionalInformation(String additionalInformation) {
this.additionalInformation = additionalInformation;
}
}
package com.brilliance.swift.vo.common;
public class SenderToReceiverInformation {
private SenderToReceiverInformationType type;
private String InstructionInformation;
public SenderToReceiverInformationType getType() {
return type;
}
public void setType(SenderToReceiverInformationType type) {
this.type = type;
}
public String getInstructionInformation() {
return InstructionInformation;
}
public void setInstructionInformation(String instructionInformation) {
InstructionInformation = instructionInformation;
}
}
package com.brilliance.swift.vo.common;
public enum SenderToReceiverInformationType {
PIA("Previous Instructing Agent"),
IFCA("Instruction For Creditor Agent"),
IFNA("Instruction For Next Agent");
SenderToReceiverInformationType(String s) {
this.desc = s;
}
public String value() {
return name();
}
String desc;
public String desc() {
return desc;
}
}
{
"debitDate": "2022-04-21 22:24:00,000",
"creditDate": "2022-04-22 00:30:00,000",
"clsDate": "2022-04-21 23:21:00,000",
"bussinessCode": "SDVA",
"instructionCodes": [
{
"code": "SDVA"
},
{
"code": "BNKK"
},
{
"code": "GHJK",
"additionalInformation": "789556"
}
],
"txnTypeCode": "GCY",
"settledDate": "2022-03-13 00:00:00,000",
"settledCcyFormatAmount": {
"ccy": "USD",
"amt": 23453.13
},
"InstructedCcyFormatAmount": {
"ccy": "EUR",
"amt": 1345.12
},
"exchangeRate": 17.4357135422,
"partyDtos": [
{
"partyType": "OC",
"partyBic": "GCYXXXXXX12",
"partyAcct": "01111001759234567890",
"addressList": []
},
{
"partyType": "OI",
"partyBic": "FOOBARC0",
"addressList": []
},
{
"partyType": "SC",
"partyBic": "FOOBARC1",
"addressList": []
},
{
"partyType": "RC",
"partyBic": "FOOBARC3",
"addressList": []
},
{
"partyType": "RI",
"partyBic": "FOOBARC4",
"addressList": []
},
{
"partyType": "II",
"partyBic": "FOOBARC6",
"addressList": []
},
{
"partyType": "AI",
"partyBic": "BANKANC7",
"addressList": []
},
{
"partyType": "BC",
"partyName": "TEST CORP",
"partyIBANAcct": "00013500510020179998",
"addressList": [
"Nellis ABC, NV"
]
}
],
"remittanceInfos": [
"gechengyang"
],
"chargeFor": "DEBT",
"chargeCcyFormatAmount": {
"ccy": "USD",
"amt": 12.43
},
"senderToReceiverInformations": [
{
"type": "PIA",
"InstructionInformation": "FOOBARC7"
},
{
"type": "IFCA",
"InstructionInformation": "789556"
}
],
"regulatoryReportings": [
"/ORDERRES/BE//MEILAAN 1, 9000 GENT",
"//JIANGXIAQU",
"//WENHUADADAO"
],
"messageType": "pacs.008.001",
"senderBic": "BANKANC0",
"receiverBic": "FOOBARC0",
"createDate": "2022-04-21 17:41:30,705",
"messagePriority": "NORM",
"messageId": "TBEXO12345",
"uetr": "8a562c67-ca16-48ba-b074-65581be6f001"
}
\ No newline at end of file
package com.brilliance.mt2mx.pacs008001;
import com.brilliance.swift.mt2mx.Mt2MxCreateManager;
import org.apache.commons.io.FileUtils;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
......@@ -9,8 +9,10 @@ public class TestPacs008001 {
public static void main(String[] args) throws Exception {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT103.txt");
String mtStr = FileUtils.readFileToString(file);
String xmlStr = new Mt2MxCreateManager().mt2mx(file, "d:/test/pacs008.xml", null);
System.out.println(xmlStr);
//String xmlStr = new Mt2MxCreateManager().mt2mx(file, "d:/test/pacs008.xml", null);
//System.out.println(xmlStr);
SwiftDto swiftDto = new Mt2MxCreateManager().mt2SwiftDto(file, "d:/test/pacs008.txt", null);
System.out.println(swiftDto.toString());
}
}
package com.brilliance.mx.pacs008001;
import com.brilliance.swift.mx.SwiftDto2MxCreatorManager;
import java.io.File;
public class TestPacs008001_GSON {
public static void main(String[] args) throws Exception {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\customercredittransfer.txt");
String xmlStr = new SwiftDto2MxCreatorManager().swiftDto2Mx(file, "d:/test/pacs008_json.xml");
System.out.println(xmlStr);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment