Commit 840937a0 by chengzhuoshen

重写MX报文要素展示功能,支持国际化

parent 599bbbed
......@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -203,28 +204,41 @@ public class SwiftTransfer {
}
}
/**
* 将MX xml转换成Map<String, String>
* 展示MX报文要素
* @param xmlStr
* @return
*/
public static Map<String, String> mx2Map(String xmlStr) {
if (StringUtil.isEmpty(xmlStr)) return null;
return new Mx2MapCreatorManager().mx2Map(xmlStr);
}
public static Map<String, String> mx2Map(String xmlFilePath, boolean filePathFlag) {
try {
if (filePathFlag) {
File file = new File(xmlFilePath);
String mxStr = FileUtils.readFileToString(file);
return mx2Map(mxStr);
} else {
return mx2Map(xmlFilePath);
public static String showMxElement(String xmlStr, String localCode) {
String mxElementStr = "";
Map<String, Object> maps = mx2Map(xmlStr, localCode);
if (maps.size() > 0) {
Set<String> keys = maps.keySet();
for (String key : keys) {
if (maps.get(key) instanceof Map) {
mxElementStr += Mx2MtConstants.NEW_LINE;
mxElementStr += key + ":" + Mx2MtConstants.NEW_LINE;
Map<String, Object> newMaps = (Map<String, Object>)maps.get(key);
for (String tmpKey : newMaps.keySet()) {
mxElementStr += tmpKey + ":" + newMaps.get(tmpKey) + Mx2MtConstants.NEW_LINE;
}
} else {
mxElementStr += key + ":" + maps.get(key) + Mx2MtConstants.NEW_LINE;
}
}
} catch (IOException e) {
throw new SwiftException(e.getMessage());
}
return mxElementStr;
}
/**
* 将MX xml转换成Map<String, String>
* 支持国际化 US CN
* @param xmlStr
* @return
*/
public static Map<String, Object> mx2Map(String xmlStr, String localCode) {
if (StringUtil.isEmpty(xmlStr)) return null;
return new Mx2MapCreatorManager().mx2Map(xmlStr, localCode);
}
public static boolean validateMx(String xmlFilePath, boolean filePathFlag) {
......@@ -321,6 +335,10 @@ public class SwiftTransfer {
}
}
public static Map<String, Object> mx2ElementMaps(String xmlStr) {
return new Mx2ElementCreatorManager().mx2ElementMaps(xmlStr);
}
/**
* 从混合格式(MXMT)的报文中提取MX报文
* @param mixStr
......
package com.brilliance.swift.mx2element;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2element.camt029001.Mx2ElementCamt029001Creator;
import com.brilliance.swift.mx2element.camt053001.Mx2ElementCamt053001Creator;
......@@ -11,12 +12,15 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.prowidesoftware.swift.model.mx.AbstractMX;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.LinkedHashMap;
import java.util.Map;
public class Mx2ElementCreatorManager {
public String mx2Element(String xmlStr) throws SwiftException {
xmlStr = handlingXml(xmlStr);
AbstractMX abstractMX = AbstractMX.parse(xmlStr);
String messageType = (abstractMX.getMxId().getBusinessProcess().name()
+ "."
......@@ -33,6 +37,22 @@ public class Mx2ElementCreatorManager {
return gson.toJson(maps, LinkedHashMap.class);
}
public Map<String, Object> mx2ElementMaps(String xmlStr) throws SwiftException {
xmlStr = handlingXml(xmlStr);
AbstractMX abstractMX = AbstractMX.parse(xmlStr);
String messageType = (abstractMX.getMxId().getBusinessProcess().name()
+ "."
+ abstractMX.getMxId().getFunctionality()
+ "."
+ abstractMX.getMxId().getVariant())
//+ abstractMX.getMxId().getVersion())
.trim();
AbstractMx2ElementCreator creator = getCreator(messageType);
creator.setAbstractMX(abstractMX);
creator.setXmlStr(xmlStr);
return creator.buildElement();
}
public AbstractMx2ElementCreator getCreator(String messageType) {
if ("pacs.008.001".equals(messageType)) {
return new Mx2ElementPacs008001Creator();
......@@ -50,4 +70,24 @@ public class Mx2ElementCreatorManager {
return new Mx2ElementDefaultCreator();
}
}
/**
* 如果传入的xml 没有报文头,导致dom4j无法解析
* 提取xml里面的AppHdr和Document,重新组装成有效的xml报文
*/
private String handlingXml(String xmlStr) {
boolean flag = true;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder.parse(xmlStr);
} catch (Exception e) {
flag = false;
}
if (flag) { //如果是有效xml报文,直接返回
return xmlStr;
} else {
return SwiftTransfer.fetchXmlFromMixMessage(xmlStr);
}
}
}
package com.brilliance.swift.mx2map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.util.StringUtil;
import java.util.Map;
import java.util.Set;
public class DefaultMx2MapCreator extends AbstractMx2MapCreator{
@Override
public Map<String, String> mx2Map() throws SwiftException {
String gsonStr = abstractMX.toJson();
Map<String, Object> mxGsonMaps = JSON.parseObject(gsonStr);
parseMxGsonMap(maps, mxGsonMaps, null);
return maps;
}
/**
* 把mxGsonMaps解析成Map<String, String>,回调函数然后拼接前缀
* @param maps
* @param mxGsonMaps
* @param prefix
*/
public void parseMxGsonMap(Map<String, String> maps, Map<String, Object> mxGsonMaps, String prefix) {
Set<String> keys = mxGsonMaps.keySet();
for (String key : keys) {
Object object = (Object)mxGsonMaps.get(key);
if (object == null) continue;
if (object instanceof JSONArray) {
if (StringUtil.isEmpty(prefix)) {
parseMxGsonArray(maps, (JSONArray)object, key);
} else {
parseMxGsonArray(maps, (JSONArray)object, prefix + "." + key);
}
} else if (object instanceof JSONObject) {
if (StringUtil.isEmpty(prefix)) {
parseMxGsonMap(maps, (Map<String, Object>)object, key);
} else {
parseMxGsonMap(maps, (Map<String, Object>)object, prefix + "." + key);
}
} else {
if (StringUtil.isEmpty(prefix)) {
maps.put(key, String.valueOf(object));
} else {
maps.put(prefix + "." + key, String.valueOf(object));
}
}
}
}
/**
* jsonArray 是json数组格式 回调函数
* 如果长度只有1,那么就不需要下标
* 否则需要下标(0) (1) (2) (3)
* @param maps
* @param jsonArray
* @param prefix
*/
public void parseMxGsonArray(Map<String, String> maps, JSONArray jsonArray, String prefix) {
Object[] jsonArrays = jsonArray.toArray();
if (jsonArrays.length == 1) {
Object object = jsonArrays[0];
if (object instanceof JSONArray) {
parseMxGsonArray(maps, (JSONArray)object, prefix);
} else if (object instanceof JSONObject) {
parseMxGsonMap(maps, (Map<String, Object>)object, prefix);
} else {
maps.put(prefix, String.valueOf(object));
}
} else {
for (int i=0; i<jsonArrays.length; i++) {
Object object = jsonArrays[i];
if (object instanceof JSONArray) {
parseMxGsonArray(maps, (JSONArray)object, prefix+"("+i+")");
} else if (object instanceof JSONObject) {
parseMxGsonMap(maps, (Map<String, Object>)object, prefix+"("+i+")");
} else {
maps.put(prefix+"("+i+")", String.valueOf(object));
}
}
}
}
}
......@@ -6,5 +6,5 @@ import java.util.Map;
public interface Mx2MapCreator {
public Map<String, String> mx2Map() throws SwiftException;
public Map<String, Object> mx2Map() throws SwiftException;
}
package com.brilliance.swift.mx2map;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.camt053.Mx2MapCamt053Creator;
import com.brilliance.swift.mx2map.pacs008.Mx2MapPacs008Creator;
import com.prowidesoftware.swift.model.mx.AbstractMX;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.Map;
public class Mx2MapCreatorManager {
public Map<String, String> mx2Map(String xml) throws SwiftException {
public Map<String, Object> mx2Map(String xml, String localCode) throws SwiftException {
xml = handlingXml(xml);
AbstractMX abstractMX = AbstractMX.parse(xml);
String messageType = (abstractMX.getMxId().getBusinessProcess().name()
+ "."
......@@ -19,14 +24,16 @@ public class Mx2MapCreatorManager {
.trim();
AbstractMx2MapCreator creator = getCreator(messageType);
creator.setXmlStr(xml);
creator.setAbstractMX(abstractMX);
creator.setLocalCode(localCode);
return creator.mx2Map();
}
public AbstractMx2MapCreator getCreator(String messageType) {
if("camt.053.001".equals(messageType)){
return new Mx2MapCamt053Creator();
} /*else if("camt.029.001".equals(messageType)) {
} else if("pacs.008.001".equals(messageType)){
return new Mx2MapPacs008Creator();
}/*else if("camt.029.001".equals(messageType)) {
return new Mx2MapCamt029Creator();
} else if("camt.056.001".equals(messageType)) {
return new Mx2MapCamt056Creator();
......@@ -37,7 +44,27 @@ public class Mx2MapCreatorManager {
} else if("pacs.008.001".equals(messageType)){
return new Mx2MapPacs008Creator();
} */else {
return new DefaultMx2MapCreator();
throw new SwiftException("无效的报文类型");
}
}
/**
* 如果传入的xml 没有报文头,导致dom4j无法解析
* 提取xml里面的AppHdr和Document,重新组装成有效的xml报文
*/
private String handlingXml(String xmlStr) {
boolean flag = true;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder.parse(xmlStr);
} catch (Exception e) {
flag = false;
}
if (flag) { //如果是有效xml报文,直接返回
return xmlStr;
} else {
return SwiftTransfer.fetchXmlFromMixMessage(xmlStr);
}
}
}
package com.brilliance.swift.mx2map.camt029;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.AbstractMx2MapCreator;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Map;
public class Mx2MapCamt029Creator extends AbstractMx2MapCreator {
@Override
public Map<String, String> mx2Map() throws SwiftException {
try {
Document document = DocumentHelper.parseText(xmlStr);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
String appHdrParentElementName = parentElementMaps.get("AppHdr");
String grpHdrParentElementName = parentElementMaps.get("GrpHdr");
String bodyParentElementName = parentElementMaps.get("CxlDtls");
String sendBic = abstractMX.getAppHdr().from();
maps.put(getPropertyValue("app.header.sendBic"), sendBic);
String receiverBic = abstractMX.getAppHdr().to();
maps.put(getPropertyValue("app.header.receiverBic"), receiverBic);
String uetr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.OrgnlUETR");
if(StringUtil.isNotEmpty(uetr)){
maps.put(getPropertyValue("uetr"), uetr);
}
String msgDefId = abstractMX.getAppHdr().messageName();
maps.put(getPropertyValue("app.header.msgDefId"), msgDefId);
String bizSvc = abstractMX.getAppHdr().serviceName();
maps.put(getPropertyValue("app.header.bizSvc"), bizSvc);
XMLGregorianCalendar creDt = abstractMX.getAppHdr().creationDate();
maps.put(getPropertyValue("app.header.creDt"), creDt.toXMLFormat());
String messageId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.CxlStsId");
if(StringUtil.isNotEmpty(messageId)){
maps.put(Mx2MtConstants.NEW_LINE+getPropertyValue("message.id"), messageId);
}
String endToEndId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.RslvdCase.Id");
if(StringUtil.isNotEmpty(endToEndId)){
maps.put(getPropertyValue("endToEnd.id"), endToEndId);
}
String nameId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.OrgnlGrpInf.OrgnlMsgNmId");
String dateStr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.OrgnlGrpInf.OrgnlCreDtTm");
if(StringUtil.isNotEmpty(nameId)){
maps.put(getPropertyValue("originalGroupInformation.orgnlMsgId"), nameId);
}
if(StringUtil.isNotEmpty(dateStr)){
maps.put(getPropertyValue("originalGroupInformation.orgnlCreDtTm"), dateStr);
}
String reason = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.CxlStsRsnInf.Rsn.Cd");
if(StringUtil.isNotEmpty(reason)){
maps.put(getPropertyValue("cancellationDetails.transactionInformationAndStatus.cancellationStatusReasonInformation.reason.cd"), reason);
}
int count = XmlUtil.getChildrenCount(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.CxlStsRsnInf.AddtlInf",null);
String information = "";
if(count>0){
for (int i = 0; i < count; i++) {
information = information + XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.CxlStsRsnInf.AddtlInf("+i+")");
}
}
if(StringUtil.isNotEmpty(information)){
maps.put(getPropertyValue("cancellationDetails.transactionInformationAndStatus.cancellationStatusReasonInformation.addtlInf"), information);
}
} catch (DocumentException e) {
throw new SwiftException(e.getMessage());
}
return maps;
}
}
package com.brilliance.swift.mx2map.camt052;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.AbstractMx2MapCreator;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.brilliance.swift.vo.common.CdtDbtCode;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Map;
public class Mx2MapCamt052Creator extends AbstractMx2MapCreator {
@Override
public Map<String, String> mx2Map() throws SwiftException {
try {
Document document = DocumentHelper.parseText(xmlStr);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
String appHdrParentElementName = parentElementMaps.get("AppHdr");
String grpHdrParentElementName = parentElementMaps.get("GrpHdr");
String bodyParentElementName = parentElementMaps.get("Rpt");
String sendBic = abstractMX.getAppHdr().from();
maps.put(getPropertyValue("app.header.sendBic"), sendBic);
String receiverBic = abstractMX.getAppHdr().to();
maps.put(getPropertyValue("app.header.receiverBic"), receiverBic);
String msgDefId = abstractMX.getAppHdr().messageName();
maps.put(getPropertyValue("app.header.msgDefId"), msgDefId);
String bizSvc = abstractMX.getAppHdr().serviceName();
maps.put(getPropertyValue("app.header.bizSvc"), bizSvc);
XMLGregorianCalendar creDt = abstractMX.getAppHdr().creationDate();
maps.put(getPropertyValue("app.header.creDt"), creDt.toXMLFormat());
String messageId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Id");
if(StringUtil.isNotEmpty(messageId)){
maps.put(Mx2MtConstants.NEW_LINE+getPropertyValue("message.id"), messageId);
}
String iban = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Acct.Id.IBAN");
String acctId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Acct.Id.Othr.Id");
String account = StringUtil.isNotEmpty(iban) ? iban : acctId;
if (StringUtil.isNotEmpty(account)) {
maps.put(getPropertyValue("statement.account"), account);
}
String elctrncSeqNb = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.LglSeqNb");
if (StringUtil.isEmpty(elctrncSeqNb) || elctrncSeqNb.length() > 5) {
elctrncSeqNb = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.ElctrncSeqNb");
}
if (StringUtil.isNotEmpty(elctrncSeqNb)) {
maps.put(getPropertyValue("statement.sequence.number"), elctrncSeqNb);
}
String pageNumber = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.RptPgntn.PgNb");
if (StringUtil.isNotEmpty(pageNumber)){
maps.put(getPropertyValue("statement.page.number"), pageNumber);
}
String amount = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Acct.Ccy");
if(StringUtil.isNotEmpty(amount)){
maps.put(getPropertyValue("report.account.currency"),amount+"0");
}
String dateStr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.CreDtTm");
if(StringUtil.isEmpty(dateStr)){
dateStr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".GrpHdr.CreDtTm");
}
if(StringUtil.isEmpty(dateStr)){
maps.put(getPropertyValue("report.creDtTm"),dateStr);
}
int entryCount = XmlUtil.getChildrenCount(document, bodyParentElementName + ".Rpt.Ntry", null);
if (entryCount > 0) {
for (int i=0; i<entryCount; i++) {
String reversalIndicator = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Ntry("+i+").RvslInd");
String creditDebitIndicator = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Ntry("+i+").CdtDbtInd");
if (StringUtil.isNotEmpty(reversalIndicator) && Boolean.valueOf(reversalIndicator)) {
if (CdtDbtCode.DBIT.value().equals(creditDebitIndicator)) {
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("statement.entry.crdr")+"("+(i+1)+")", getPropertyValue("reversal.credit"));
} else {
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("statement.entry.crdr")+"("+(i+1)+")", getPropertyValue("reversal.debit"));
}
} else {
if (CdtDbtCode.DBIT.value().equals(creditDebitIndicator)) {
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("statement.entry.crdr")+"("+(i+1)+")", getPropertyValue("debit"));
} else {
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("statement.entry.crdr")+"("+(i+1)+")", getPropertyValue("credit"));
}
}
String valueDateStr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Ntry("+i+").ValDt.Dt");
if (StringUtil.isNotEmpty(valueDateStr)) {
maps.put(getPropertyValue("statement.entry.valueDate")+"("+(i+1)+")", valueDateStr);
}
String amt = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Ntry("+i+").Amt");
String ccy = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Ntry("+i+").Amt@Ccy");
if (StringUtil.isNotEmpty(ccy)) {
maps.put(getPropertyValue("statement.entry.ccy")+"("+(i+1)+")", ccy);
}
if (StringUtil.isNotEmpty(amt)) {
maps.put(getPropertyValue("statement.entry.amt")+"("+(i+1)+")", amt);
}
String endToEndId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.Ntry("+i+").NtryDtls.TxDtls.Refs.EndToEndId");
if (StringUtil.isNotEmpty(endToEndId)) {
maps.put(getPropertyValue("statement.entry.endToEndId")+"("+(i+1)+")", endToEndId);
}
String sumc = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.TxsSummry.TtlCdtNtries.Sum");
String nbOfNtriesc = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.TxsSummry.TtlCdtNtries.NbOfNtries");
if(StringUtil.isNotEmpty(sumc)&&StringUtil.isNotEmpty(nbOfNtriesc)){
maps.put(Mx2MtConstants.NEW_LINE+getPropertyValue("report.transactionsSummary.totalCreditEntries.nbOfNtries"), nbOfNtriesc);
maps.put(getPropertyValue("report.transactionsSummary.totalCreditEntries.sum"), sumc);
}
String sumd = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.TxsSummry.TtlDbtNtries.Sum");
String nbOfNtriesd = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Rpt.TxsSummry.TtlDbtNtries.NbOfNtries");
if(StringUtil.isNotEmpty(sumd)&&StringUtil.isNotEmpty(nbOfNtriesd)){
maps.put(getPropertyValue("report.transactionsSummary.totalDebitEntries.nbOfNtries"), nbOfNtriesd);
maps.put(getPropertyValue("report.transactionsSummary.totalDebitEntries.sum"), sumd);
}
}
}
} catch (DocumentException e) {
throw new SwiftException(e.getMessage());
}
return maps;
}
}
package com.brilliance.swift.mx2map.camt056;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.AbstractMx2MapCreator;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Map;
public class Mx2MapCamt056Creator extends AbstractMx2MapCreator {
@Override
public Map<String, String> mx2Map() throws SwiftException {
try {
Document document = DocumentHelper.parseText(xmlStr);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
String appHdrParentElementName = parentElementMaps.get("AppHdr");
String grpHdrParentElementName = parentElementMaps.get("GrpHdr");
String bodyParentElementName = parentElementMaps.get("Undrlyg");
String sendBic = abstractMX.getAppHdr().from();
maps.put(getPropertyValue("app.header.sendBic"), sendBic);
String receiverBic = abstractMX.getAppHdr().to();
maps.put(getPropertyValue("app.header.receiverBic"), receiverBic);
String uetr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Undrlyg.TxInf.OrgnlUETR");
if(StringUtil.isNotEmpty(uetr)){
maps.put(getPropertyValue("uetr"), uetr);
}
String msgDefId = abstractMX.getAppHdr().messageName();
maps.put(getPropertyValue("app.header.msgDefId"), msgDefId);
String bizSvc = abstractMX.getAppHdr().serviceName();
maps.put(getPropertyValue("app.header.bizSvc"), bizSvc);
XMLGregorianCalendar creDt = abstractMX.getAppHdr().creationDate();
maps.put(getPropertyValue("app.header.creDt"), creDt.toXMLFormat());
String messageId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Undrlyg.TxInf.Case.Id");
if(StringUtil.isNotEmpty(messageId)){
maps.put(Mx2MtConstants.NEW_LINE+getPropertyValue("message.id"), messageId);
}
String endToEndId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Undrlyg.TxInf.OrgnlInstrId");
if(StringUtil.isNotEmpty(endToEndId)){
maps.put(getPropertyValue("endToEnd.id"), endToEndId);
}
String nameId = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Undrlyg.TxInf.OrgnlGrpInf.OrgnlMsgNmId");
String dateStr = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".CxlDtls.TxInfAndSts.OrgnlGrpInf.OrgnlCreDtTm");
if(StringUtil.isNotEmpty(nameId)){
maps.put(getPropertyValue("originalGroupInformation.orgnlMsgId"), nameId);
}
if(StringUtil.isNotEmpty(dateStr)){
maps.put(getPropertyValue("originalGroupInformation.orgnlCreDtTm"), dateStr);
}
String reason = XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Undrlyg.TxInf.CxlRsnInf.Rsn.Cd");
if(StringUtil.isNotEmpty(reason)){
maps.put(getPropertyValue("underlying.transactionInformation.cancellationReasonInformation.reason.cd"), reason);
}
int count = XmlUtil.getChildrenCount(document, bodyParentElementName + ".Undrlyg.TxInf.CxlRsnInf.AddtlInf",null);
String information = "";
if(count>0){
for (int i = 0; i < count; i++) {
information = information + XmlUtil.getXmlNodeValue(document, bodyParentElementName + ".Undrlyg.TxInf.CxlRsnInf.AddtlInf("+i+")");
}
}
if(StringUtil.isNotEmpty(information)){
maps.put(getPropertyValue("underlying.transactionInformation.cancellationReasonInformation.addtlInf"), information);
}
} catch (DocumentException e) {
throw new SwiftException(e.getMessage());
}
return maps;
}
}
......@@ -107,6 +107,10 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
find = true;
value = value.replace("\"", ".");
}
if (value.indexOf("\\") > -1) {
find = true;
value = value.replace("\\", ".");
}
tag.setValue(value);
if (find) {
if ("20".equals(tag.getName()) || "21".equals(tag.getName())) {
......
......@@ -46,7 +46,11 @@ public class Field77BGenerate extends AbstractMx2MtTagsGenerate {
int mxRegulatoryReportingDetailInfCount = getXmlNodeCounts(bodyHdrParentElementName, document, "CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Inf");
if (mxRegulatoryReportingDetailInfCount > 0) {
for (int k=0; k<mxRegulatoryReportingDetailInfCount; k++) {
mtRegulatoryReporting += getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Inf("+k+")");
if (StringUtil.isEmpty(mtRegulatoryReporting)) {
mtRegulatoryReporting = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Inf("+k+")");
} else {
mtRegulatoryReporting += " " + getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Inf("+k+")");
}
}
}
}
......
......@@ -8,92 +8,72 @@ credit=\u8d37\u8bb0
debit=\u501f\u8bb0
reversal.credit=\u4ee5\u501f\u51b2\u8d37
reversal.debit=\u4ee5\u8d37\u51b2\u501f
yes=\u662f
no=\u5426
statement.id=\u5bf9\u8d26\u5355\u6807\u8bc6
statement.account=\u5bf9\u8d26\u5355\u8d26\u53f7
statement.account.ccy=\u5bf9\u8d26\u5355\u8d26\u53f7\u5e01\u79cd
statement.sequence.number=\u5bf9\u8d26\u5355\u53f7\u7801
statement.page.number=\u5bf9\u8d26\u5355\u5206\u9875\u5e8f\u53f7
statement.openingBooked.crdr=\u8d77\u59cb\u4f59\u989d\u501f\u8d37\u6807\u8bc6
statement.openingBooked.date=\u8d77\u59cb\u4f59\u989d\u65e5\u671f
statement.openingBooked.ccy=\u8d77\u59cb\u4f59\u989d\u5e01\u79cd
statement.openingBooked.amt=\u8d77\u59cb\u4f59\u989d\u91d1\u989d
statement.closingBooked.crdr=\u8d26\u9762\u4f59\u989d\u501f\u8d37\u6807\u8bc6
statement.closingBooked.date=\u8d26\u9762\u4f59\u989d\u65e5\u671f
statement.closingBooked.ccy=\u8d26\u9762\u4f59\u989d\u5e01\u79cd
statement.closingBooked.amt=\u8d26\u9762\u4f59\u989d\u91d1\u989d
statement.entry.valueDate=\u5bf9\u8d26\u5355\u8d77\u606f\u65e5
statement.entry.crdr=\u5bf9\u8d26\u5355\u501f\u8d37\u6807\u8bc6
statement.entry.ccy=\u5bf9\u8d26\u5355\u5e01\u79cd
statement.entry.amt=\u5bf9\u8d26\u5355\u91d1\u989d
statement.entry.endToEndId=\u5bf9\u8d26\u5355\u76f8\u5173\u4ea4\u6613\u6807\u8bc6
originalGroupInformation.orgnlMsgId=\u539f\u59cb\u4ea4\u6613\u540d\u79f0
originalGroupInformation.orgnlCreDtTm=\u539f\u59cb\u4ea4\u6613\u521b\u5efa\u65f6\u95f4
cancellationDetails.transactionInformationAndStatus.cancellationStatusReasonInformation.reason.cd=\u4ea4\u6613\u64a4\u9500\u8bf7\u6c42\u54cd\u5e94\u4ee3\u7801
cancellationDetails.transactionInformationAndStatus.cancellationStatusReasonInformation.addtlInf=\u4ea4\u6613\u64a4\u9500\u8bf7\u6c42\u54cd\u5e94\u8be6\u60c5
underlying.transactionInformation.cancellationReasonInformation.reason.cd=\u4ea4\u6613\u64a4\u9500\u8bf7\u6c42\u4ee3\u7801
underlying.transactionInformation.cancellationReasonInformation.addtlInf=\u4ea4\u6613\u64a4\u9500\u8bf7\u6c42\u8be6\u60c5
report.account.currency=\u6700\u4f4e\u91d1\u989d\u89c4\u5b9a
report.creDtTm=\u65e5\u671f
report.transactionsSummary.totalCreditEntries.nbOfNtries=\u501f\u8bb0\u7b14\u6570
report.transactionsSummary.totalCreditEntries.sum=\u501f\u8bb0\u603b\u91d1\u989d
report.transactionsSummary.totalDebitEntries.nbOfNtries=\u8d37\u8bb0\u7b14\u6570
report.transactionsSummary.totalDebitEntries.sum=\u8d37\u8bb0\u603b\u91d1\u989d
notification.amount.ccy=\u8d27\u5e01
notification.amount.amt=\u91d1\u989d
remitter=\u6c47\u6b3e\u4eba
instructingBank=\u6307\u793a\u884c
intermediaryBank=\u4e2d\u95f4\u884c
remitter.anyBIC=\u6c47\u6b3e\u4eba\u91d1\u878d\u673a\u6784bic\u4ee3\u7801
remitter.ctry=\u6c47\u6b3e\u4eba\u56fd\u5bb6
remitter.nm=\u6c47\u6b3e\u4eba\u540d\u79f0
account=\u8d26\u6237
remitter.adrLine=\u6c47\u6b3e\u4eba\u5730\u5740
remitter.cd=\u6c47\u6b3e\u4eba\u6e05\u7b97\u884c\u7cfb\u7edf\u4ee3\u7801
remitter.mmbId=\u6c47\u6b3e\u4eba\u6e05\u7b97\u884c\u7cfb\u7edf\u8d26\u53f7
#
statement.page.number=\u5bf9\u8d26\u5355\u9875\u7801
statement.lastPgInd=\u662f\u5426\u6700\u540e\u4e00\u9875
statement.openingBooked.crdr=\u671f\u521d\u4f59\u989d\u501f\u8d37\u6807\u8bc6
statement.openingBooked.date=\u671f\u521d\u4f59\u989d\u65e5\u671f
statement.openingBooked.ccy=\u671f\u521d\u4f59\u989d\u5e01\u79cd
statement.openingBooked.amt=\u671f\u521d\u4f59\u989d\u91d1\u989d
statement.closingBooked.crdr=\u671f\u672b\u4f59\u989d\u501f\u8d37\u6807\u8bc6
statement.closingBooked.date=\u671f\u672b\u4f59\u989d\u65e5\u671f
statement.closingBooked.ccy=\u671f\u672b\u4f59\u989d\u5e01\u79cd
statement.closingBooked.amt=\u671f\u672b\u4f59\u989d\u91d1\u989d
statement.entry.valueDate=\u4ea4\u6613\u8d77\u606f\u65e5
statement.entry.crdr=\u4ea4\u6613\u501f\u8d37\u6807\u8bc6
statement.entry.ccy=\u4ea4\u6613\u5e01\u79cd
statement.entry.amt=\u4ea4\u6613\u91d1\u989d
statement.entry.txnRef=\u5f00\u6237\u884c\u53c2\u8003\u6807\u8bc6
statement.entry.acctSvcrRef=\u5e10\u6237\u884c\u53c2\u8003\u6807\u8bc6
statement.entry.addtlTxInf=\u9644\u8a00
message.id=\u4e1a\u52a1\u7f16\u53f7
endToEnd.id=\u76f8\u5173\u4e1a\u52a1\u7f16\u53f7
endToEnd.id=\u7aef\u5230\u7aef\u552f\u4e00\u6807\u8bc6
uetr=\u62a5\u6587\u8ddf\u8e2a\u53f7
settlement.date=\u7ed3\u7b97\u91d1\u989d
settlement.amt=\u7ed3\u7b97\u91d1\u989d
original.settlement.amt=\u539f\u59cb\u7ed3\u7b97\u91d1\u989d
settlement.method=\u7ed3\u7b97\u65b9\u5f0f
settlement.acct=\u7ed3\u7b97\u8d26\u53f7
settlement.date=\u8d77\u606f\u65e5
settlement.amt=\u53d1\u6c47\u91d1\u989d
original.settlement.amt=\u6536\u6c47\u91d1\u989d
exchange.rate=\u6c47\u7387
charge.by=\u8d39\u7528\u627f\u62c5\u65b9
charge.amt=\u8d39\u7528\u91d1\u989d
ccy=\u5e01\u79cd
debtor.info=\u6c47\u6b3e\u65b9\u4fe1\u606f
debtor.acct.info=\u6c47\u6b3e\u65b9\u8d26\u6237\u4fe1\u606f
creditor.info=\u6536\u6b3e\u4eba\u4fe1\u606f
#party
name=\u540d\u79f0
organisation.bic=\u7ec4\u7ec7\u673a\u6784\u6807\u8bc6
organisation.lei=\u7ec4\u7ec7\u673a\u6784\u6cd5\u4eba\u6807\u8bc6
organisation.other.code=\u7ec4\u7ec7\u673a\u6784\u5176\u4ed6\u6807\u8bc6\u4ee3\u7801
organisation.other.id=\u7ec4\u7ec7\u673a\u6784\u5176\u4ed6\u6807\u8bc6
private.brith.date=\u51fa\u751f\u65e5\u671f
private.brith.country=\u51fa\u751f\u56fd\u5bb6
private.brith.province=\u51fa\u751f\u7701\u4efd
private.brith.city=\u51fa\u751f\u57ce\u5e02
private.other.code=\u4e2a\u4eba\u4fe1\u606f\u5176\u4ed6\u6807\u8bc6\u4ee3\u7801
private.other.id=\u4e2a\u4eba\u4fe1\u606f\u5176\u4ed6\u6807\u8bc6
phone.number=\u7535\u8bdd\u53f7\u7801
mobile.number=\u624b\u673a\u53f7\u7801
fax.number=\u4f20\u771f\u53f7\u7801
email.number=\u90ae\u7bb1\u5730\u5740
contact.other.type=\u5176\u4ed6\u8054\u7cfb\u65b9\u5f0f
contact.other.id=\u5176\u4ed6\u8054\u7cfb\u65b9\u5f0f\u6807\u8bc6
#address
address.type=\u5730\u5740\u7c7b\u578b
address.country=\u56fd\u5bb6
address.department=\u7701\u4efd
address.sub.department=\u57ce\u5e02
address.town.name=\u57ce\u9547
address.street.name=\u8857\u9053
address.building.number=\u5efa\u7b51\u95e8\u724c\u53f7
address.building.name=\u5efa\u7b51\u540d\u79f0
address.floor=\u697c\u5c42
address.room=\u623f\u95f4\u53f7
address.post.box=\u90ae\u7bb1
address.post.code=\u90ae\u653f\u7f16\u7801
address.line=\u5730\u5740\u4fe1\u606f
dbtrInfo=\u6c47\u6b3e\u65b9\u4fe1\u606f
dbtrAgtInfo=\u6c47\u6b3e\u884c\u4fe1\u606f
instgRmbrsmntAgtInfo=\u53d1\u62a5\u884c\u7684\u4ee3\u7406\u884c\u4fe1\u606f
instdRmbrsmntAgtInfo=\u6536\u62a5\u884c\u7684\u4ee3\u7406\u884c\u4fe1\u606f
thrdRmbrsmntAgtInfo=\u7b2c\u4e09\u65b9\u507f\u4ed8\u884c\u4fe1\u606f
intrmyAgt1Info=\u4e2d\u95f4\u884c\u4fe1\u606f
cdtrAgtInfo=\u6536\u6b3e\u884c\u4fe1\u606f
cdtrInfo=\u6536\u6b3e\u65b9\u4fe1\u606f
charge.by=\u8d39\u7528\u627f\u62c5\u65b9\u5f0f
charge.info=\u8d39\u7528\u660e\u7ec6
remittanceInformation=\u6c47\u6b3e\u4fe1\u606f
regulatoryReporting=\u6cd5\u89c4\u8bf4\u660e
#party&agent
acctIdIban=\u8d26\u53f7
acctId=\u8d26\u53f7
nm=\u540d\u79f0
orgAnyBIC=\u7ec4\u7ec7\u673a\u6784\u884c\u53f7
pstlAdrCtry=\u5c45\u4f4f\u5730\u56fd\u5bb6
pstlAdrCtrySubDvsn=\u5c45\u4f4f\u5730\u7701\u4efd
pstlAdrDstrctNm=\u5c45\u4f4f\u5730\u57ce\u5e02
pstlAdrTwnLctnNm=\u5c45\u4f4f\u5730\u533a\u53bf
pstlAdrDept=\u90e8\u95e8\u540d\u79f0
pstlAdrSubDept=\u5b50\u90e8\u95e8\u540d\u79f0
pstlAdrStrtNm=\u5c45\u4f4f\u5730\u8857\u9053
pstlAdrBldgNb=\u4f4f\u5740\u95e8\u724c\u53f7
pstlAdrBldgNm=\u4f4f\u5740\u540d\u79f0
pstlAdrFlr=\u4f4f\u5740\u697c\u5c42
pstlAdrRoom=\u4f4f\u5740\u623f\u95f4\u53f7
pstlAdrTwnNm=\u5c45\u4f4f\u5730\u57ce\u9547\u540d\u79f0
pstlAdrPstBx=\u4f4f\u5740\u90ae\u7bb1\u7f16\u53f7
pstlAdrPstCd=\u4f4f\u5740\u90ae\u7f16
adrLines=\u4f4f\u5740\u4fe1\u606f
bicfi=\u7ec4\u7ec7\u673a\u6784\u884c\u53f7
clrSysIdType=\u6e05\u7b97\u7cfb\u7edf\u4ee3\u7801
clrSysId=\u6e05\u7b97\u7cfb\u7edf\u884c\u53f7
\ No newline at end of file
......@@ -8,10 +8,14 @@ credit=Credit
debit=Debit
reversal.credit=Reversal Credit
reversal.debit=Reversal Debit
yes=Yes
no=No
statement.id=Statement Identifier
statement.account=Statement Account Number
statement.account.ccy=Statement Account Currency
statement.sequence.number=Statement Sequence Number
statement.page.number=Statement Page Number
statement.lastPgInd=Last Page Indicator
statement.openingBooked.crdr=Opening Booked Credit Debit Indicator
statement.openingBooked.date=Opening Booked Value Date
statement.openingBooked.ccy=Opening Booked Currency
......@@ -24,4 +28,52 @@ statement.entry.valueDate=Statement Entry Value Date
statement.entry.crdr=Statement Entry Credit Debit Indicator
statement.entry.ccy=Statement Entry Currency
statement.entry.amt=Statement Entry Currency
statement.entry.endToEndId=Statement Entry End To End Identification
\ No newline at end of file
statement.entry.txnRef=Statement Entry Transaction Reference
statement.entry.acctSvcrRef=Statement Entry Account Service Reference
statement.entry.addtlTxInf=Additional Information
message.id=Message Identifier
endToEnd.id=End To End Identification
uetr=UETR
settlement.method=Settlement Method
settlement.acct=Settlement Account Number
settlement.date=Interbank Settlement Date
settlement.amt=Interbank Settlement Amount
original.settlement.amt=Instructed Amount
exchange.rate=Exchange Rate
ccy=Currency
dbtrInfo=Debtor
dbtrAgtInfo=Debtor Agent
instgRmbrsmntAgtInfo=Instructing Reimbursement Agent
instdRmbrsmntAgtInfo=Instructed Reimbursement Agent
thrdRmbrsmntAgtInfo=Third Reimbursement Agent
intrmyAgt1Info=Intermediary Agent 1
cdtrAgtInfo=Creditor Agent
cdtrInfo=Creditor
charge.by=Charge Bearer
charge.info=Charges Information
remittanceInformation=Remittance Information
regulatoryReporting=Regulatory Reporting
#party&agent
acctIdIban=Account Number(IBAN)
acctId=Account Number
nm=Name
orgAnyBIC=Organisation Identification BIC
pstlAdrCtry=Country
pstlAdrCtrySubDvsn=Country Sub Division
pstlAdrDstrctNm=District Name
pstlAdrTwnLctnNm=Town Location Name
pstlAdrDept=Department
pstlAdrSubDept=Sub Department
pstlAdrStrtNm=Street Name
pstlAdrBldgNb=Building Number
pstlAdrBldgNm=Building Name
pstlAdrFlr=Floor
pstlAdrRoom=Room
pstlAdrTwnNm=Town Name
pstlAdrPstBx=Post Box
pstlAdrPstCd=Post Code
adrLines=Address Line
bicfi=Financial Institution BIC
clrSysIdType=Clearing System Code
clrSysId=Clearing System Identification
\ No newline at end of file
......@@ -5,12 +5,13 @@ ntryCdtDbtInd=cdtDbtInd
ntryRvslInd=rvslInd&boolean
ntrySts=sts.cd
ntryStsPrtry=sts.prtry
ntryBookgDt=bookgDt.dt
ntryValDt=valDt.dt
ntryBookgDt=bookgDt.dt?bookgDt.dtTm
ntryValDt=valDt.dt?valDt.dtTm
ntryAcctSvcrRef=acctSvcrRef
ntryBkTxCdDomnCd=bkTxCd.domn.cd
ntryBkTxCdFmlyCd=bkTxCd.domn.fmly.cd
ntryBkTxCdFmlySubFmlyCd=bkTxCd.domn.fmly.subFmlyCd
ntryBkTxCdPrtryCd=bkTxCd.prtry.cd
endToEndId=ntryDtls.txDtls.refs.endToEndId
addtlTxInf=ntryDtls.txDtls.addtlTxInf
\ No newline at end of file
addtlTxInf=ntryDtls.txDtls.addtlTxInf
instrId=ntryDtls.txDtls.refs.instrId
\ No newline at end of file
......@@ -5,6 +5,8 @@ import org.apache.commons.io.FileUtils;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Map;
public class Mx2ElementTest {
......@@ -14,4 +16,13 @@ public class Mx2ElementTest {
String elementStr = SwiftTransfer.mx2Element(file);
System.out.println(elementStr);
}
@Test
public void testMx2Map() throws IOException {
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00800108.xml"));
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt05300108_950.xml"));
String xmlStr = FileUtils.readFileToString(file);
String elementStr = SwiftTransfer.showMxElement(xmlStr, "CN");
System.out.println(elementStr);
}
}
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