Commit 8d648a52 by chengzhuoshen

MX2MT:pacs002001转mtN99

parent 9a6e1316
......@@ -47,6 +47,10 @@ public class Mx2MtConstants {
public static final String MT_TYPE_210 = "210";
public static final String MT_TYPE_199 = "199";
public static final String MT_TYPE_299 = "299";
public static final String OUT_PUT_FILE_PATH = "outPutFilePath";
public static final String MX_OBJECT = "mxObj";
......
......@@ -13,6 +13,7 @@ import com.brilliance.swift.mx2mt.mt210.Mx2Mt210Creator;
import com.brilliance.swift.mx2mt.mt900910.Mx2Mt900910Creator;
import com.brilliance.swift.mx2mt.mt940950.Mx2Mt940950Creator;
import com.brilliance.swift.mx2mt.mt941942.Mx2Mt941942Creator;
import com.brilliance.swift.mx2mt.mtn99.Mx2MtN99Creator;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.prowidesoftware.swift.model.mx.AbstractMX;
......@@ -92,7 +93,9 @@ public class Mx2MtCreatorManager {
return new Mx2Mt205RetnCreator();
} else if("camt.057.001".equals(messageType)){
return new Mx2Mt210Creator();
}else {
} else if("pacs.002.001".equals(messageType)){
return new Mx2MtN99Creator();
} else {
throw new SwiftException("ERROR", "Invalid message type");
}
}
......
package com.brilliance.swift.mx2mt.mtn99;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtCreator;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.mx2mt.Mx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.mtn99.impl.Field20Generate;
import com.brilliance.swift.mx2mt.mtn99.impl.Field21Generate;
import com.brilliance.swift.mx2mt.mtn99.impl.Field79Generate;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.prowidesoftware.swift.model.SwiftBlock3;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.field.Field121;
import org.dom4j.Document;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Mx2MtN99Creator extends AbstractMx2MtCreator {
@Override
public void preProcess() {
super.preProcess();
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
context.set(Mx2MtContextIdentifier.APPHDR_PARENT_ELEMENT_NAME, parentElementMaps.get("AppHdr"));
context.set(Mx2MtContextIdentifier.GRPHDR_PARENT_ELEMENT_NAME, parentElementMaps.get("GrpHdr"));
context.set(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, parentElementMaps.get("TxInfAndSts"));
}
@Override
public void withBlock3() throws SwiftException {
super.withBlock3();
SwiftBlock3 block3 = context.get(SwiftMessage.class).getBlock3();
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
String bodyParentPath = (String)context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, true);
String uetr = getXmlNodeValue(bodyParentPath, document, "TxInfAndSts.OrgnlUETR");
if (StringUtil.isNotEmpty(uetr)) {
Field121 field121 = new Field121(uetr);
block3.builder().setField121(field121);
}
}
@Override
public List<Mx2MtTagsGenerate> getGenerateTagList() {
List<Mx2MtTagsGenerate> fieldsGenerateList = new ArrayList<>();
fieldsGenerateList.add(new Field20Generate());
fieldsGenerateList.add(new Field21Generate());
fieldsGenerateList.add(new Field79Generate());
return fieldsGenerateList;
}
@Override
protected String getMtType() {
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
String bodyParentPath = (String)context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, true);
String orgMsgNameIdentification = getXmlNodeValue(bodyParentPath, document, "TxInfAndSts.OrgnlGrpInf.OrgnlMsgNmId");
String mtType = Mx2MtConstants.MT_TYPE_299;
if (StringUtil.isNotEmpty(orgMsgNameIdentification)) {
if (orgMsgNameIdentification.startsWith("pacs.008")
|| orgMsgNameIdentification.startsWith("pacs.003")) {
mtType = Mx2MtConstants.MT_TYPE_199;
} else if (orgMsgNameIdentification.startsWith("pacs.009")
|| orgMsgNameIdentification.startsWith("pacs.010")) {
mtType = Mx2MtConstants.MT_TYPE_299;
} else if (orgMsgNameIdentification.matches("MT10[0-9]{1}")) {
mtType = Mx2MtConstants.MT_TYPE_199;
} else if (orgMsgNameIdentification.matches("MT20[0-9]{1}")) {
mtType = Mx2MtConstants.MT_TYPE_299;
}
}
return mtType;
}
}
package com.brilliance.swift.mx2mt.mtn99.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
public class Field20Generate extends AbstractMx2MtTagsGenerate {
private static String name = "20";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String messageId = getXmlNodeValue(grpHdrParentElementName, document, "GrpHdr.MsgId");
if (StringUtil.isNotEmpty(messageId)) {
if (messageId.length() > 16) {
messageId = messageId.substring(0, 15) + "+";
}
String value = messageId;
if (value.startsWith("/") || value.endsWith("/") || value.contains("//")) {
value = Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE;
}
tags.add(new Tag(name, value));
}
}
}
package com.brilliance.swift.mx2mt.mtn99.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
public class Field21Generate extends AbstractMx2MtTagsGenerate {
private static String name = "21";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String relatedMessageId = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.OrgnlGrpInf.OrgnlMsgId");
if (StringUtil.isNotEmpty(relatedMessageId)) {
tags.add(new Tag(name, relatedMessageId));
}
}
}
\ No newline at end of file
package com.brilliance.swift.mx2mt.mtn99.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.vo.MxMtReasonCodeInfo;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.ArrayList;
import java.util.List;
public class Field79Generate extends AbstractMx2MtTagsGenerate {
private static String name = "21";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
List<String> mt72List = new ArrayList<>();
List<MxMtReasonCodeInfo> mxMtReasonCodeInfos = SwiftTransferUtil.getMxMtReasonCodes();
String mxAddtlInf = "";
int addtlInfCount = getXmlNodeCounts(bodyHdrParentElementName, document, "TxInfAndSts.StsRsnInf.AddtlInf");
if (addtlInfCount > 0) {
mxAddtlInf = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.StsRsnInf.AddtlInf(0)");
if (addtlInfCount > 1) {
for (int i=1; i<addtlInfCount; i++) {
if (i == 2) break; //最多只取2行数据
String tmpAddtlInf = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.StsRsnInf.AddtlInf(" + i + ")");
if (mxAddtlInf.length() > 104) {
mxAddtlInf += tmpAddtlInf;
} else {
mxAddtlInf += " " + tmpAddtlInf;
}
}
}
}
mt72List.add("/REJT/99");
String mtLine2 = "";
String mtLine6 = "";
String mxReasonCode = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.StsRsnInf.Rsn.Cd");
String mxReasonProprietary = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.StsRsnInf.Rsn.Prtry");
if (StringUtil.isNotEmpty(mxReasonCode)) {
mtLine2 = subFunctionReasonCodeTranslation(mxReasonCode, mxMtReasonCodeInfos);
} else if (StringUtil.isNotEmpty(mxReasonProprietary)) {
mtLine2 = "/XT99/" + mxReasonProprietary + "/";
}
mtLine2 += mxAddtlInf;
if (mtLine2.length() > 50) {
mtLine6 = "/TEXT/" + mtLine2.substring(50);
mtLine2 = mtLine2.substring(0, 50);
}
if (StringUtil.isNotEmpty(mtLine2)) {
mt72List.add(mtLine2);
}
String orgMsgId = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.OrgnlGrpInf.OrgnlMsgId");
String mtLine3 = "/MREF/" + subFunctionIDTruncation(orgMsgId);
mt72List.add(mtLine3);
String orgEndToEndId = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.OrgnlEndToEndId");
if (StringUtil.isNotEmpty(orgEndToEndId)) {
String mtLine4 = "/TREF/" + subFunctionIDTruncation(orgEndToEndId);
mt72List.add(mtLine4);
}
//没有mtLine5
String mtUetr = "";
//是否有UETR
String uetr = getXmlNodeValue(bodyHdrParentElementName, document, "TxInfAndSts.OrgnlUETR");
if (StringUtil.isNotEmpty(uetr)) {
mtUetr = "/UETR/" + uetr;
}
if (StringUtil.isNotEmpty(mtLine6)) {
mt72List.add(mtLine6);
if (StringUtil.isNotEmpty(mtUetr)) {
mt72List.add("//" + mtUetr);
}
} else {
mt72List.add("/TEXT/" + mtUetr);
}
if (mt72List.size() > 0) {
List<String> list = new ArrayList<>();
for (int i=0; i<mt72List.size(); i++) {
String mt72FullField = mt72List.get(i);
List<String> tmplist = StringUtil.outStringList(mt72FullField, 50, "//");
list.addAll(tmplist);
}
String value = "";
for (int i=0; i<list.size(); i++) {
if (i == 35) break;
if (i == 0) {
value = list.get(i);
} else {
value += Mx2MtConstants.NEW_LINE + list.get(i);
}
}
tags.add(new Tag(name, value));
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
THE MESSAGE WILL WORK “AS IS” IN THE READINESS PORTAL. IT IS ESSENTIAL THAT USERS REMOVE THE ENVELOPE AND REPLACE IT WITH THEIR OWN TRANSPORT HEADER (FOR EXAMPLE FOR ALLIANCE ACCESS YOU WOULD USE THE XML V2 HEADERS).
=========================================================================================================================================================================================
SWIFT © 2020. All rights reserved.
This publication contains SWIFT or third-party confidential information. Do not disclose this publication outside your organisation without SWIFT’s prior written consent.
The use of this document is governed by the legal notices appearing at the end of this document. By using this document, you will be deemed to have accepted those legal notices.
=========================================================================================================================================================================================
Use Case p.2.1.2 pacs.002 with code RJCT Flow #DtoC
========================================================================================================================
Change Log
2020-10-16 - Original version
=============================
-->
<Envelope xmlns="urn:swift:xsd:envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:swift:xsd:envelope ../../../../March21Schemas/Translator_envelope.xsd">
<AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Fr>
<FIId>
<FinInstnId>
<BICFI>BAUTUS31XXX</BICFI>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<BICFI>FTSBUS33XXX</BICFI>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>P2D2C2007/212</BizMsgIdr>
<MsgDefIdr>pacs.002.001.10</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2020-01-11T12:55:00.960-05:00</CreDt>
</AppHdr>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FIToFIPmtStsRpt>
<GrpHdr>
<MsgId>P2D2C2007/212</MsgId>
<CreDtTm>2020-01-11T12:55:00.960-05:00</CreDtTm>
</GrpHdr>
<TxInfAndSts>
<OrgnlGrpInf>
<OrgnlMsgId>B2C0506272708</OrgnlMsgId>
<OrgnlMsgNmId>pacs.008.001.08</OrgnlMsgNmId>
</OrgnlGrpInf>
<OrgnlInstrId>B2C0506272708</OrgnlInstrId>
<OrgnlEndToEndId>E2E04044506271305</OrgnlEndToEndId>
<OrgnlUETR>174c245f-2682-4291-ad67-2a41e530cd27</OrgnlUETR>
<TxSts>RJCT</TxSts>
<StsRsnInf>
<Rsn>
<Cd>AC04</Cd>
</Rsn>
<AddtlInf>Further details on the status reason</AddtlInf>
<AddtlInf>Additional information can be used for several purposes such as the reporting of repaired information</AddtlInf>
</StsRsnInf>
<InstgAgt>
<FinInstnId>
<BICFI>BAUTUS31XXX</BICFI>
</FinInstnId>
</InstgAgt>
<InstdAgt>
<FinInstnId>
<BICFI>FTSBUS33XXX</BICFI>
</FinInstnId>
</InstdAgt>
</TxInfAndSts>
</FIToFIPmtStsRpt>
</Document>
</Envelope>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
THE MESSAGE WILL WORK “AS IS” IN THE READINESS PORTAL. IT IS ESSENTIAL THAT USERS REMOVE THE ENVELOPE AND REPLACE IT WITH THEIR OWN TRANSPORT HEADER (FOR EXAMPLE FOR ALLIANCE ACCESS YOU WOULD USE THE XML V2 HEADERS).
=========================================================================================================================================================================================
SWIFT © 2020. All rights reserved.
This publication contains SWIFT or third-party confidential information. Do not disclose this publication outside your organisation without SWIFT’s prior written consent.
The use of this document is governed by the legal notices appearing at the end of this document. By using this document, you will be deemed to have accepted those legal notices.
====================================================================================================================================================================
Use Case p.2.2.1 Agent D Aktia sends a pacs.002 to Agent C Nordea Finland
========================================================================================================================
Change Log
2020-10-16 - Original version
=============================
-->
<Envelope xmlns="urn:swift:xsd:envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:swift:xsd:envelope ../../../../Schemas/Translator_envelope.xsd">
<AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.02">
<Fr>
<FIId>
<FinInstnId>
<BICFI>HELSFIHHXXX</BICFI>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<BICFI>NDEAFIHHXXX</BICFI>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>pacs2bizmsgidr01</BizMsgIdr>
<MsgDefIdr>pacs.002.001.10</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2020-08-03T11:13:41.960+00:00</CreDt>
<Rltd>
<Fr>
<FIId>
<FinInstnId>
<BICFI>NDEAFIHHXXX</BICFI>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<BICFI>HELSFIHHXXX</BICFI>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>pacs9bizmsgidr02</BizMsgIdr>
<MsgDefIdr>pacs.009.001.08</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2020-08-03T10:23:41.960+00:00</CreDt>
</Rltd>
</AppHdr>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10">
<FIToFIPmtStsRpt>
<GrpHdr>
<MsgId>pacs2bizmsgidr01</MsgId>
<CreDtTm>2020-08-03T11:13:41.960+00:00</CreDtTm>
</GrpHdr>
<TxInfAndSts>
<OrgnlGrpInf>
<OrgnlMsgId>pacs9bizmsgidr02</OrgnlMsgId>
<OrgnlMsgNmId>pacs.009.001.08</OrgnlMsgNmId>
</OrgnlGrpInf>
<OrgnlInstrId>pacs9bizmsgidr02</OrgnlInstrId>
<OrgnlEndToEndId>pacs009EndToEndId-001</OrgnlEndToEndId>
<OrgnlUETR>dab3b64f-092b-4839-b7e9-8f438af50961</OrgnlUETR>
<TxSts>RJCT</TxSts>
<StsRsnInf>
<Rsn>
<Cd>AC12</Cd>
</Rsn>
<AddtlInf>Further details on the status reason</AddtlInf>
<AddtlInf>Additional information can be used for several purposes such as the reporting of repaired information</AddtlInf>
</StsRsnInf>
<InstgAgt>
<FinInstnId>
<BICFI>HELSFIHHXXX</BICFI>
</FinInstnId>
</InstgAgt>
<InstdAgt>
<FinInstnId>
<BICFI>NDEAFIHHXXX</BICFI>
</FinInstnId>
</InstdAgt>
</TxInfAndSts>
</FIToFIPmtStsRpt>
</Document>
</Envelope>
package com.brilliance.mx2mt.mtn99;
import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import org.apache.commons.io.FileUtils;
import java.io.File;
public class Test {
public static void test199() throws Exception{
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00200110_Pacs008.xml");
String xmlStr = FileUtils.readFileToString(file);
String mt103Retn = new Mx2MtCreatorManager().mx2Mt(xmlStr, null, null);
System.out.println(mt103Retn);
}
public static void test299() throws Exception {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00200110_Pacs009.xml");
String xmlStr = FileUtils.readFileToString(file);
String mt103Retn = new Mx2MtCreatorManager().mx2Mt(xmlStr, null, null);
System.out.println(mt103Retn);
}
public static void main(String[] args) throws Exception {
//test199();
test299();
}
}
......@@ -40,8 +40,9 @@ class AbstractMXAdapter implements JsonSerializer<AbstractMX>, JsonDeserializer<
// default serialization
// in Integrator this will fill the JSON structure with the complete MX message model
JsonObject object = context.serialize(mx).getAsJsonObject();
object.addProperty("@xmlns", mx.getNamespace());
//object.addProperty("@xmlns", mx.getNamespace());
object.addProperty(IDENTIFIER, mx.getMxId().id());
object.remove("type");
return object;
}
......
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