Commit 110a897e by gechengyang

提交JsonMxConvertTest测试类

parent 88a48653
...@@ -10,9 +10,8 @@ import com.brilliance.swift.mx2mt.Mx2MtCreatorManager; ...@@ -10,9 +10,8 @@ import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import com.brilliance.swift.util.*; import com.brilliance.swift.util.*;
import com.brilliance.swift.vo.SwiftTranslationReport; import com.brilliance.swift.vo.SwiftTranslationReport;
import com.prowidesoftware.swift.model.MxId; import com.prowidesoftware.swift.model.MxId;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mx.AbstractMX; import com.prowidesoftware.swift.model.mx.AbstractMX;
import com.prowidesoftware.swift.model.mx.AppHdr;
import com.prowidesoftware.swift.model.mx.BusinessAppHdrV02;
import com.prowidesoftware.swift.model.mx.NamespaceReader; import com.prowidesoftware.swift.model.mx.NamespaceReader;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.dom4j.Document; import org.dom4j.Document;
...@@ -428,4 +427,26 @@ public class SwiftTransfer { ...@@ -428,4 +427,26 @@ public class SwiftTransfer {
return fetchFinFromMixMessage(mixFilePath); return fetchFinFromMixMessage(mixFilePath);
} }
} }
public static String json2Mx(String isoJson){
AbstractMX abstractMX=AbstractMX.fromJson(isoJson);
if(abstractMX!=null)
return abstractMX.message();
return null;
}
public static String mx2Json(String isoXml){
AbstractMX abstractMX = AbstractMX.parse(isoXml);
if(abstractMX!=null)
return abstractMX.toJson();
return null;
}
public static AbstractMT getMt(String mtStr) throws IOException {
AbstractMT abstractMT = AbstractMT.parse(mtStr);
//MT103 mt103= (MT103) abstractMT;
return abstractMT;
}
} }
...@@ -21,6 +21,8 @@ public class DateUtil { ...@@ -21,6 +21,8 @@ public class DateUtil {
public static String defaultFormate = "yyyy-MM-dd HH:mm:ss,SSS"; // 默认的日期格式 public static String defaultFormate = "yyyy-MM-dd HH:mm:ss,SSS"; // 默认的日期格式
public static String defaultISOFormate="yyyy-MM-dd HH:mm:ss";
/*** /***
* @param paramDate * @param paramDate
* 日期 * 日期
...@@ -199,6 +201,17 @@ public class DateUtil { ...@@ -199,6 +201,17 @@ public class DateUtil {
return xgc; return xgc;
} }
public static String date2XMLGregorianCalendarStr(String date) throws ParseException, DatatypeConfigurationException {
return date2XMLGregorianCalendarStr(date,defaultISOFormate);
}
public static String date2XMLGregorianCalendarStr(String date,String format) throws ParseException, DatatypeConfigurationException {
if(StringUtil.isEmpty(format))
format=defaultISOFormate;
String xmlGregorianCalendarStr = DateUtil.parseXMLGregorianCalendar(DateUtil.parseDate(date, format)).toXMLFormat();
return xmlGregorianCalendarStr;
}
public static XMLGregorianCalendar parseXMLGregorianCalendarOfUTC(Date date) throws ParseException, DatatypeConfigurationException { public static XMLGregorianCalendar parseXMLGregorianCalendarOfUTC(Date date) throws ParseException, DatatypeConfigurationException {
GregorianCalendar gc = new GregorianCalendar(); GregorianCalendar gc = new GregorianCalendar();
// 获取当前默认时区 // 获取当前默认时区
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
> >
<Doc:xsys.011.001.01> <Doc:xsys.011.001.01>
<Doc:DlvryNtfctn> <Doc:DlvryNtfctn>
<Sw:OrigSnFRef>REF00001</Sw:OrigSnFRef>
<Sw:SnFRef>swi00001-2010-05-04T15:31:37.22284.11144096Z</Sw:SnFRef> <Sw:SnFRef>swi00001-2010-05-04T15:31:37.22284.11144096Z</Sw:SnFRef>
<Sw:SnFRefType>InterAct</Sw:SnFRefType> <Sw:SnFRefType>InterAct</Sw:SnFRefType>
<Sw:AcceptStatus>Accepted</Sw:AcceptStatus> <Sw:AcceptStatus>Accepted</Sw:AcceptStatus>
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
> >
<Doc:xsys.012.001.01> <Doc:xsys.012.001.01>
<Doc:DlvryNtfctn> <Doc:DlvryNtfctn>
<Sw:OrigSnFRef>REF00001</Sw:OrigSnFRef>
<Sw:SnFRef>swi00001-2010-05-04T15:32:59.21582.11198379Z</Sw:SnFRef> <Sw:SnFRef>swi00001-2010-05-04T15:32:59.21582.11198379Z</Sw:SnFRef>
<Sw:SnFRefType>InterAct</Sw:SnFRefType> <Sw:SnFRefType>InterAct</Sw:SnFRefType>
<Sw:AcceptStatus>Failed</Sw:AcceptStatus> <Sw:AcceptStatus>Failed</Sw:AcceptStatus>
......
package com.brilliance;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.util.DateUtil;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import com.prowidesoftware.swift.model.mt1xx.MT103;
import com.prowidesoftware.swift.model.mt1xx.MT103_STP;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import javax.xml.datatype.DatatypeConfigurationException;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class JsonMxConvertTest {
@Test
public void json2MxTest() throws IOException {
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/mxjson/JSONpacs00800108.json"));
String isoXml = SwiftTransfer.json2Mx(FileUtils.readFileToString(file, "UTF-8"));
System.out.println(isoXml);
}
@Test
public void mx2JsonTest() throws IOException {
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/mxjson/Pacs00800108.xml"));
String isoJson = SwiftTransfer.mx2Json(FileUtils.readFileToString(file, "UTF-8"));
System.out.println(isoJson);
}
@Test
public void dateFormatTest() throws DatatypeConfigurationException, ParseException {
String date="2023-12-10 20:10:11";
String isoDateTime = DateUtil.date2XMLGregorianCalendarStr(date);
System.out.println(isoDateTime);
}
@Test
public void testDate(){
TimeZone timezone = TimeZone.getTimeZone("UTC");
//"Z" indicates UTC, which means no timezone offset
//2024-01-03T07:06:36.496+08:00
//标准的ISO 8601日期格式 yyyy-MM-ddThh:mm:ss.sss+/-hh:mm
// 发报时,采用东八区时间,样例如2024-01-03T07:06:36.496+08:00
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
dateFormat.setTimeZone(timezone);
String ISODate = dateFormat.format(new Date());
System.out.println(ISODate+"+08:00");
}
@Test
public void testMt() throws IOException {
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftTxt/MT103.txt"));
String mtStr =FileUtils.readFileToString(file, "UTF-8");
AbstractMT abstractMT = AbstractMT.parse(mtStr);
if(abstractMT!=null)
{
String mtType=abstractMT.getMessageType();
if("103".equals(mtType))
{
if(abstractMT.getSwiftMessage().getBlock3().isSTP()) {
MT103_STP mt103Stp= (MT103_STP) abstractMT;
System.out.println("this is mt103_stp");
System.out.println(mt103Stp.message());
}else {
MT103 mt103= (MT103) abstractMT;
System.out.println("this is mt103");
System.out.println(mt103.message());
}
}
}
}
}
...@@ -15,6 +15,7 @@ import java.util.Map; ...@@ -15,6 +15,7 @@ import java.util.Map;
*/ */
public class Mx2MapTest { public class Mx2MapTest {
/** /**
* 如果origSnFRef=xsys01100101.dlvryNtfctn.origSnFRef不为空则origSnFRef,否则snFRef=xsys01100101.dlvryNtfctn.snFRef
* ack报文 * ack报文
* *
* @throws IOException * @throws IOException
...@@ -28,7 +29,8 @@ public class Mx2MapTest { ...@@ -28,7 +29,8 @@ public class Mx2MapTest {
} }
/** /**
* nck报文 *如果origSnFRef=xsys01100101.dlvryNtfctn.origSnFRef不为空则origSnFRef,否则snFRef=xsys01100101.dlvryNtfctn.snFRef
* nck报文
* *
* @throws IOException * @throws IOException
*/ */
......
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