-
Notifications
You must be signed in to change notification settings - Fork 0
/
TranslateMtToMx.java
146 lines (134 loc) · 6.58 KB
/
TranslateMtToMx.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.paymentcomponents.converter.iso20022.demo;
import gr.datamation.converter.common.exceptions.InvalidMtMessageException;
import gr.datamation.converter.common.exceptions.InvalidMxMessageException;
import gr.datamation.converter.common.exceptions.StopTranslationException;
import gr.datamation.converter.common.exceptions.TranslationUnhandledException;
import gr.datamation.converter.common.utils.MtMessageValidationUtils;
import gr.datamation.converter.common.utils.MxMessageValidationUtils;
import gr.datamation.converter.iso20022.Iso20022Translator;
import gr.datamation.converter.iso20022.converters.mt.Mt300ToFxtr01400104;
import gr.datamation.converter.iso20022.interfaces.MtToIso20022Translator;
import gr.datamation.mt.common.SwiftMessage;
import gr.datamation.mx.message.fxtr.ForeignExchangeTradeInstruction04;
import javax.xml.bind.JAXBException;
import java.io.UnsupportedEncodingException;
public class TranslateMtToMx {
public static void main(String... args) {
translateMt300ToFxtr014_Auto();
translateMt300ToFxtr014_ExplicitText();
translateMt300ToFxtr014_ExplicitObject();
}
public static void translateMt300ToFxtr014_Auto() {
String mxMessage = null;
// You have the option to provide the MT message in text format and get back the ISO20022 message in text format.
// Translator auto detects the translation mapping.
// In order to handle MT and ISO20022 messages, advice README.md
try {
mxMessage = Iso20022Translator.translateMtToMx(validMtMessage);
} catch (InvalidMtMessageException e) {
System.out.println("MT message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (StopTranslationException e) {
System.out.println("Translation errors occurred");
e.getTranslationErrorList().forEach(System.out::println);
return;
} catch (TranslationUnhandledException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
return;
}
//Validate the Translated message
try {
MxMessageValidationUtils.autoParseAndValidateMxMessage(mxMessage);
System.out.println("Translated Message is: \n" + mxMessage);
} catch (InvalidMxMessageException e) {
System.out.println("ISO20022 message is invalid");
e.getValidationErrorList().forEach(System.out::println);
}
}
public static void translateMt300ToFxtr014_ExplicitText() {
String mxMessage = null;
try {
// If you do not want to use the auto-translation functionality, you have the option to provide the MT message
// in text format and get back the ISO20022 message in text format. In this case you need to know the exact translation mapping.
// In order to handle MT and ISO20022 messages, advice README.md
MtToIso20022Translator<?> mtToMxTranslator = new Mt300ToFxtr01400104();
mxMessage = mtToMxTranslator.translate(validMtMessage);
} catch (InvalidMtMessageException e) {
System.out.println("MT message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (StopTranslationException e) {
System.out.println("Translation errors occurred");
e.getTranslationErrorList().forEach(System.out::println);
return;
} catch (TranslationUnhandledException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
return;
}
//Validate the Translated message
try {
MxMessageValidationUtils.autoParseAndValidateMxMessage(mxMessage);
System.out.println("Translated Message is: \n" + mxMessage);
} catch (InvalidMxMessageException e) {
System.out.println("ISO20022 message is invalid");
e.getValidationErrorList().forEach(System.out::println);
}
}
public static void translateMt300ToFxtr014_ExplicitObject() {
ForeignExchangeTradeInstruction04 mxMessage = null;
// If you do not want to use the auto-translation functionality, you have the option to provide the MT message
// in Object format and get back the ISO20022 message in Object format. In this case you need to know the exact translation mapping.
// In order to handle MT and ISO20022 messages, advice README.md
try {
SwiftMessage swiftMessage = MtMessageValidationUtils.parseMtMessage(validMtMessage);
MtToIso20022Translator<ForeignExchangeTradeInstruction04> mtToMxTranslator = new Mt300ToFxtr01400104();
mxMessage = mtToMxTranslator.translate(swiftMessage);
} catch (InvalidMtMessageException e) {
System.out.println("MT message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (StopTranslationException e) {
System.out.println("Translation errors occurred");
e.getTranslationErrorList().forEach(System.out::println);
return;
} catch (TranslationUnhandledException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
return;
}
//Validate the Translated message
try {
MxMessageValidationUtils.validateMxMessage(mxMessage);
System.out.println("Translated Message is: \n" + mxMessage.convertToXML());
} catch (InvalidMxMessageException e) {
System.out.println("ISO20022 message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (JAXBException | UnsupportedEncodingException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
}
}
private static final String validMtMessage = "{1:F01PRDTNGLAAXXX0000000000}{2:I300NAMENGLAXXXXN2020}{3:{108:MT300}}{4:\n" +
":15A:\n" +
":20:309656\n" +
":21:REF\n" +
":22A:NEWT\n" +
":22C:NAMELA1462PRDTLA\n" +
":82A:/12345\n" +
"PRDTNGLA\n" +
":87A:/54321\n" +
"NAMENGLA\n" +
":15B:\n" +
":30T:20220805\n" +
":30V:20220809\n" +
":36:414,62\n" +
":32B:USD5000,\n" +
":57A:/36204777\n" +
"CITIUS33\n" +
":33B:NGN2073100,\n" +
":57A:/3000025911\n" +
"CBNINGLA\n" +
":58A:/541291\n" +
"NAMENGLA\n" +
"-}{5:}";
}