Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2025 Prowide Inc.
* All rights reserved. This program and the accompanying materials are made available under the terms of private
* license agreements between Prowide Inc. and its commercial customers and partners.
*/

package com.prowidesoftware.swift.samples.integrator.myformat;

import com.prowidesoftware.swift.myformat.FileFormat;
import com.prowidesoftware.swift.myformat.MappingTable;
import com.prowidesoftware.swift.myformat.MappingTableExcelLoader;
import com.prowidesoftware.swift.myformat.MyFormatEngine;

import java.io.IOException;
import java.util.Objects;

/**
* Test creating an MT from a simple JSON.
*/
class Json2MtExample1 {

public static void main(String[] args) throws IOException {
final String jsonInput = "{" + " 'Document': {"
+ " 'GnlInf': {"
+ " 'SndrMsgRef': 12345,"
+ " 'FuncOfMsg': 'NEWM',"
+ " 'CreDtTm': {"
+ " 'DtTm': '2015-08-27T08:59:00'"
+ " }"
+ " },"
+ " 'PmtInf': {"
+ " 'PmtRef': {"
+ " 'PmtId': 20150827000000"
+ " },"
+ " 'DbtrDtls': {"
+ " 'MmbId': 99,"
+ " 'PngAgt': {"
+ " 'CshAcct': '12345-67890-12345',"
+ " 'BIC': 'FOOOUSPAXXX'"
+ " }"
+ " },"
+ " 'CdtrDtls': {"
+ " 'MmbId': 123,"
+ " 'PngAgt': {"
+ " 'BIC': 'FOOPUSPW'"
+ " }"
+ " },"
+ " 'PmtDtls': {"
+ " 'SttlmDt': '2015-08-27',"
+ " 'StsCd': 21,"
+ " 'CshTxTp': 19,"
+ " 'SttlmAmt': 1234.56,"
+ " 'Ccy': 'USD',"
+ " 'AddnlInf': 'FOO text ZYX8764'"
+ " }"
+ " }"
+ " }"
+ "}";


MappingTableExcelLoader loader = new MappingTableExcelLoader(Objects.requireNonNull(Json2MtExample1.class.getResourceAsStream("/myformat/json2mt.xls")));
MappingTable table = loader.load("SIMPLE", FileFormat.JSON, FileFormat.MT);
final String mt = MyFormatEngine.translate(jsonInput, table);
System.out.println(mt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2025 Prowide Inc.
* All rights reserved. This program and the accompanying materials are made available under the terms of private
* license agreements between Prowide Inc. and its commercial customers and partners.
*/

package com.prowidesoftware.swift.samples.integrator.myformat;

import com.prowidesoftware.swift.myformat.FileFormat;
import com.prowidesoftware.swift.myformat.MappingTable;
import com.prowidesoftware.swift.myformat.MappingTableExcelLoader;
import com.prowidesoftware.swift.myformat.MyFormatEngine;

import java.io.IOException;
import java.util.Objects;

/**
* Test creating an MT from a JSON source with an array of elements.
*/
class Json2MtExample2 {

public static void main(String[] args) throws IOException {
String jsonInput = "{" + " 'type': 'MT',"
+ " 'basicHeaderBlock': {"
+ " 'applicationId': 'F',"
+ " 'serviceId': '01',"
+ " 'logicalTerminal': 'FOOTHKHHAXXX',"
+ " 'sessionNumber': '0000',"
+ " 'sequenceNumber': '000000'"
+ " },"
+ " 'applicationHeaderBlock': {"
+ " 'receiverAddress': 'EXMTHKHHXXXX',"
+ " 'senderInputTime': null,"
+ " 'MIRDate': null,"
+ " 'MIRLogicalTerminal': null,"
+ " 'MIRSessionNumber': null,"
+ " 'MIRSequenceNumber': null,"
+ " 'receiverOutputDate': null,"
+ " 'receiverOutputTime': null,"
+ " 'messagePriority': 'N',"
+ " 'messageType': '202',"
+ " 'direction': 'I'"
+ " },"
+ " 'textBlock': {"
+ " 'fields': ["
+ " {"
+ " 'name': '20',"
+ " 'reference': 'TEST2021234'"
+ " },"
+ " {"
+ " 'name': '21',"
+ " 'reference': 'TEST202123233'"
+ " },"
+ " {"
+ " 'name': '32A',"
+ " 'date': '230131',"
+ " 'currency': 'USD',"
+ " 'amount': '7878778,'"
+ " },"
+ " {"
+ " 'name': '58A',"
+ " 'account': '898989',"
+ " 'bIC': 'EXMTHKHH'"
+ " },"
+ " {"
+ " 'name': '72',"
+ " 'narrative': ' /INS/PURPOSE CODE 1670',"
+ " 'narrative2': '//SERVICES, SELF COMPANY FUNDING'"
+ " }"
+ " ]"
+ " }"
+ "}";

MappingTableExcelLoader loader = new MappingTableExcelLoader(Objects.requireNonNull(Json2MtExample2.class.getResourceAsStream("/myformat/json2mt.xls")));
MappingTable table = loader.load("INDEX", FileFormat.JSON, FileFormat.MT);
final String mt = MyFormatEngine.translate(jsonInput, table);
System.out.println(mt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2025 Prowide Inc.
* All rights reserved. This program and the accompanying materials are made available under the terms of private
* license agreements between Prowide Inc. and its commercial customers and partners.
*/

package com.prowidesoftware.swift.samples.integrator.myformat;

import com.prowidesoftware.swift.model.mt.mt5xx.MT540;
import com.prowidesoftware.swift.myformat.FileFormat;
import com.prowidesoftware.swift.myformat.MappingTable;
import com.prowidesoftware.swift.myformat.MappingTableExcelLoader;
import com.prowidesoftware.swift.myformat.MyFormatEngine;
import com.prowidesoftware.swift.myformat.json.JsonReader;
import com.prowidesoftware.swift.myformat.mt.MtWriter;

import java.io.IOException;
import java.util.Objects;

/**
* Each "party" element should generate an instance of sequence E.
* Either attribute "type" or "price" in the "party" element should generate a field 95Q in the corresponding
* sequence E, the attribute value goes to component 1 in the field.
* The "id" attribute in the party element must be mapped to component 2 in the corresponding 95Q field instance.
*/
class Json2MtExample3 {

public static void main(String[] args) throws IOException {
String jsonInput = "{ 'riskPledgeAllocation': {" + " 'taskId': 1111,"
+ " 'bussinessDate': '2019-01-03',"
+ " 'strategyId': 'XXXXXXX',"
+ " 'fundId': 'XXXXX',"
+ " 'sscSecId': 999999,"
+ " 'assetType': 'EQUITY',"
+ " 'settlementLoc': 'AAA',"
+ " 'allocatedQty': 0,"
+ " 'availableQty': 9999,"
+ " 'memoPledgeQty': 0,"
+ " 'allocatedMarketVal': 0,"
+ " 'calculatedDelta': 99,"
+ " 'eligibilityFlag': false,"
+ " 'price': 99,"
+ " 'priceCcy': 'USD',"
+ " 'lastModifiedBy': 'XXXXX',"
+ " 'pricingBasis': 1,"
+ " 'parties': {"
+ " 'party': ["
+ " {"
+ " 'id': 'AA',"
+ " 'type': 'SELLER'"
+ " },"
+ " {"
+ " 'id': 'BB',"
+ " 'type': 'BUYER'"
+ " }"
+ " ]"
+ " }"
+ " }"
+ "}";


MappingTableExcelLoader loader = new MappingTableExcelLoader(Objects.requireNonNull(Json2MtExample2.class.getResourceAsStream("/myformat/json2mt.xls")));
MappingTable t = loader.load("SEQUENCE", FileFormat.JSON, FileFormat.MT);
assert (t.validate().isEmpty());

MtWriter writer = new MtWriter(new MT540());
MyFormatEngine.translate(new JsonReader(jsonInput), writer, t.getRules());

MT540 mt = (MT540) writer.mt();

System.out.println(mt.message());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2025 Prowide Inc.
* All rights reserved. This program and the accompanying materials are made available under the terms of private
* license agreements between Prowide Inc. and its commercial customers and partners.
*/

package com.prowidesoftware.swift.samples.integrator.myformat;

import com.prowidesoftware.swift.model.mt.mt5xx.MT535;
import com.prowidesoftware.swift.myformat.FileFormat;
import com.prowidesoftware.swift.myformat.MappingTable;
import com.prowidesoftware.swift.myformat.MappingTableExcelLoader;
import com.prowidesoftware.swift.myformat.MyFormatEngine;
import com.prowidesoftware.swift.myformat.json.JsonReader;
import com.prowidesoftware.swift.myformat.mt.MtWriter;

import java.io.IOException;
import java.util.Objects;

/**
* Complex test creating real MT535 nested sequences from several foreach.
*/
class Json2MtExample4 {

public static void main(String[] args) throws IOException {
String jsonInput = "{" + " 'M': {"
+ " 'B': ["
+ " {"
+ " 'T95P': 'F1F1//ABCDARXXXXX',"
+ " 'T97A': 'F2F2//1',"
+ " 'B1': {"
+ " 'T35B': 'F3',"
+ " 'B1b': ["
+ " {"
+ " 'T22F': 'F4F4//1',"
+ " 'T94B': 'F5F5//1'"
+ " },"
+ " {"
+ " 'T22F': 'F4F4//2',"
+ " 'T94B': 'F5F5//2'"
+ " }"
+ " ],"
+ " 'T99A': 'F6F6//103',"
+ " 'B1c': {"
+ " 'T13B': 'F7F7//1',"
+ " 'T90A': 'F8F8//F8F/1,'"
+ " }"
+ " }"
+ " },"
+ " {"
+ " 'T97A': 'F2F2//2',"
+ " 'B1': {"
+ " 'B1c': ["
+ " {"
+ " 'T13B': 'F7F7//2',"
+ " 'T90A': 'F8F8//F8F/2,'"
+ " },"
+ " {"
+ " 'T13B': 'F7F7//3',"
+ " 'T90A': 'F8F8//F8F/3,'"
+ " }"
+ " ]"
+ " }"
+ " }"
+ " ]"
+ " }"
+ "}";

System.out.println(jsonInput);

MappingTableExcelLoader loader = new MappingTableExcelLoader(Objects.requireNonNull(Json2MtExample2.class.getResourceAsStream("/myformat/json2mt.xls")));
MappingTable t = loader.load("REP_SEQ", FileFormat.JSON, FileFormat.MT);
assert (t.validate().isEmpty());

MtWriter writer = new MtWriter(new MT535());
MyFormatEngine.translate(new JsonReader(jsonInput), writer, t.getRules());

MT535 mt = (MT535) writer.mt();
System.out.println(mt.message());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2025 Prowide Inc.
* All rights reserved. This program and the accompanying materials are made available under the terms of private
* license agreements between Prowide Inc. and its commercial customers and partners.
*/

package com.prowidesoftware.swift.samples.integrator.myformat;

import com.prowidesoftware.swift.model.mx.MxPain00100103;
import com.prowidesoftware.swift.myformat.MappingTable;
import com.prowidesoftware.swift.myformat.MappingTableExcelLoader;
import com.prowidesoftware.swift.myformat.MyFormatEngine;

import java.util.Objects;

class Json2MxExample1 {

public static void main(String[] args) {

String json = "{" + " 'root': {"
+ " 'GRP_HDR': {"
+ " 'CUSTREF': 'FILEREF123',"
+ " 'NO_OF_PAYMENTS': 4,"
+ " 'TOTAL_AMOUNT': 100"
+ " },"
+ " 'PAYMENT': ["
+ " {"
+ " 'VALUE_DATE': '2019-03-11',"
+ " 'TRANSFER_CCY_CODE': 'USD',"
+ " 'TRANSFER_AMOUNT': 30,"
+ " 'CREDIT': ["
+ " {"
+ " 'DBTR_BANK_ACC_NUM': 5948198,"
+ " 'CDTR_REF_NUM': 71237456,"
+ " 'CDTR_NAME': 'Venkat'"
+ " },"
+ " {"
+ " 'DBTR_BANK_ACC_NUM': 5948199,"
+ " 'CDTR_REF_NUM': 71237457,"
+ " 'CDTR_NAME': 'Gourab'"
+ " }"
+ " ]"
+ " },"
+ " {"
+ " 'VALUE_DATE': '2019-03-11',"
+ " 'TRANSFER_CCY_CODE': 'KWD',"
+ " 'TRANSFER_AMOUNT': 20,"
+ " 'CREDIT': ["
+ " {"
+ " 'DBTR_BANK_ACC_NUM': 5948198,"
+ " 'CDTR_REF_NUM': 71237456,"
+ " 'CDTR_NAME': 'Venkat'"
+ " },"
+ " {"
+ " 'DBTR_BANK_ACC_NUM': 5948199,"
+ " 'CDTR_REF_NUM': 71237457,"
+ " 'CDTR_NAME': 'Gourab'"
+ " }"
+ " ]"
+ " }"
+ " ]"
+ " }"
+ "}";

MappingTableExcelLoader loader = new MappingTableExcelLoader(Objects.requireNonNull(Json2MxExample1.class.getResourceAsStream("/myformat/json2mx.xls")));
MappingTable table = loader.load("SIMPLE");
String out = MyFormatEngine.translate(json, table);
MxPain00100103 mx = MxPain00100103.parse(out);
System.out.println(mx.message());
}

}
Loading