Commit 6ca018b3 by wuzhe

camt10800101

parent b3151c1b
......@@ -35,6 +35,8 @@ public class Mx2MtConstants {
public static final String MT_TYPE_110 = "110";
public static final String MT_TYPE_111 = "111";
public static final String MT_TYPE_202 = "202";
public static final String MT_TYPE_205 = "205";
......
......@@ -5,6 +5,7 @@ import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.mt103.Mx2Mt103Creator;
import com.brilliance.swift.mx2mt.mt103Retn.Mx2Mt103RetnCreator;
import com.brilliance.swift.mx2mt.mt110.Mx2Mt110Creator;
import com.brilliance.swift.mx2mt.mt111.Mx2Mt111Creator;
import com.brilliance.swift.mx2mt.mt112.Mx2Mt112Creator;
import com.brilliance.swift.mx2mt.mt192292.Mx2Mtn92Creator;
import com.brilliance.swift.mx2mt.mt196296.Mx2Mtn96Creator;
......@@ -127,6 +128,8 @@ public class Mx2MtCreatorManager {
return new Mx2Mt112Creator();
} else if("camt107001".equals(messageType)){
return new Mx2Mt110Creator();
} else if("camt108001".equals(messageType)){
return new Mx2Mt111Creator();
}
else {
throw new SwiftException("Invalid message type");
......
package com.brilliance.swift.mx2mt.mt111;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mx2mt.AbstractMx2MtCreator;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.mx2mt.Mx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.mt111.impl.*;
import com.brilliance.swift.util.XmlUtil;
import org.dom4j.Document;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Mx2Mt111Creator 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("Chq"));
}
@Override
public List<Mx2MtTagsGenerate> getGenerateTagList() {
List<Mx2MtTagsGenerate> fieldsGenerateList = new ArrayList<>();
fieldsGenerateList.add(new Field20Generate());
fieldsGenerateList.add(new Field21Generate());
fieldsGenerateList.add(new Field30Generate());
fieldsGenerateList.add(new Field32aGenerate());
fieldsGenerateList.add(new Field52aGenerate());
fieldsGenerateList.add(new Field59Generate());
fieldsGenerateList.add(new Field75Generate());
return fieldsGenerateList;
}
@Override
protected String getMtType() {
return Mx2MtConstants.MT_TYPE_111;
}
}
package com.brilliance.swift.mx2mt.mt111.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;
/**
* GrpHdr.MsgId
* AppHdr.BizMsgIdr
*/
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.isEmpty(messageId)) {
messageId = getXmlNodeValue(appHdrParentElementName, document, "AppHdr.BizMsgIdr");
}
if (StringUtil.isNotEmpty(messageId)) {
if (messageId.length() > 16) {
buildSTErrorInfo(13, "Block4/:20:", messageId);
messageId = messageId.substring(0, 15) + "+";
}
tags.add(new Tag(name, messageId));
}
}
}
package com.brilliance.swift.mx2mt.mt111.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;
/**
* 取值逻辑:
* field21 = OrgnlNtfctn.OrgnlNtfctnRef.OrgnlItm.OrgnlItmId,如果长度大于16,field21 = field21截取15位 + 最后一位用+代替
* 如果filed21 以/开始或者以/结束或者包含//,field21=NONREF
* 否则保持原值不变
*/
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 chqNb = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.ChqNb");
if (StringUtil.isNotEmpty(chqNb)) {
if (chqNb.length() > 16) {
buildSTErrorInfo(13, "Block4/:21:", chqNb);
chqNb = chqNb.substring(0, 15) + "+";
}
tags.add(new Tag(name, chqNb));
}
}
}
package com.brilliance.swift.mx2mt.mt111.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.List;
/**
*
*/
public class Field30Generate extends AbstractMx2MtTagsGenerate {
private static String name = "30";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
boolean flag30 = false;
String mtIsseDtStr = "";
String isseDtStr = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.IsseDt");
if (StringUtil.isNotEmpty(isseDtStr)) {
try {
XMLGregorianCalendar valDt = DatatypeFactory.newInstance().newXMLGregorianCalendar(isseDtStr);
mtIsseDtStr = DateUtil.format(valDt, "yyMMdd");
flag30 = true;
} catch (DatatypeConfigurationException e) {
throw new SwiftException(e.getMessage());
}
}
if(flag30){
tags.add(new Tag(name, mtIsseDtStr));
}
}
}
package com.brilliance.swift.mx2mt.mt111.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.NumberUtil;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.math.BigDecimal;
import java.util.List;
/**
*/
public class Field32aGenerate extends AbstractMx2MtTagsGenerate {
private static String name_32A = "32A";
private static String name_32B = "32B";
@Override
public void tagGenerate() throws SwiftException {
try {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String cheVaDt = "";
String cheAmt = "";
String cheAmtCcy = "";
String cheValDtValue = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.FctvDt.Dt");
String amt = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.Amt");
String ccy = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.Amt@Ccy");
if ("XAU".equalsIgnoreCase(ccy) || "XAG".equalsIgnoreCase(ccy)
|| "XPD".equalsIgnoreCase(ccy) || "XPT".equalsIgnoreCase(ccy)) {
buildSTErrorInfo(63, bodyHdrParentElementName+".Chq.Amt", ccy);
}
if (StringUtil.isNotEmpty(amt) && StringUtil.isNotEmpty(ccy)) {
cheAmt = NumberUtil.formatAmt(new BigDecimal(amt), ccy);
cheAmtCcy = ccy;
}
if (StringUtil.isNotEmpty(cheValDtValue)) {
XMLGregorianCalendar intrBkSttlmDt = DatatypeFactory.newInstance().newXMLGregorianCalendar(cheValDtValue);
cheVaDt = DateUtil.format(intrBkSttlmDt, "yyMMdd");
tags.add(new Tag(name_32A, cheVaDt+cheAmtCcy+cheAmt));
}else {
tags.add(new Tag(name_32B, cheAmtCcy+cheAmt));
}
} catch (DatatypeConfigurationException e) {
throw new SwiftException(e.getMessage());
}
}
}
package com.brilliance.swift.mx2mt.mt111.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
/**
*
*/
public class Field52aGenerate extends AbstractMx2MtTagsGenerate {
private static String name_52A = "52A";
private static String name_52B = "52B";
private static String name_52D = "52D";
private static String name = "52";
@Override
public void tagGenerate() throws SwiftException {
context.set(Mx2MtContextIdentifier.MX_TO_MT_ERROR_LOCATION, "Block4/52a");
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
int cheDrwrAgt = getXmlNodeCounts(bodyHdrParentElementName, document, "Chq.DrwrAgt");
int cheDrwrAgtAcct = getXmlNodeCounts(bodyHdrParentElementName, document, "Chq.DrwrAgtAcct");
String account = "";
if (cheDrwrAgt > 0 || cheDrwrAgtAcct > 0) {
String cheDrwrAgtPath = bodyHdrParentElementName + ".Chq.DrwrAgt";
String cheDrwrAgtAcctPath = bodyHdrParentElementName + ".Chq.DrwrAgtAcct";
if (cheDrwrAgt == 0 ) {
account = mx_to_mtAccount(bodyHdrParentElementName + ".Chq.DrwrAgtAcct");
tags.add(new Tag(name_52B, account));
} else {
Tag tag = mx_to_mtAgentGeneric(name, cheDrwrAgtPath, cheDrwrAgtAcctPath, true, false, false, null);
if (tag != null) {
if (name_52D.equals(tag.getName())) {
String value = mx_to_mtStartingLineCharacter(tag.getValue(), "Block4/:" + name_52D + ":");
tag.setValue(value);
}
tags.add(tag);
}
}
}
}
}
package com.brilliance.swift.mx2mt.mt111.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 Field59Generate extends AbstractMx2MtTagsGenerate {
private static String name = "59";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String ptsCtry = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.Pyee.PstlAdr.Ctry");
String partyPath = bodyHdrParentElementName + ".Chq.Pyee";
if (StringUtil.isNotEmpty(ptsCtry)){
String nameAddress = mx_to_mtPartyNameAndAddressLEI1(partyPath);
tags.add(new Tag(name, nameAddress));
} else {
String nameAddress = mx_to_mtPartyNameAndUnstructuredAddress(partyPath);
tags.add(new Tag(name, nameAddress));
}
}
}
package com.brilliance.swift.mx2mt.mt111.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 Field75Generate extends AbstractMx2MtTagsGenerate {
private static String name = "75";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String reasonCode = getXmlNodeValue(bodyHdrParentElementName, document, "Chq.ChqCxlOrStopRsn.Rsn.Cd");
String reasonDescription = "";
String cancellationReason = getXmlNodeValue(bodyHdrParentElementName,document,"Chq.ChqCxlOrStopRsn.AddtlInf");
String[][] reasonTable = {
{"LOST", "ChequeLost"},
{"DUPL", "DuplicateCheque"},
{"FRAD", "FraudulentOrigin"},
{"NARR", "Narrative"},
{"CUST", "RequestedByCustomer"}
};
for (String[] reason : reasonTable) {
if (reasonCode.equals(reason[0])) {
reasonDescription = reason[1];
break;
}
}
String mx75 = "";
mx75 = "/" + reasonDescription + "/" + cancellationReason;
List<String> list = StringUtil.outStringList(mx75, 35, "//");
String mt75 = "";
if (list != null && list.size() > 0) {
for (int i=0; i<list.size(); i++) {
String str = list.get(i);
if (i < 6) {
if (i == 0) {
mt75 = str;
} else {
mt75 += Mx2MtConstants.NEW_LINE + str;
}
}
}
}
if (StringUtil.isNotEmpty(mt75)) {
tags.add(new Tag(name, mt75));
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<RequestPayload>
<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>CNCL-ID001</BizMsgIdr>
<MsgDefIdr>camt.108.001.01</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2022-07-22T10:17:51.619+08:00</CreDt>
<PssblDplct>false</PssblDplct>
<Prty>NORM</Prty>
</AppHdr>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.108.001.01">
<ChqCxlOrStopReq>
<GrpHdr>
<MsgId>CSE-001</MsgId>
<CreDtTm>2022-07-22</CreDtTm>
<NbOfChqs>1</NbOfChqs>
</GrpHdr>
<Chq>
<OrgnlInstrId>AAAAAAA</OrgnlInstrId>
<!--21-->
<ChqNb>BBBBB</ChqNb>
<!--30-->
<IsseDt>2022-09-22</IsseDt>
<!--32A-->
<FctvDt>
<Dt>2022-10-22</Dt>
</FctvDt>
<!--32B-->
<Amt Ccy="USD">123131</Amt>
<!--52D-->
<!-- <DrwrAgt>-->
<!-- <FinInstnId>QWERTYOII</FinInstnId>-->
<!-- </DrwrAgt>-->
<!--52B-->
<DrwrAgtAcct>
<Id>
<IBAN>OBHHIO</IBAN>
</Id>
</DrwrAgtAcct>
<!--59-->
<Pyee>
<Nm>TTTT</Nm>
<PstlAdr>
<AdrLine>PPPPPPPP</AdrLine>
</PstlAdr>
</Pyee>
<ChqCxlOrStopRsn>
<!--75-->
<Rsn>
<Cd>NARR</Cd>
</Rsn>
<AddtlInf>REWQ</AddtlInf>
</ChqCxlOrStopRsn>
</Chq>
</ChqCxlOrStopReq>
</Document>
</RequestPayload>
\ No newline at end of file
......@@ -152,6 +152,11 @@ public class Mx2MtTest {
public void test112() { test("/swiftXml/camt10900101.xml",null);}
@Test
public void test111() {
test("/swiftXml/camt10800101.xml", null);
}
@Test
public void testXmlFilePath() {
SwiftTranslationReport str = SwiftTransfer.mx2MtPlus("d:/test/MxPacs00800108.xml", true, null, null);
System.out.println(str.getMessage());
......
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