-
Notifications
You must be signed in to change notification settings - Fork 6
/
TranslateMxToMt.java
182 lines (174 loc) · 9.24 KB
/
TranslateMxToMt.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.paymentcomponents.converter.rtgs.demo;
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.MxMessageValidationUtils;
import gr.datamation.converter.rtgs.RtgsTranslator;
import gr.datamation.converter.rtgs.converters.mx.Pacs009ToMt202;
import gr.datamation.converter.rtgs.interfaces.Target2ToMtTranslator;
import gr.datamation.iso20022.target2.pacs.FinancialInstitutionCreditTransfer08Rtgs;
import gr.datamation.mt.common.SwiftMessage;
import gr.datamation.mt.processor.SwiftMsgProcessor;
public class TranslateMxToMt {
public static void main(String... args) {
translatePacs009toMt202_Auto();
translatePacs009toMt202_ExplicitText();
translatePacs009toMt202_ExplicitObject();
}
public static void translatePacs009toMt202_Auto() {
// You have the option to provide the RTGS message in text format and get back the MT message in text format.
// Translator auto detects the translation mapping.
// In order to handle MT and RTGS messages, advice README.md
try {
String mtMessage = RtgsTranslator.translateMxToMt(validMXMessage);
System.out.println("Translated Message is: \n" + mtMessage);
} catch (InvalidMxMessageException e) {
System.out.println("Target2 message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (StopTranslationException e) {
System.out.println("Translation errors occurred");
e.getTranslationErrorList().forEach(System.out::println);
} catch (TranslationUnhandledException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
}
}
public static void translatePacs009toMt202_ExplicitText() {
// If you do not want to use the auto-translation functionality, you have the option to provide the RTGS message
// in text format and get back the MT message in text format. In this case you need to know the exact translation mapping.
// In order to handle MT and RTGS messages, advice README.md
try {
Target2ToMtTranslator<?> mxToMtTranslator = new Pacs009ToMt202();
String mtMessage = mxToMtTranslator.translate(validMXMessage);
System.out.println("Translated Message is: \n" + mtMessage);
} catch (InvalidMxMessageException e) {
System.out.println("Target2 message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (StopTranslationException e) {
System.out.println("Translation errors occurred");
e.getTranslationErrorList().forEach(System.out::println);
} catch (TranslationUnhandledException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
}
}
public static void translatePacs009toMt202_ExplicitObject() {
// If you do not want to use the auto-translation functionality, you have the option to provide the RTGS message
// in Object format and get back the MT message in Object format. In this case you need to know the exact translation mapping.
// In order to handle MT and RTGS messages, advice README.md
try {
FinancialInstitutionCreditTransfer08Rtgs coreMessage = MxMessageValidationUtils.parseAndValidateMxMessage(validMXMessage, FinancialInstitutionCreditTransfer08Rtgs.class);
//or RtgsMessageValidationUtils.autoParseAndValidateRtgsMessage(validMXMessage);
Target2ToMtTranslator<FinancialInstitutionCreditTransfer08Rtgs> mxToMtTranslator = new Pacs009ToMt202();
SwiftMessage mtMessage = mxToMtTranslator.translate(coreMessage);
System.out.println("Translated Message is: \n" + new SwiftMsgProcessor().BuildMsgStringFromObject(mtMessage));
} catch (InvalidMxMessageException e) {
System.out.println("Target2 message is invalid");
e.getValidationErrorList().forEach(System.out::println);
} catch (StopTranslationException e) {
System.out.println("Translation errors occurred");
e.getTranslationErrorList().forEach(System.out::println);
} catch (TranslationUnhandledException e) {
System.out.println("Unexpected error occurred");
e.printStackTrace();
} catch (Exception e) {
System.out.println("MT message is invalid");
e.printStackTrace();
}
}
private static final String validMXMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.009.001.08\">\n" +
" <FICdtTrf>\n" +
" <GrpHdr>\n" +
" <MsgId>BBBB/120928-FICT/JPY/430</MsgId>\n" +
" <CreDtTm>2012-09-28T16:00:00+13:00</CreDtTm>\n" +
" <NbOfTxs>1</NbOfTxs>\n" +
" <SttlmInf>\n" +
" <SttlmMtd>CLRG</SttlmMtd>\n" +
" <ClrSys>\n" +
" <Cd>TGT</Cd>\n" +
" </ClrSys>\n" +
" </SttlmInf>\n" +
" </GrpHdr>\n" +
" <CdtTrfTxInf>\n" +
" <PmtId>\n" +
" <InstrId>BBBB/120928-FICT</InstrId>\n" +
" <EndToEndId>ABC/4562/2012-09-08</EndToEndId>\n" +
" <UETR>00000000-0000-4000-8000-000000000000</UETR>\n" +
" </PmtId>\n" +
" <IntrBkSttlmAmt Ccy=\"JPY\">10000000</IntrBkSttlmAmt>\n" +
" <IntrBkSttlmDt>2012-09-29</IntrBkSttlmDt>\n" +
" <SttlmTmIndctn>\n" +
" <CdtDtTm>2012-09-28T16:00:00+13:00</CdtDtTm>\n" +
" </SttlmTmIndctn>\n" +
" <SttlmTmReq>\n" +
" <TillTm>12:12:12+13:00</TillTm>\n" +
" <FrTm>13:12:12+13:00</FrTm>\n" +
" </SttlmTmReq>\n" +
" <PrvsInstgAgt1>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICDXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </PrvsInstgAgt1>\n" +
" <InstgAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>BBBBUS33XXX</BICFI>\n" +
" </FinInstnId>\n" +
" </InstgAgt>\n" +
" <InstdAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>CCCCJPJTXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </InstdAgt>\n" +
" <IntrmyAgt1>\n" +
" <FinInstnId>\n" +
" <BICFI>INTERBICXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </IntrmyAgt1>\n" +
" <IntrmyAgt1Acct>\n" +
" <Id>\n" +
" <Othr>\n" +
" <Id>INTERAGTACCT</Id>\n" +
" </Othr>\n" +
" </Id>\n" +
" </IntrmyAgt1Acct>\n" +
" <Dbtr>\n" +
" <FinInstnId>\n" +
" <BICFI>BBBBUS33XXX</BICFI>\n" +
" </FinInstnId>\n" +
" </Dbtr>\n" +
" <DbtrAcct>\n" +
" <Id>\n" +
" <Othr>\n" +
" <Id>DBTRACCT</Id>\n" +
" </Othr>\n" +
" </Id>\n" +
" </DbtrAcct>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>AAAAJPJTXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" <CdtrAgtAcct>\n" +
" <Id>\n" +
" <Othr>\n" +
" <Id>CDTRAGTACCT</Id>\n" +
" </Othr>\n" +
" </Id>\n" +
" </CdtrAgtAcct>\n" +
" <Cdtr>\n" +
" <FinInstnId>\n" +
" <BICFI>AAAAGB2LXXX</BICFI>\n" +
" </FinInstnId>\n" +
" </Cdtr>\n" +
" <CdtrAcct>\n" +
" <Id>\n" +
" <Othr>\n" +
" <Id>CDTRACCT</Id>\n" +
" </Othr>\n" +
" </Id>\n" +
" </CdtrAcct>\n" +
" </CdtTrfTxInf>\n" +
" </FICdtTrf>\n" +
"</Document>";
}