Commit 07dd6283 by chengzhuoshen

mt103retn,mt202retn,mt205retn转pacs004001

parent ea0d9b7b
package com.brilliance.swift.mt2mx;
import com.alibaba.fastjson.JSONObject;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.vo.SwiftTranslationErrorInfo;
import com.brilliance.swift.vo.SwiftTranslationReport;
import com.brilliance.swift.vo.common.MessagePriority;
import com.prowidesoftware.swift.model.SwiftBlock5;
......@@ -18,6 +21,7 @@ import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class AbstractMt2MxCreator implements Mt2MxCreator{
......@@ -146,4 +150,32 @@ public abstract class AbstractMt2MxCreator implements Mt2MxCreator{
}
return createDateStr;
}
/**
* 封装报文转换详细报告
* @param errorCode
* @param location
* @param originalValue
* @return
*/
protected void buildSTErrorInfo(String errorCode, String location, String originalValue) {
SwiftTranslationReport str = context.get(SwiftTranslationReport.class);
SwiftTranslationErrorInfo errorInfo = SwiftTransferUtil.getSwiftTranslationErrorInfoByErrorCode(errorCode);
errorInfo.setLocation(location);
errorInfo.setOriginalValue(originalValue);
List<SwiftTranslationErrorInfo> errorInfos = str.getErrorInfos();
boolean existFlag = false;
for (int i=0; i<errorInfos.size(); i++) {
if (SwiftTransferUtil.compareStErrorInfo(errorInfo, errorInfos.get(i))) {
existFlag = true;
break;
}
}
if (!existFlag) {
str.addErrorInfo(errorInfo);
if ("FAILURE".equalsIgnoreCase(errorInfo.getErrorType())) {
throw new SwiftException(location + Mx2MtConstants.NEW_LINE + "-" + errorInfo.getErrorType() + ":" + errorInfo.getDescription());
}
}
}
}
......@@ -11,6 +11,8 @@ public class Mt2MxContextIdentifier {
public static final String MT_RECEIVE_BIC = "mt.receive.bic";
public static final String MT_TO_MX_NOW = "mt.to.mx.now";
public static final String MT_TO_MX_RETURN_FLAG = "mt.to.mx.return.flag";
/**
* 外部参数
*/
......
......@@ -8,6 +8,7 @@ import com.brilliance.swift.mt2mx.camt054001.Mt2MxCamt054001Creator;
import com.brilliance.swift.mt2mx.camt056001.Mt2MxCamt056001Creator;
import com.brilliance.swift.mt2mx.camt057001.Mt2MxCamt057001Creator;
import com.brilliance.swift.mt2mx.pacs002001.Mt2MxPacs002001Creator;
import com.brilliance.swift.mt2mx.pacs004001.Mt2MxPacs004001Creator;
import com.brilliance.swift.mt2mx.pacs008001.Mt2MxPacs008001Creator;
import com.brilliance.swift.mt2mx.pacs009001.Mt2MxPacs009001Creator;
import com.brilliance.swift.util.StringUtil;
......@@ -60,7 +61,7 @@ public class Mt2MxCreatorManager {
} else if ("103REJT".equals(messageType) || "202REJT".equals(messageType) || "205REJT".equals(messageType)) {
return new Mt2MxPacs002001Creator();
} else if ("103RETN".equals(messageType) || "202RETN".equals(messageType) || "205RETN".equals(messageType)) {
return new Mt2MxPacs009001Creator();
return new Mt2MxPacs004001Creator();
} else if("196".equals(messageType) || "296".equals(messageType)) {
return new Mt2MxCamt029001Creator();
} else if("192".equals(messageType)||"292".equals(messageType)) {
......
package com.brilliance.swift.mt2mx.pacs004001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.mt2mx.AbstractMt2MxParseField;
import java.util.Map;
public abstract class AbstractMt2MxPacs004001ParseField extends AbstractMt2MxParseField {
protected Map<String, Object> appHdrMaps = null;
protected Map<String, Object> grpHdrMaps = null;
protected Map<String, Object> txInfMaps = null;
@Override
public void initJsonMaps() {
super.initJsonMaps();
appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
Map<String, Object> pmtRtrMaps = (Map<String, Object>)jsonMaps.get("pmtRtr");
grpHdrMaps = (Map<String, Object>)pmtRtrMaps.get("grpHdr");
JSONArray txInfJsonArray = (JSONArray) pmtRtrMaps.get("txInf");
txInfMaps = (Map<String, Object>)txInfJsonArray.get(0);
}
}
package com.brilliance.swift.mt2mx.pacs004001;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.mt2mx.AbstractMt2MxCreator;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.Mt2MxParseField;
import com.brilliance.swift.mt2mx.pacs004001.mt103retn.*;
import com.brilliance.swift.mt2mx.pacs004001.mt202retn.Pacs004001Parse21Field;
import com.brilliance.swift.mt2mx.pacs004001.mt202retn.Pacs004001Parse58Field;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.common.ChargeForEnum;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Mt2MxPacs004001Creator extends AbstractMt2MxCreator {
@Override
public void preProcess() {
super.preProcess();
jsonMaps.put("identifier", "pacs.004.001.09");
Map<String, Object> appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
appHdrMaps.put("msgDefIdr", "pacs.004.001.09");
AbstractMT abstractMT = context.get(AbstractMT.class);
//初始化转换和不需要BLOCK4的转换
Map<String, Object> pmtRtrMaps = new HashMap<>();
jsonMaps.put("pmtRtr", pmtRtrMaps);
Map<String, Object> grpHdrMaps = new HashMap<>();
pmtRtrMaps.put("grpHdr", grpHdrMaps);
grpHdrMaps.put("creDtTm", getCreateDateStr());
grpHdrMaps.put("nbOfTxs", "1");
Map<String, Object> txInfMaps = new HashMap<>();
JSONArray txInfJsonArray = new JSONArray();
txInfJsonArray.add(txInfMaps);
pmtRtrMaps.put("txInf", txInfJsonArray);
String uetr = abstractMT.getSwiftMessage().getUETR();
if (StringUtil.isNotEmpty(uetr)) {
txInfMaps.put("orgnlUETR", uetr);
} else {
buildSTErrorInfo(ERROR.T20087, "Block3/{121}", null);
}
//设置InstructingAgent InstructedAgent 取值从sendbic receivebic
String sendBic = (String) context.get(Mt2MxContextIdentifier.MT_SEND_BIC, true);
if (StringUtil.isNotEmpty(sendBic)) {
Map<String, Object> instgAgtMaps = new HashMap<>();
txInfMaps.put("instgAgt", instgAgtMaps);
mt_to_mxBICFI(sendBic, instgAgtMaps);
}
String receiverBic = (String) context.get(Mt2MxContextIdentifier.MT_RECEIVE_BIC, true);
if (StringUtil.isNotEmpty(receiverBic)) {
Map<String, Object> instdAgtMaps = new HashMap<>();
txInfMaps.put("instdAgt", instdAgtMaps);
mt_to_mxBICFI(receiverBic, instdAgtMaps);
}
//设置Service Level 取值从block3 {111:00[0-9]}
Tag tag111 = abstractMT.getSwiftMessage().getBlock3().getTagByName("111");
if (tag111 != null) {
String svcLvlCode = "";
String value = tag111.getValue();
if (value.matches("00[0-9]{1}")) {
svcLvlCode = value;
}
if (StringUtil.isNotEmpty(svcLvlCode)) {
Map<String, Object> orgnlTxRefMaps = new HashMap<>();
txInfMaps.put("orgnlTxRef", orgnlTxRefMaps);
Map<String, Object> pmtTpInfMaps = new HashMap<>();
orgnlTxRefMaps.put("pmtTpInf", pmtTpInfMaps);
JSONArray svcLvlJsonArray = new JSONArray();
pmtTpInfMaps.put("svcLvl", svcLvlJsonArray);
Map<String, Object> svcLvlMaps = new HashMap<>();
svcLvlJsonArray.add(svcLvlMaps);
svcLvlMaps.put("cd", "G" + svcLvlCode);
}
}
//202 205,ChargerBearer 默认值是SHAR
if ("202".equals(abstractMT.getMessageType()) || "205".equals(abstractMT.getMessageType())) {
txInfMaps.put("chrgBr", ChargeForEnum.SHAR.value());
buildSTErrorInfo(ERROR.T20096, "PmtRtr/TxInf/ChrgBr", null);
}
}
@Override
public List<Mt2MxParseField> getParseFieldList() {
AbstractMT abstractMT = context.get(AbstractMT.class);
List<Mt2MxParseField> list = new ArrayList<>();
if ("103".equals(abstractMT.getMessageType())) {
list.add(new Pacs004001Parse20Field());
list.add(new Pacs004001Parse13CField());
list.add(new Pacs004001Parse23BField());
list.add(new Pacs004001Parse23EField());
list.add(new Pacs004001Parse26TField());
list.add(new Pacs004001Parse32AField());
list.add(new Pacs004001Parse33BField());
list.add(new Pacs004001Parse36Field());
list.add(new Pacs004001Parse50Field());
list.add(new Pacs004001Parse52Field());
list.add(new Pacs004001ParseSetlMtdField());
list.add(new Pacs004001ParseSetlAcctField());
list.add(new Pacs004001Parse53Field());
list.add(new Pacs004001Parse54Field());
list.add(new Pacs004001Parse55Field());
list.add(new Pacs004001Parse56Field());
list.add(new Pacs004001Parse57Field());
list.add(new Pacs004001Parse59Field());
list.add(new Pacs004001Parse70Field());
list.add(new Pacs004001Parse71Field());
list.add(new Pacs004001Parse72Field());
list.add(new Pacs004001Parse77BField());
} else if ("202".equals(abstractMT.getMessageType())
|| "205".equals(abstractMT.getMessageType())) {
list.add(new Pacs004001Parse20Field());
list.add(new Pacs004001Parse21Field());
list.add(new Pacs004001Parse13CField());
list.add(new Pacs004001Parse32AField());
list.add(new com.brilliance.swift.mt2mx.pacs004001.mt202retn.Pacs004001Parse52Field());
list.add(new Pacs004001ParseSetlMtdField());
list.add(new Pacs004001ParseSetlAcctField());
list.add(new Pacs004001Parse53Field());
list.add(new Pacs004001Parse54Field());
list.add(new Pacs004001Parse56Field());
list.add(new Pacs004001Parse57Field());
list.add(new Pacs004001Parse58Field());
list.add(new Pacs004001Parse72Field());
}
return list;
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field13C;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse13CField extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "13C";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag[] tags = abstractMT.getSwiftMessage().getBlock4().getTagsByName(NAME);
if (tags != null && tags.length > 0) {
Map<String,Object> sttlmTmIndctnMaps = null;
if (txInfMaps.containsKey("sttlmTmIndctn")) {
sttlmTmIndctnMaps = (Map<String,Object>)txInfMaps.get("sttlmTmIndctn");
} else {
sttlmTmIndctnMaps = new HashMap<>();
txInfMaps.put("sttlmTmIndctn", sttlmTmIndctnMaps);
}
for (int i=0; i<tags.length; i++) {
Field13C field13C = (Field13C)tags[i].asField();
String dateTimeStr = "0001-01-01T"
+ field13C.getTime().substring(0,2)
+ ":" + field13C.getTime().substring(2,4)
+ ":00"
+ field13C.getSign()
+ field13C.getOffset().substring(0, 2)
+ ":" + field13C.getOffset().substring(2, 4);
if ("SNDTIME".equals(field13C.getCode())) {
sttlmTmIndctnMaps.put("dbtDtTm", dateTimeStr);
} else if ("RNCTIME".equals(field13C.getCode())) {
sttlmTmIndctnMaps.put("cdtDtTm", dateTimeStr);
}
}
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
public class Pacs004001Parse20Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "20";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag20 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag20 != null) {
appHdrMaps.put("bizMsgIdr", tag20.getValue());
grpHdrMaps.put("msgId", tag20.getValue());
txInfMaps.put("rtrId", tag20.getValue());
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
public class Pacs004001Parse23BField extends AbstractMt2MxPacs004001ParseField {
@Override
public void parseField() throws SwiftException {
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
public class Pacs004001Parse23EField extends AbstractMt2MxPacs004001ParseField {
@Override
public void parseField() throws SwiftException {
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
public class Pacs004001Parse26TField extends AbstractMt2MxPacs004001ParseField {
@Override
public void parseField() throws SwiftException {
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.DateUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field32A;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse32AField extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "32A";
@Override
public void parseField() throws SwiftException {
try {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
Field32A field32A = (Field32A)tag.asField();
Date date = DateUtil.parseDate("20"+field32A.getDate(), "yyyyMMdd");
String dateStr = DateUtil.format(date, "yyyy-MM-dd");
txInfMaps.put("intrBkSttlmDt", dateStr);
Map<String, Object> rtrdIntrBkSttlmAmtMaps = new HashMap<>();
rtrdIntrBkSttlmAmtMaps.put("value", field32A.amount());
rtrdIntrBkSttlmAmtMaps.put("ccy", field32A.getCurrency());
txInfMaps.put("rtrdIntrBkSttlmAmt", rtrdIntrBkSttlmAmtMaps);
}
} catch (ParseException e) {
throw new SwiftException(e.getMessage());
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field33B;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse33BField extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "33B";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
Field33B field33B = (Field33B)tag.asField();
Map<String, Object> rtrdInstdAmtMaps = new HashMap<>();
rtrdInstdAmtMaps.put("value", field33B.amount());
rtrdInstdAmtMaps.put("ccy", field33B.getCurrency());
txInfMaps.put("rtrdInstdAmt", rtrdInstdAmtMaps);
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field36;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.math.BigDecimal;
public class Pacs004001Parse36Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "36";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
Field36 field36 = (Field36)tag.asField();
txInfMaps.put("xchgRate", new BigDecimal(field36.getRateAsNumber().toString()).stripTrailingZeros());
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.common.OrganisationIdentificationCode;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field50A;
import com.prowidesoftware.swift.model.field.Field50F;
import com.prowidesoftware.swift.model.field.Field50K;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pacs004001Parse50Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "50A";
private static final String NAME_F = "50F";
private static final String NAME_K = "50K";
@Override
public void parseField() throws SwiftException {
Field50A field50A = null;
Field50F field50F = null;
Field50K field50K = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field50A = (Field50A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_F);
if (tag != null) {
field50F = (Field50F)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_K);
if (tag != null) {
field50K = (Field50K)tag.asField();
}
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> dbtrMaps = null;
if (rtrChainMaps.containsKey("dbtr")) {
dbtrMaps = (Map<String, Object>) rtrChainMaps.get("dbtr");
} else {
dbtrMaps = new HashMap<>();
}
Map<String, Object> ptyMaps = null;
if (dbtrMaps.containsKey("pty")) {
ptyMaps = (Map<String, Object>) dbtrMaps.get("pty");
} else {
ptyMaps = new HashMap<>();
}
if (field50A != null) {
String bicCode = field50A.getBIC();
mt_to_mxAnyBIC(bicCode, ptyMaps);
if (StringUtil.isEmpty(field50A.getComponent1())) {
buildDefaultValue(ptyMaps);
}
}
if (field50F != null) {
String partyIdentifier = field50F.getPartyIdentifier();
String nameAddress = "";
List<String> lines = field50F.getLines();
for (int i=0; i<lines.size(); i++) {
if (i == 0) {
continue;
}
if (i == lines.size()-1) {
nameAddress += lines.get(i);
} else {
nameAddress += lines.get(i) + Mx2MtConstants.NEW_LINE;
}
}
if (partyIdentifier.startsWith("/")) {
buildDefaultValue(ptyMaps);
} else {
Map<String, Object> idMaps = null;
if (ptyMaps.containsKey("id")) {
idMaps = (Map<String, Object>) ptyMaps.get("id");
} else {
idMaps = new HashMap<>();
ptyMaps.put("id", idMaps);
}
mt_to_mxFATFIdentification(partyIdentifier, nameAddress, idMaps);
}
mt_to_mxFATFNameAndAddress(partyIdentifier, nameAddress, ptyMaps);
}
if (field50K != null) {
String account = "";
if (StringUtil.isNotEmpty(field50K.getComponent1())) {
account += "/" + field50K.getComponent1();
}
String nameAddress1 = field50K.getNameAndAddressLine1();
if (("/"+Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE).equals(account) && StringUtil.isNotEmpty(nameAddress1) && nameAddress1.startsWith("//")) {
Map<String, Object> agtMaps = null;
if (dbtrMaps.containsKey("agt")) {
agtMaps = (Map<String, Object>) dbtrMaps.get("agt");
} else {
agtMaps = new HashMap<>();
dbtrMaps.put("agt", agtMaps);
}
Map<String, Object> finInstnIdMaps = null;
if (agtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)agtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
agtMaps.put("finInstnId", finInstnIdMaps);
}
if (isMTClearingSystemCodeInList(nameAddress1)) {
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(nameAddress1, clrSysMmbIdMaps);
} else {
String nameAddress = field50K.getNameAndAddress();
mt_to_mxPartyNameAndAddress(nameAddress, finInstnIdMaps);
buildSTErrorInfo(ERROR.T20126, "PmtRtr/TxInf/RtrChain/Dbtr/Agt/FinInstnId", null);
}
} else {
String nameAddress = field50K.getNameAndAddress();
mt_to_mxPartyNameAndAddress(nameAddress, ptyMaps);
if (StringUtil.isEmpty(account)) {
buildDefaultValue(ptyMaps);
}
}
}
if (ptyMaps.size() > 0) {
dbtrMaps.put("pty", ptyMaps);
}
if (dbtrMaps.size() > 0) {
rtrChainMaps.put("dbtr", dbtrMaps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
/**
* IF 50A/Account 50K/Account IsAbsent
* THEN Copy "NOTPROVIDED" to Debtor/Id/OrgID/Other/ID
* and "TXID" to SchemeName/Code
* @param dbtrMaps
*/
private void buildDefaultValue(Map<String, Object> dbtrMaps) {
Map<String, Object> idMaps = null;
if (dbtrMaps.containsKey("id")) {
idMaps = (Map<String, Object>)dbtrMaps.get("id");
} else {
idMaps = new HashMap<>();
dbtrMaps.put("id", idMaps);
}
Map<String, Object> idOrgMaps = null;
if (idMaps.containsKey("orgId")) {
idOrgMaps = (Map<String, Object>)idMaps.get("orgId");
} else {
idOrgMaps = new HashMap<>();
idMaps.put("orgId", idOrgMaps);
}
JSONArray othrJsonArray = null;
if (idOrgMaps.containsKey("othr")) {
othrJsonArray = (JSONArray) idOrgMaps.get("othr");
} else {
othrJsonArray = new JSONArray();
idOrgMaps.put("othr", othrJsonArray);
}
Map<String, Object> othrMaps = new HashMap<>();
othrJsonArray.add(othrMaps);
othrMaps.put("id", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
Map<String, Object> schmeNmMaps = null;
if (othrMaps.containsKey("schmeNm")) {
schmeNmMaps = (Map<String, Object>) othrMaps.get("schmeNm");
} else {
schmeNmMaps = new HashMap<>();
othrMaps.put("schmeNm", schmeNmMaps);
}
schmeNmMaps.put("cd", OrganisationIdentificationCode.TXID.value());
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field52A;
import com.prowidesoftware.swift.model.field.Field52D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse52Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "52A";
private static final String NAME_D = "52D";
@Override
public void parseField() throws SwiftException {
Field52A field52A = null;
Field52D field52D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field52A = (Field52A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field52D = (Field52D)tag.asField();
}
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> dbtrAgtMaps = null;
if (rtrChainMaps.containsKey("dbtrAgt")) {
dbtrAgtMaps = (Map<String, Object>) rtrChainMaps.get("dbtrAgt");
} else {
dbtrAgtMaps = new HashMap<>();
}
String account = "";
if (field52A != null) {
String bicCode = field52A.getBIC();
mt_to_mxBICFI(bicCode, dbtrAgtMaps);
if (StringUtil.isNotEmpty(field52A.getComponent1())) {
account += "/" + field52A.getComponent1();
}
if (StringUtil.isNotEmpty(field52A.getComponent2())) {
account += "/" + field52A.getComponent2();
}
} else if (field52D != null) {
if (StringUtil.isNotEmpty(field52D.getComponent1())) {
account += "/" + field52D.getComponent1();
}
if (StringUtil.isNotEmpty(field52D.getComponent2())) {
account += "/" + field52D.getComponent2();
}
String nameAddress = field52D.getNameAndAddress();
mt_to_mxFinancialInstitutionNameAndUnstructuredAddress(nameAddress, dbtrAgtMaps);
}
if (StringUtil.isNotEmpty(account)) {
if (account.startsWith("//") && !account.startsWith("//CH") && !account.startsWith("//FW")) {
Map<String, Object> finInstnIdMaps = null;
if (dbtrAgtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)dbtrAgtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
dbtrAgtMaps.put("finInstnId", finInstnIdMaps);
}
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
}
}
if (dbtrAgtMaps.size() > 0) {
rtrChainMaps.put("dbtrAgt", dbtrAgtMaps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.VoSettlementMethodHelper;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field53A;
import com.prowidesoftware.swift.model.field.Field53D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse53Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "53A";
//private static final String NAME_B = "53B";
private static final String NAME_D = "53D";
@Override
public void parseField() throws SwiftException {
VoSettlementMethodHelper setlMtdHelper = context.get(VoSettlementMethodHelper.class);
if (setlMtdHelper.isTranslate53Flag()) {
//53B 只能翻译成 Group Header -> Settlement Information -> Settlement Account/Settlement Method
Field53A field53A = null;
Field53D field53D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field53A = (Field53A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field53D = (Field53D)tag.asField();
}
Map<String, Object> sttlmInfMaps = null;
if (grpHdrMaps.containsKey("sttlmInf")) {
sttlmInfMaps = (Map<String, Object>) grpHdrMaps.get("sttlmInf");
} else {
sttlmInfMaps = new HashMap<>();
grpHdrMaps.put("sttlmInf", sttlmInfMaps);
}
Map<String, Object> instgRmbrsmntAgtMaps = null;
if (sttlmInfMaps.containsKey("instgRmbrsmntAgt")) {
instgRmbrsmntAgtMaps = (Map<String, Object>) sttlmInfMaps.get("instgRmbrsmntAgt");
} else {
instgRmbrsmntAgtMaps = new HashMap<>();
sttlmInfMaps.put("instgRmbrsmntAgt", instgRmbrsmntAgtMaps);
}
String account = "";
if (field53A != null) {
String bicCode = field53A.getBIC();
mt_to_mxBICFI(bicCode, instgRmbrsmntAgtMaps);
if (StringUtil.isNotEmpty(field53A.getComponent1())) {
account += "/" + field53A.getComponent1();
}
if (StringUtil.isNotEmpty(field53A.getComponent2())) {
account += "/" + field53A.getComponent2();
}
} else if (field53D != null) {
String nameAddress = field53D.getNameAndAddress();
mt_to_mxFinancialInstitutionNameAndUnstructuredAddress(nameAddress, instgRmbrsmntAgtMaps);
if (StringUtil.isNotEmpty(field53D.getComponent1())) {
account += "/" + field53D.getComponent1();
}
if (StringUtil.isNotEmpty(field53D.getComponent2())) {
account += "/" + field53D.getComponent2();
}
}
if (StringUtil.isNotEmpty(account)) {
Map<String, Object> instgRmbrsmntAgtAcctMaps = null;
if (sttlmInfMaps.containsKey("instgRmbrsmntAgtAcct")) {
instgRmbrsmntAgtAcctMaps = (Map<String, Object>) sttlmInfMaps.get("instgRmbrsmntAgtAcct");
} else {
instgRmbrsmntAgtAcctMaps = new HashMap<>();
sttlmInfMaps.put("instgRmbrsmntAgtAcct", instgRmbrsmntAgtAcctMaps);
}
if (account.startsWith("//") && !account.startsWith("//CH")) {
Map<String, Object> finInstnIdMaps = null;
if (instgRmbrsmntAgtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)instgRmbrsmntAgtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
instgRmbrsmntAgtMaps.put("finInstnId", finInstnIdMaps);
}
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
} else {
mt_to_mxFinancialInstitutionAccount(account, instgRmbrsmntAgtAcctMaps, "InstgRmbrsmntAgtAcct/Id");
}
}
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.vo.VoSettlementMethodHelper;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field55A;
import com.prowidesoftware.swift.model.field.Field55B;
import com.prowidesoftware.swift.model.field.Field55D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
/**
* 如果55存在,那么53 54必须同时存在
*/
public class Pacs004001Parse55Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "55A";
private static final String NAME_B = "55B";
private static final String NAME_D = "55D";
@Override
public void parseField() throws SwiftException {
VoSettlementMethodHelper setlMtdHelper = context.get(VoSettlementMethodHelper.class);
if (setlMtdHelper.isTranslate55Flag()) {
Field55A field55A = null;
Field55B field55B = null;
Field55D field55D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field55A = (Field55A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_B);
if (tag != null) {
field55B = (Field55B)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field55D = (Field55D)tag.asField();
}
if (field55A != null || field55B != null || field55D != null) {
buildSTErrorInfo(ERROR.T20008, "PmtRtr/GrpHdr/SttlmInf/ThrdRmbrsmntAgt", null);
}
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field56A;
import com.prowidesoftware.swift.model.field.Field56C;
import com.prowidesoftware.swift.model.field.Field56D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pacs004001Parse56Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "56A";
private static final String NAME_C = "56C";
private static final String NAME_D = "56D";
@Override
public void parseField() throws SwiftException {
Field56A field56A = null;
Field56C field56C = null;
Field56D field56D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field56A = (Field56A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_C);
if (tag != null) {
field56C = (Field56C)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field56D = (Field56D)tag.asField();
}
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> intrmyAgt1Maps = null;
if (rtrChainMaps.containsKey("intrmyAgt1")) {
intrmyAgt1Maps = (Map<String, Object>) rtrChainMaps.get("intrmyAgt1");
} else {
intrmyAgt1Maps = new HashMap<>();
}
String account = "";
if (field56A != null) {
String bicCode = field56A.getBIC();
mt_to_mxBICFI(bicCode, intrmyAgt1Maps);
if (StringUtil.isNotEmpty(field56A.getComponent1())) {
account += "/" + field56A.getComponent1();
}
if (StringUtil.isNotEmpty(field56A.getComponent2())) {
account += "/" + field56A.getComponent2();
}
if (account.startsWith("//") && !account.startsWith("//CH") && !account.startsWith("//FW") && !account.startsWith("//RT")) {
Map<String, Object> finInstnIdMaps = null;
if (intrmyAgt1Maps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)intrmyAgt1Maps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
intrmyAgt1Maps.put("finInstnId", finInstnIdMaps);
}
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
}
} else if (field56C != null) {
account = field56C.getValue();
Map<String, Object> finInstnIdMaps = null;
if (intrmyAgt1Maps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)intrmyAgt1Maps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
intrmyAgt1Maps.put("finInstnId", finInstnIdMaps);
}
if (account.startsWith("//") && !account.startsWith("//CH") && !account.startsWith("//FW")) {
if (isMTClearingSystemCodeInList(account)) {
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
//name address 设置NOTPROVIDED
finInstnIdMaps.put("nm", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
Map<String, Object> pstlAdrMaps = null;
if (finInstnIdMaps.containsKey("pstlAdr")) {
pstlAdrMaps = (Map<String, Object>)finInstnIdMaps.get("pstlAdr");
} else {
pstlAdrMaps = new HashMap<>();
finInstnIdMaps.put("pstlAdr", pstlAdrMaps);
}
List<String> adrLineList = new ArrayList<>();
adrLineList.add(Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
pstlAdrMaps.put("adrLine", adrLineList);
} else {
mt_to_mxClearingSystemToNameAndAddressLine(account, null, finInstnIdMaps, "IntrmyAgt1/FinInstnId");
}
}
} else if (field56D != null) {
if (StringUtil.isNotEmpty(field56D.getComponent1())) {
account += "/" + field56D.getComponent1();
}
if (StringUtil.isNotEmpty(field56D.getComponent2())) {
account += "/" + field56D.getComponent2();
}
String nameAddress = field56D.getNameAndAddress();
mt_to_mxFinancialInstitutionNameAndUnstructuredAddress(nameAddress, intrmyAgt1Maps);
if (account.startsWith("//") && !account.startsWith("//CH") && !account.startsWith("//FW")) {
Map<String, Object> finInstnIdMaps = null;
if (intrmyAgt1Maps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)intrmyAgt1Maps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
intrmyAgt1Maps.put("finInstnId", finInstnIdMaps);
}
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
}
}
if (intrmyAgt1Maps.size() > 0) {
rtrChainMaps.put("intrmyAgt1", intrmyAgt1Maps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field59;
import com.prowidesoftware.swift.model.field.Field59A;
import com.prowidesoftware.swift.model.field.Field59F;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pacs004001Parse59Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "59";
private static final String NAME_A = "59A";
private static final String NAME_F = "59F";
@Override
public void parseField() throws SwiftException {
Field59 field59 = null;
Field59A field59A = null;
Field59F field59F = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
field59 = (Field59)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field59A = (Field59A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_F);
if (tag != null) {
field59F = (Field59F)tag.asField();
}
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> cdtrMaps = null;
if (rtrChainMaps.containsKey("cdtr")) {
cdtrMaps = (Map<String, Object>) rtrChainMaps.get("cdtr");
} else {
cdtrMaps = new HashMap<>();
}
Map<String, Object> ptyMaps = null;
if (cdtrMaps.containsKey("pty")) {
ptyMaps = (Map<String, Object>) cdtrMaps.get("pty");
} else {
ptyMaps = new HashMap<>();
}
String account = "";
if (field59A != null) {
String bicCode = field59A.getBIC();
if (StringUtil.isNotEmpty(field59A.getComponent1())) {
account += "/" + field59A.getComponent1();
}
mt_to_mxAnyBIC(bicCode, ptyMaps);
if (StringUtil.isEmpty(account)) {
buildDefaultValue(ptyMaps);
}
}
if (field59F != null) {
if (StringUtil.isNotEmpty(field59F.getComponent1())) {
account += "/" + field59F.getComponent1();
}
if (StringUtil.isEmpty(account)) {
buildDefaultValue(ptyMaps);
}
String nameAddress = "";
List<String> lines = field59F.getLines();
for (int i=0; i<lines.size(); i++) {
if (i == 0 && StringUtil.isNotEmpty(account)) {
continue;
}
if (i == lines.size()-1) {
nameAddress += lines.get(i);
} else {
nameAddress += lines.get(i) + Mx2MtConstants.NEW_LINE;
}
}
mt_to_mxPartyNameAndStructuredAddress(nameAddress, ptyMaps);
}
if (field59 != null) {
if (StringUtil.isNotEmpty(field59.getComponent1())) {
account += "/" + field59.getComponent1();
}
String nameAddress1 = field59.getNameAndAddressLine1();
if (("/"+Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE).equals(account) && StringUtil.isNotEmpty(nameAddress1) && nameAddress1.startsWith("//")) {
Map<String, Object> agtMaps = null;
if (cdtrMaps.containsKey("agt")) {
agtMaps = (Map<String, Object>) cdtrMaps.get("agt");
} else {
agtMaps = new HashMap<>();
cdtrMaps.put("agt", agtMaps);
}
Map<String, Object> finInstnIdMaps = null;
if (agtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)agtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
agtMaps.put("finInstnId", finInstnIdMaps);
}
if (isMTClearingSystemCodeInList(nameAddress1)) {
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(nameAddress1, clrSysMmbIdMaps);
} else {
String nameAddress = field59.getNameAndAddress(Mx2MtConstants.NEW_LINE);
mt_to_mxPartyNameAndAddress(nameAddress, finInstnIdMaps);
buildSTErrorInfo(ERROR.T20127, "PmtRtr/TxInf/RtrChain/Cdtr/Agt/FinInstnId", null);
}
} else {
String nameAddress = field59.getNameAndAddress(Mx2MtConstants.NEW_LINE);
mt_to_mxPartyNameAndAddress(nameAddress, ptyMaps);
if (StringUtil.isEmpty(account)) {
buildDefaultValue(ptyMaps);
}
}
}
if (ptyMaps.size() > 0) {
cdtrMaps.put("pty", ptyMaps);
}
if (cdtrMaps.size() > 0) {
rtrChainMaps.put("cdtr", cdtrMaps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
/**
* IF 59A/Account 59/Account IsAbsent
* THEN Copy "NOTPROVIDED" to Debtor/Id/OrgID/Other/ID
* and "TXID" to SchemeName/Code
* @param dbtrMaps
*/
private void buildDefaultValue(Map<String, Object> dbtrMaps) {
Map<String, Object> idMaps = null;
if (dbtrMaps.containsKey("id")) {
idMaps = (Map<String, Object>)dbtrMaps.get("id");
} else {
idMaps = new HashMap<>();
dbtrMaps.put("id", idMaps);
}
Map<String, Object> idOrgMaps = null;
if (idMaps.containsKey("orgId")) {
idOrgMaps = (Map<String, Object>)idMaps.get("orgId");
} else {
idOrgMaps = new HashMap<>();
idMaps.put("orgId", idOrgMaps);
}
JSONArray othrJsonArray = null;
if (idOrgMaps.containsKey("othr")) {
othrJsonArray = (JSONArray) idOrgMaps.get("othr");
} else {
othrJsonArray = new JSONArray();
idOrgMaps.put("othr", othrJsonArray);
}
Map<String, Object> othrMaps = new HashMap<>();
othrJsonArray.add(othrMaps);
othrMaps.put("id", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field70;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse70Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "70";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
Field70 field70 = (Field70)tag.asField();
String mt70 = field70.getValue();
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> ultmtDbtrMaps = null;
if (rtrChainMaps.containsKey("ultmtDbtr")) {
ultmtDbtrMaps = (Map<String, Object>)rtrChainMaps.get("ultmtDbtr");
} else {
ultmtDbtrMaps = new HashMap<>();
}
Map<String, Object> ptyMaps = null;
if (ultmtDbtrMaps.containsKey("pty")) {
ptyMaps = (Map<String, Object>)ultmtDbtrMaps.get("pty");
} else {
ptyMaps = new HashMap<>();
}
mt_to_mxUltimateParty(mt70, ptyMaps,"/ULTD/");
if (ptyMaps.size() > 0) {
ultmtDbtrMaps.put("pty", ptyMaps);
}
if (ultmtDbtrMaps.size() > 0) {
rtrChainMaps.put("ultmtDbtr", ultmtDbtrMaps);
}
Map<String, Object> ultmtCdtrMaps = null;
if (rtrChainMaps.containsKey("ultmtCdtr")) {
ultmtCdtrMaps = (Map<String, Object>)rtrChainMaps.get("ultmtCdtr");
} else {
ultmtCdtrMaps = new HashMap<>();
}
Map<String, Object> cdtrPtyMaps = null;
if (ultmtCdtrMaps.containsKey("pty")) {
cdtrPtyMaps = (Map<String, Object>)ultmtCdtrMaps.get("pty");
} else {
cdtrPtyMaps = new HashMap<>();
}
mt_to_mxUltimateParty(mt70, cdtrPtyMaps,"/ULTB/");
if (cdtrPtyMaps.size() > 0) {
ultmtCdtrMaps.put("pty", cdtrPtyMaps);
}
if (ultmtCdtrMaps.size() > 0) {
rtrChainMaps.put("ultmtCdtr", ultmtCdtrMaps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.vo.common.ChargeForEnum;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field71A;
import com.prowidesoftware.swift.model.field.Field71F;
import com.prowidesoftware.swift.model.field.Field71G;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pacs004001Parse71Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "71A";
private static final String NAME_F = "71F";
private static final String NAME_G = "71G";
@Override
public void parseField() throws SwiftException {
Field71A field71A = null;
Field71G field71G = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field71A = (Field71A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_G);
if (tag != null) {
field71G = (Field71G)tag.asField();
}
if (field71A != null) {
ChargeForEnum chargeForEnum = SwiftTransferUtil.getChargeForByDesc(field71A.getValue());
if (chargeForEnum != null) {
/**
* DEBT is removed from pacs.004 as it does not make sense.
* So if "OUR" is present in MT103 /RETN/,
* it is converted in "SHAR" in pacs.004
*/
if (ChargeForEnum.DEBT.equals(chargeForEnum)) {
chargeForEnum = ChargeForEnum.SHAR;
}
txInfMaps.put("chrgBr", chargeForEnum.value());
}
}
if (field71G != null) {
String ccy = field71G.getCurrency();
BigDecimal amt = field71G.amount();
JSONArray jsonArray = new JSONArray();
txInfMaps.put("chrgsInf", jsonArray);
Map<String, Object> chrgsInfMaps = new HashMap<>();
jsonArray.add(chrgsInfMaps);
Map<String, Object> amtMaps = new HashMap<>();
amtMaps.put("value", amt);
amtMaps.put("ccy", ccy);
chrgsInfMaps.put("amt", amtMaps);
Map<String, Object> agtMaps = new HashMap<>();
chrgsInfMaps.put("agt", agtMaps);
String receiverBic = (String) context.get(Mt2MxContextIdentifier.MT_RECEIVE_BIC, true);
mt_to_mxBICFI(receiverBic, agtMaps);
}
Tag[] tags = abstractMT.getSwiftMessage().getBlock4().getTagsByName(NAME_F);
if (tags != null && tags.length > 0) {
JSONArray jsonArray = new JSONArray();
txInfMaps.put("chrgsInf", jsonArray);
for (int i=0; i<tags.length; i++) {
Field71F field71F = (Field71F)tags[i].asField();
String ccy = field71F.getCurrency();
BigDecimal amt = field71F.amount();
Map<String, Object> chrgsInfMaps = new HashMap<>();
jsonArray.add(chrgsInfMaps);
Map<String, Object> amtMaps = new HashMap<>();
amtMaps.put("value", amt);
amtMaps.put("ccy", ccy);
chrgsInfMaps.put("amt", amtMaps);
Map<String, Object> agtMaps = new HashMap<>();
chrgsInfMaps.put("agt", agtMaps);
Map<String, Object> finInstnIdMaps = null;
if (agtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)agtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
agtMaps.put("finInstnId", finInstnIdMaps);
}
//name address 设置NOTPROVIDED
finInstnIdMaps.put("nm", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
Map<String, Object> pstlAdrMaps = null;
if (finInstnIdMaps.containsKey("pstlAdr")) {
pstlAdrMaps = (Map<String, Object>)finInstnIdMaps.get("pstlAdr");
} else {
pstlAdrMaps = new HashMap<>();
finInstnIdMaps.put("pstlAdr", pstlAdrMaps);
}
List<String> adrLineList = new ArrayList<>();
adrLineList.add(Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
pstlAdrMaps.put("adrLine", adrLineList);
}
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field72;
import com.prowidesoftware.swift.model.field.SwiftParseUtils;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.utils.SwiftFormatUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pacs004001Parse72Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "72";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
Field72 field72 = (Field72)tag.asField();
String mt72 = field72.getValue();
String[] mt72s = mt72.split(Mx2MtConstants.NEW_LINE);
String mRef = "";
String tRef = "";
String chgs = "";
for (String value : mt72s) {
if (value.startsWith("/MREF/")) {
mRef = value.substring(6);
}
if (value.startsWith("/TREF/")) {
tRef = value.substring(6);
}
if (value.startsWith("/CHGS/")) {
chgs = value.substring(6);
}
}
if (StringUtil.isNotEmpty(mRef)) {
txInfMaps.put("orgnlInstrId", mRef);
}
if (!"202".equals(abstractMT.getMessageType())
&& !"205".equals(abstractMT.getMessageType())) {
if (StringUtil.isNotEmpty(tRef)) {
txInfMaps.put("orgnlEndToEndId", tRef);
} else {
txInfMaps.put("orgnlEndToEndId", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
}
}
if (StringUtil.isNotEmpty(chgs)) {
Tag tag71G = abstractMT.getSwiftMessage().getBlock4().getTagByName("71G");
Tag[] tag71Fs = abstractMT.getSwiftMessage().getBlock4().getTagsByName("71F");
if (tag71G == null && tag71Fs.length == 0) {
String ccy = SwiftParseUtils.getAlphaPrefix(chgs);
String amtStr = SwiftParseUtils.getNumericSuffix(chgs);
Number number = SwiftFormatUtils.getNumber(amtStr);
BigDecimal amt = new BigDecimal(number.toString()).stripTrailingZeros();
JSONArray jsonArray = new JSONArray();
txInfMaps.put("chrgsInf", jsonArray);
Map<String, Object> chrgsInfMaps = new HashMap<>();
jsonArray.add(chrgsInfMaps);
Map<String, Object> amtMaps = new HashMap<>();
amtMaps.put("value", amt);
amtMaps.put("ccy", ccy);
chrgsInfMaps.put("amt", amtMaps);
Map<String, Object> agtMaps = new HashMap<>();
chrgsInfMaps.put("agt", agtMaps);
Map<String, Object> finInstnIdMaps = null;
if (agtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)agtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
agtMaps.put("finInstnId", finInstnIdMaps);
}
//name address 设置NOTPROVIDED
finInstnIdMaps.put("nm", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
Map<String, Object> pstlAdrMaps = null;
if (finInstnIdMaps.containsKey("pstlAdr")) {
pstlAdrMaps = (Map<String, Object>)finInstnIdMaps.get("pstlAdr");
} else {
pstlAdrMaps = new HashMap<>();
finInstnIdMaps.put("pstlAdr", pstlAdrMaps);
}
List<String> adrLineList = new ArrayList<>();
adrLineList.add(Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
pstlAdrMaps.put("adrLine", adrLineList);
}
}
mt_to_mxReturn72(mt72, txInfMaps);
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field77B;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Pacs004001Parse77BField extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "77B";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag != null) {
String creditorCountryCode = "";
String debtorCountryCode = "";
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>)txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Field77B field77B = (Field77B)tag.asField();
List<String> lines = field77B.getLines();
for (int i=0; i<lines.size();i++) {
String line = lines.get(i);
String regex = "/BENEFRES/([A-Z]{2})";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(line);
if (m.find()) {
creditorCountryCode = m.group(1);
break;
}
}
if (StringUtil.isNotEmpty(creditorCountryCode)) {
Map<String, Object> cdtrMaps = null;
if (rtrChainMaps.containsKey("cdtr")) {
cdtrMaps = (Map<String, Object>) rtrChainMaps.get("cdtr");
} else {
cdtrMaps = new HashMap<>();
rtrChainMaps.put("cdtr", cdtrMaps);
}
Map<String, Object> ptyMaps = null;
if (cdtrMaps.containsKey("pty")) {
ptyMaps = (Map<String, Object>) cdtrMaps.get("pty");
} else {
ptyMaps = new HashMap<>();
cdtrMaps.put("pty", ptyMaps);
}
ptyMaps.put("ctryOfRes", creditorCountryCode);
}
for (int i=0; i<lines.size();i++) {
String line = lines.get(i);
String regex = "/ORDERRES/([A-Z]{2})";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(line);
if (m.find()) {
debtorCountryCode = m.group(1);
break;
}
}
if (StringUtil.isNotEmpty(debtorCountryCode)) {
Map<String, Object> dbtrMaps = null;
if (rtrChainMaps.containsKey("dbtr")) {
dbtrMaps = (Map<String, Object>) rtrChainMaps.get("dbtr");
} else {
dbtrMaps = new HashMap<>();
rtrChainMaps.put("dbtr", dbtrMaps);
}
Map<String, Object> ptyMaps = null;
if (dbtrMaps.containsKey("pty")) {
ptyMaps = (Map<String, Object>) dbtrMaps.get("pty");
} else {
ptyMaps = new HashMap<>();
dbtrMaps.put("pty", ptyMaps);
}
ptyMaps.put("ctryOfRes", debtorCountryCode);
}
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.VoSettlementMethodHelper;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field53A;
import com.prowidesoftware.swift.model.field.Field53B;
import com.prowidesoftware.swift.model.field.Field53D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
/**
* Group Header -> Settlement Information -> Settlement Account
*/
public class Pacs004001ParseSetlAcctField extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "53A";
private static final String NAME_B = "53B";
private static final String NAME_D = "53D";
@Override
public void parseField() throws SwiftException {
//值来源于 Pacs00801ParseSetlMtdField
VoSettlementMethodHelper setlMtdHelper = context.get(VoSettlementMethodHelper.class);
if (setlMtdHelper.isTranslateSetlAcctFlag()) {
Field53A field53A = null;
Field53B field53B = null;
Field53D field53D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field53A = (Field53A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_B);
if (tag != null) {
field53B = (Field53B) tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field53D = (Field53D)tag.asField();
}
String account = "";
if (field53A != null) {
if (StringUtil.isNotEmpty(field53A.getComponent1())) {
account += "/" + field53A.getComponent1();
}
if (StringUtil.isNotEmpty(field53A.getComponent2())) {
account += "/" + field53A.getComponent2();
}
} else if (field53B != null) {
if (StringUtil.isNotEmpty(field53B.getComponent1())) {
account += "/" + field53B.getComponent1();
}
if (StringUtil.isNotEmpty(field53B.getComponent2())) {
account += "/" + field53B.getComponent2();
}
} else if (field53D != null) {
if (StringUtil.isNotEmpty(field53D.getComponent1())) {
account += "/" + field53D.getComponent1();
}
if (StringUtil.isNotEmpty(field53D.getComponent2())) {
account += "/" + field53D.getComponent2();
}
}
if (StringUtil.isEmpty(account)) return;
Map<String, Object> sttlmInfMaps = null;
if (grpHdrMaps.containsKey("sttlmInf")) {
sttlmInfMaps = (Map<String, Object>) grpHdrMaps.get("sttlmInf");
} else {
sttlmInfMaps = new HashMap<>();
grpHdrMaps.put("sttlmInf", sttlmInfMaps);
}
Map<String, Object> sttlmAcctMaps = null;
if (sttlmInfMaps.containsKey("sttlmAcct")) {
sttlmAcctMaps = (Map<String, Object>)sttlmInfMaps.get("sttlmAcct");
} else {
sttlmAcctMaps = new HashMap<>();
sttlmInfMaps.put("sttlmAcct", sttlmAcctMaps);
}
mt_to_mxFinancialInstitutionAccount(account, sttlmAcctMaps, "SttlmAcct/Id");
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt103retn;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.mt2mx.setlmtd.SettlementMethodAnalyzerFactory;
import com.brilliance.swift.vo.VoSettlementMethodHelper;
import java.util.HashMap;
import java.util.Map;
/**
* Group Header -> Settlement Information -> Settlement Method
*/
public class Pacs004001ParseSetlMtdField extends AbstractMt2MxPacs004001ParseField {
@Override
public void parseField() throws SwiftException {
context.set(Mt2MxContextIdentifier.MT_TO_MX_RETURN_FLAG, Mx2MtConstants.YES);
VoSettlementMethodHelper setlMtdHelper = SettlementMethodAnalyzerFactory.find(context).analyse();
String settlementMethod = setlMtdHelper.getSettlementMethod();
Map<String, Object> sttlmInfMaps = null;
if (grpHdrMaps.containsKey("sttlmInf")) {
sttlmInfMaps = (Map<String, Object>) grpHdrMaps.get("sttlmInf");
} else {
sttlmInfMaps = new HashMap<>();
grpHdrMaps.put("sttlmInf", sttlmInfMaps);
}
sttlmInfMaps.put("sttlmMtd", settlementMethod);
context.set(setlMtdHelper);
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt202retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
public class Pacs004001Parse21Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME = "21";
@Override
public void parseField() throws SwiftException {
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag21 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag21 != null) {
txInfMaps.put("orgnlEndToEndId", tag21.getValue());
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt202retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field52A;
import com.prowidesoftware.swift.model.field.Field52D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse52Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "52A";
private static final String NAME_D = "52D";
@Override
public void parseField() throws SwiftException {
Field52A field52A = null;
Field52D field52D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field52A = (Field52A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field52D = (Field52D)tag.asField();
}
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> dbtrMaps = null;
if (rtrChainMaps.containsKey("dbtr")) {
dbtrMaps = (Map<String, Object>) rtrChainMaps.get("dbtr");
} else {
dbtrMaps = new HashMap<>();
}
Map<String, Object> agtMaps = null;
if (dbtrMaps.containsKey("agt")) {
agtMaps = (Map<String, Object>) dbtrMaps.get("agt");
} else {
agtMaps = new HashMap<>();
}
String account = "";
if (field52A != null) {
String bicCode = field52A.getBIC();
mt_to_mxBICFI(bicCode, agtMaps);
if (StringUtil.isNotEmpty(field52A.getComponent1())) {
account += "/" + field52A.getComponent1();
}
if (StringUtil.isNotEmpty(field52A.getComponent2())) {
account += "/" + field52A.getComponent2();
}
} else if (field52D != null) {
if (StringUtil.isNotEmpty(field52D.getComponent1())) {
account += "/" + field52D.getComponent1();
}
if (StringUtil.isNotEmpty(field52D.getComponent2())) {
account += "/" + field52D.getComponent2();
}
String nameAddress = field52D.getNameAndAddress();
mt_to_mxFinancialInstitutionNameAndUnstructuredAddress(nameAddress, agtMaps);
} else {
String sendBic = (String) context.get(Mt2MxContextIdentifier.MT_SEND_BIC, true);
mt_to_mxBICFI(sendBic, agtMaps);
}
if (StringUtil.isNotEmpty(account)) {
if (account.startsWith("//") && !account.startsWith("//CH") && !account.startsWith("//FW")) {
Map<String, Object> finInstnIdMaps = null;
if (agtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)agtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
agtMaps.put("finInstnId", finInstnIdMaps);
}
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
}
}
if (agtMaps.size() > 0) {
dbtrMaps.put("agt", agtMaps);
}
if (dbtrMaps.size() > 0) {
rtrChainMaps.put("dbtr", dbtrMaps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
}
package com.brilliance.swift.mt2mx.pacs004001.mt202retn;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.pacs004001.AbstractMt2MxPacs004001ParseField;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field58A;
import com.prowidesoftware.swift.model.field.Field58D;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs004001Parse58Field extends AbstractMt2MxPacs004001ParseField {
private static final String NAME_A = "58A";
private static final String NAME_D = "58D";
@Override
public void parseField() throws SwiftException {
Field58A field58A = null;
Field58D field58D = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_A);
if (tag != null) {
field58A = (Field58A)tag.asField();
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME_D);
if (tag != null) {
field58D = (Field58D)tag.asField();
}
Map<String, Object> rtrChainMaps = null;
if (txInfMaps.containsKey("rtrChain")) {
rtrChainMaps = (Map<String, Object>) txInfMaps.get("rtrChain");
} else {
rtrChainMaps = new HashMap<>();
}
Map<String, Object> cdtrMaps = null;
if (rtrChainMaps.containsKey("cdtr")) {
cdtrMaps = (Map<String, Object>) rtrChainMaps.get("cdtr");
} else {
cdtrMaps = new HashMap<>();
}
Map<String, Object> agtMaps = null;
if (cdtrMaps.containsKey("agt")) {
agtMaps = (Map<String, Object>) cdtrMaps.get("agt");
} else {
agtMaps = new HashMap<>();
}
String account = "";
if (field58A != null) {
String bicCode = field58A.getBIC();
mt_to_mxBICFI(bicCode, agtMaps);
if (StringUtil.isNotEmpty(field58A.getComponent1())) {
account += "/" + field58A.getComponent1();
}
if (StringUtil.isNotEmpty(field58A.getComponent2())) {
account += "/" + field58A.getComponent2();
}
} else if (field58D != null) {
if (StringUtil.isNotEmpty(field58D.getComponent1())) {
account += "/" + field58D.getComponent1();
}
if (StringUtil.isNotEmpty(field58D.getComponent2())) {
account += "/" + field58D.getComponent2();
}
String nameAddress = field58D.getNameAndAddress();
mt_to_mxFinancialInstitutionNameAndUnstructuredAddress(nameAddress, agtMaps);
}
if (StringUtil.isNotEmpty(account)) {
if (account.startsWith("//") && !account.startsWith("//CH") && !account.startsWith("//FW")) {
Map<String, Object> finInstnIdMaps = null;
if (agtMaps.containsKey("finInstnId")) {
finInstnIdMaps = (Map<String, Object>)agtMaps.get("finInstnId");
} else {
finInstnIdMaps = new HashMap<>();
agtMaps.put("finInstnId", finInstnIdMaps);
}
Map<String, Object> clrSysMmbIdMaps = null;
if (finInstnIdMaps.containsKey("clrSysMmbId")) {
clrSysMmbIdMaps = (Map<String, Object>)finInstnIdMaps.get("clrSysMmbId");
} else {
clrSysMmbIdMaps = new HashMap<>();
finInstnIdMaps.put("clrSysMmbId", clrSysMmbIdMaps);
}
mt_to_mxClearingIdentifier(account, clrSysMmbIdMaps);
}
}
if (agtMaps.size() > 0) {
cdtrMaps.put("agt", agtMaps);
}
if (cdtrMaps.size() > 0) {
rtrChainMaps.put("cdtr", cdtrMaps);
}
if (rtrChainMaps.size() > 0) {
txInfMaps.put("rtrChain", rtrChainMaps);
}
}
}
......@@ -64,7 +64,7 @@ public class Pacs00801Parse71Field extends AbstractMt2MxPacs008001ParseField {
mt_to_mxBICFI(receiverBic, agtMaps);
}
Tag[] tags = abstractMT.getSwiftMessage().getBlock4().getTagsByName(NAME_F);
if (tag != null && tags.length > 0) {
if (tags != null && tags.length > 0) {
JSONArray jsonArray = new JSONArray();
cdtTrfTxInfMaps.put("chrgsInf", jsonArray);
for (int i=0; i<tags.length; i++) {
......
......@@ -29,6 +29,8 @@ public abstract class AbstractSettlementMethodAnalyzer implements SettlementMeth
protected Field field54;
protected String returnFlag;
public Field getField53() {
return field53;
}
......@@ -47,6 +49,15 @@ public abstract class AbstractSettlementMethodAnalyzer implements SettlementMeth
return this;
}
public String getReturnFlag() {
return returnFlag;
}
public AbstractSettlementMethodAnalyzer setReturnFlag(String returnFlag) {
this.returnFlag = returnFlag;
return this;
}
/**
* 封装报文转换详细报告
* @param errorCode
......
package com.brilliance.swift.mt2mx.setlmtd;
import com.brilliance.swift.mt2mx.Mt2MxContext;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.setlmtd.impl.*;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.*;
......@@ -41,6 +42,7 @@ public class SettlementMethodAnalyzerFactory {
if (tag != null) {
field54D = (Field54D)tag.asField();
}
String returnFlag = (String) context.get(Mt2MxContextIdentifier.MT_TO_MX_RETURN_FLAG, true);
boolean noneField53 = false;
if (field53A == null && field53B == null && field53D == null) {
noneField53 = true;
......@@ -50,59 +52,71 @@ public class SettlementMethodAnalyzerFactory {
noneField54 = true;
}
if (noneField53 && noneField54) {
analyzer = new FieldNone5354Analyzer().setContext(context);
analyzer = new FieldNone5354Analyzer().setContext(context).setReturnFlag(returnFlag);
} else if (field53A != null && noneField54) {
analyzer = new FieldOnly53AAnalyzer()
.setContext(context)
.setField53(field53A);
.setField53(field53A)
.setReturnFlag(returnFlag);
} else if (field53B != null && noneField54) {
analyzer = new FieldOnly53BAnalyzer()
.setContext(context)
.setField53(field53B);
.setField53(field53B)
.setReturnFlag(returnFlag);
} else if (field53D != null && noneField54) {
analyzer = new FieldOnly53DAnalyzer()
.setContext(context)
.setField53(field53D);
.setField53(field53D)
.setReturnFlag(returnFlag);
} else if (noneField53 && field54A != null) {
analyzer = new FieldOnly54AAnalyzer()
.setContext(context)
.setField54(field54A);
.setField54(field54A)
.setReturnFlag(returnFlag);
} else if (noneField53 && field54B != null) {
analyzer = new FieldOnly54BAnalyzer()
.setContext(context)
.setField54(field54B);
.setField54(field54B)
.setReturnFlag(returnFlag);
} else if (noneField53 && field54D != null) {
analyzer = new FieldOnly54DAnalyzer()
.setContext(context)
.setField54(field54D);
.setField54(field54D)
.setReturnFlag(returnFlag);
} else if (field53A != null && field54A != null) {
analyzer = new Field53A54AAnalyzer()
.setContext(context)
.setField53(field53A)
.setField54(field54A);
.setField54(field54A)
.setReturnFlag(returnFlag);
} else if (field53A != null && field54B != null) {
analyzer = new Field53A54BAnalyzer()
.setContext(context)
.setField53(field53A)
.setField54(field54B);
.setField54(field54B)
.setReturnFlag(returnFlag);
} else if (field53A != null && field54D != null) {
analyzer = new Field53A54DAnalyzer()
.setContext(context)
.setField53(field53A)
.setField54(field54D);
.setField54(field54D)
.setReturnFlag(returnFlag);
} else if (field53B != null && field54A != null) {
analyzer = new Field53B54aAnalyzer()
.setContext(context)
.setField53(field53B)
.setField54(field54A);
.setField54(field54A)
.setReturnFlag(returnFlag);
} else if (field53B != null && !noneField54) {
analyzer = new Field53B54aAnalyzer()
.setContext(context)
.setField53(field53B);
.setField53(field53B)
.setReturnFlag(returnFlag);
} else if (field53D != null && !noneField54) {
analyzer = new Field53D54aAnalyzer()
.setContext(context)
.setField53(field53D);
.setField53(field53D)
.setReturnFlag(returnFlag);
}
return analyzer;
}
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.util.StringUtil;
......@@ -56,7 +57,7 @@ public class Field53A54AAnalyzer extends AbstractSettlementMethodAnalyzer {
}
} else {
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20024, "Block4/:53A:", null);
buildSTErrorInfo(ERROR.T20023, "Block4/:54A:", null);
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.util.StringUtil;
......@@ -39,7 +40,7 @@ public class Field53A54BAnalyzer extends AbstractSettlementMethodAnalyzer {
}
} else {
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20024, "Block4/:53A:", null);
buildSTErrorInfo(ERROR.T20023, "Block4/:54B:", null);
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.util.StringUtil;
......@@ -39,7 +40,7 @@ public class Field53A54DAnalyzer extends AbstractSettlementMethodAnalyzer {
}
} else {
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20024, "Block4/:53A:", null);
buildSTErrorInfo(ERROR.T20023, "Block4/:54D:", null);
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
......@@ -34,7 +35,7 @@ public class Field53D54aAnalyzer extends AbstractSettlementMethodAnalyzer {
}
} else {
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20024, "Block4/:53D:", null);
buildSTErrorInfo(ERROR.T20023, "Block4/:54a:", null);
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.util.StringUtil;
......@@ -29,22 +30,30 @@ public class FieldOnly53AAnalyzer extends AbstractSettlementMethodAnalyzer {
seltMtdHelper.setSettlementMethod("INDA");
}
seltMtdHelper.setTranslateSetlAcctFlag(true);
seltMtdHelper.setInstructionForNextAgent("/FIN53/"+bicCode);
buildSTErrorInfo(ERROR.T20021, "Block4/:53A:", null);
if (Mx2MtConstants.YES.equals(returnFlag)) {
buildSTErrorInfo(ERROR.T22006, "Block4/:53A:", null);
} else {
seltMtdHelper.setInstructionForNextAgent("/FIN53/"+bicCode);
buildSTErrorInfo(ERROR.T20021, "Block4/:53A:", null);
}
} else {
String sendBic = (String) context.get(Mt2MxContextIdentifier.MT_SEND_BIC, true);
String receiveBic = (String) context.get(Mt2MxContextIdentifier.MT_RECEIVE_BIC, true);
if ((StringUtil.isNotEmpty(sendBic) && bicCode.substring(0, 6).equals(sendBic.substring(0, 6)))
|| (StringUtil.isNotEmpty(receiveBic) && bicCode.substring(0, 6).equals(receiveBic.substring(0, 6)))) {
seltMtdHelper.setSettlementMethod("INDA");
seltMtdHelper.setInstructionForNextAgent("/FIN53/"+bicCode);
buildSTErrorInfo(ERROR.T20021, "Block4/:53A:", null);
if (Mx2MtConstants.YES.equals(returnFlag)) {
buildSTErrorInfo(ERROR.T22006, "Block4/:53A:", null);
} else {
seltMtdHelper.setInstructionForNextAgent("/FIN53/"+bicCode);
buildSTErrorInfo(ERROR.T20021, "Block4/:53A:", null);
}
if (StringUtil.isNotEmpty(account)) {
buildSTErrorInfo(ERROR.T20068, "Block4/:53A:", null);
}
} else {
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20024, "Block4/:53A:", null);
} else {
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.Mt2MxContextIdentifier;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.util.StringUtil;
......@@ -22,7 +23,7 @@ public class FieldOnly54AAnalyzer extends AbstractSettlementMethodAnalyzer {
buildSTErrorInfo(ERROR.T20010, "Block4/:54A:", null);
} else {
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20023, "Block4/:54A:", null);
} else {
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.vo.VoSettlementMethodHelper;
import com.prowidesoftware.swift.model.mt.AbstractMT;
......@@ -10,7 +11,7 @@ public class FieldOnly54BAnalyzer extends AbstractSettlementMethodAnalyzer {
public VoSettlementMethodHelper analyse() {
VoSettlementMethodHelper seltMtdHelper = new VoSettlementMethodHelper();
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20023, "Block4/:54B:", null);
} else {
......
package com.brilliance.swift.mt2mx.setlmtd.impl;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.setlmtd.AbstractSettlementMethodAnalyzer;
import com.brilliance.swift.vo.VoSettlementMethodHelper;
import com.prowidesoftware.swift.model.mt.AbstractMT;
......@@ -10,7 +11,7 @@ public class FieldOnly54DAnalyzer extends AbstractSettlementMethodAnalyzer {
public VoSettlementMethodHelper analyse() {
VoSettlementMethodHelper seltMtdHelper = new VoSettlementMethodHelper();
AbstractMT abstractMT = context.get(AbstractMT.class);
if (abstractMT.getSwiftMessage().isCOV()) {
if (abstractMT.getSwiftMessage().isCOV() || Mx2MtConstants.YES.equals(returnFlag)) {
seltMtdHelper.setSettlementMethod("INDA");
buildSTErrorInfo(ERROR.T20023, "Block4/:54D:", null);
} else {
......
......@@ -7,13 +7,9 @@ import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.mx.AbstractMX;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -53,26 +49,6 @@ public abstract class AbstractMx2ElementCreator implements Mx2ElementCreator{
}
}
public List<String> convertToLines(InputStream is) {
BufferedReader bReader = new BufferedReader(new InputStreamReader(is));
List<String> list = new ArrayList<>();
String line = null;
try {
while((line = bReader.readLine())!=null){
list.add(line);
}
} catch (IOException e) {
throw new SwiftException(e.getMessage());
} finally {
try {
bReader.close();
} catch (IOException e) {
throw new SwiftException(e.getMessage());
}
}
return list;
}
@Override
public Map<String, Object> buildElement() {
//AbstractMX abstractMX = AbstractMX.parse(xmlStr);
......
......@@ -710,6 +710,21 @@ public class SwiftTransferUtil {
}
/**
* 根据mxcode取ReturnReasonCode
*/
public static ReturnReasonCode getReturnReasonCodeByCode(String mxCode) {
ReturnReasonCode code = null;
ReturnReasonCode[] values = ReturnReasonCode.values();
for (ReturnReasonCode tmpCode : values) {
if (tmpCode.value().equals(mxCode)) {
code = tmpCode;
break;
}
}
return code;
}
/**
* 根据ErrorCodesRETNREJT.xlsx文件返回
* List<MxMtReasonCodeInfo>
*/
......
......@@ -121,6 +121,7 @@ Change Log
<Purp>
<Cd>COMC</Cd>
</Purp>
<AddtlTxInf>Charge to an account</AddtlTxInf>
</TxDtls>
</NtryDtls>
</Ntry>
......
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