-
Notifications
You must be signed in to change notification settings - Fork 13
/
ParseAndValidateSepaSibsCtMessage.java
293 lines (267 loc) · 13.6 KB
/
ParseAndValidateSepaSibsCtMessage.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.paymentcomponents.swift.mx.sepa.sibs.ct;
import gr.datamation.iso20022.sepa.sibs.ct.headers.CvfBulkCreditTransferSepaSibsCt;
import gr.datamation.iso20022.sepa.sibs.ct.pacs.FIToFIPaymentStatusReport10SepaSibsCt;
import gr.datamation.validation.error.ValidationError;
import gr.datamation.validation.error.ValidationErrorList;
import java.io.ByteArrayInputStream;
public class ParseAndValidateSepaSibsCtMessage {
public static void main(String... args) {
execute();
}
public static void execute() {
constructSepaSibsCtMessage();
parseAndValidateSepaSibsCtMessage();
constructSepaSibsCtHeader();
parseAndValidateSepaSibsCtHeader();
}
public static void constructSepaSibsCtMessage() {
try {
//Initialize the message object
FIToFIPaymentStatusReport10SepaSibsCt fIToFIPaymentStatusReport10 = new FIToFIPaymentStatusReport10SepaSibsCt();
//Optionally use an existing message if we do not want to create the object from scratch
fIToFIPaymentStatusReport10.parseXML(validSepaSibsCtPacs002String);
//We fill the elements with the message object using setters
// fIToFIPaymentStatusReport10.getMessage().setGrpHdr(new SCTGroupHeader91());
// fIToFIPaymentStatusReport10.getMessage().getGrpHdr().setMsgId("1234");
//or setElement()
//fIToFIPaymentStatusReport10.setElement("GrpHdr/MsgId", "1234");
//Perform validation
ValidationErrorList validationErrorList = fIToFIPaymentStatusReport10.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Message is valid");
System.out.println(fIToFIPaymentStatusReport10.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
public static void parseAndValidateSepaSibsCtMessage() {
try {
//Initialize the message object
FIToFIPaymentStatusReport10SepaSibsCt fIToFIPaymentStatusReport10 = new FIToFIPaymentStatusReport10SepaSibsCt();
//Validate against the xml schema
ValidationErrorList validationErrorList = fIToFIPaymentStatusReport10.validateXML(new ByteArrayInputStream(validSepaSibsCtPacs002String.getBytes()));
if (!validationErrorList.isEmpty()) {
handleValidationError(validationErrorList);
return;
}
//Fill the message with data from xml
fIToFIPaymentStatusReport10.parseXML(validSepaSibsCtPacs002String);
//Validate both the xml schema and rules
validationErrorList.addAll(fIToFIPaymentStatusReport10.validate());
if (validationErrorList.isEmpty()) {
System.out.println("Message is valid");
System.out.println(fIToFIPaymentStatusReport10.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
public static void constructSepaSibsCtHeader() {
try {
//Initialize the message object
CvfBulkCreditTransferSepaSibsCt cvfHeader = new CvfBulkCreditTransferSepaSibsCt();
//Optionally use an existing message if we do not want to create the object from scratch
cvfHeader.parseXML(validSepaSibsCtCvfHeaderString);
//We fill the elements with the message object using setters
//cvfHeader.getMessage().setFileCycleNo("123")
//or setElement()
// cvfHeader.setElement("FileCycleNo", "123");
// In case we already have a message object, we can set it to the header
FIToFIPaymentStatusReport10SepaSibsCt fIToFIPaymentStatusReport10 = new FIToFIPaymentStatusReport10SepaSibsCt();
fIToFIPaymentStatusReport10.parseXML(validSepaSibsCtPacs002String);
cvfHeader.getMessage().getFIToFIPmtStsRptS2().add(fIToFIPaymentStatusReport10.getMessage());
//Perform validation
ValidationErrorList validationErrorList = cvfHeader.validate();
if (validationErrorList.isEmpty()) {
System.out.println("Message is valid");
System.out.println(cvfHeader.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
public static void parseAndValidateSepaSibsCtHeader() {
try {
//Initialize the message object
CvfBulkCreditTransferSepaSibsCt cvfHeader = new CvfBulkCreditTransferSepaSibsCt();
//Validate against the xml schema
ValidationErrorList validationErrorList = cvfHeader.validateXML(new ByteArrayInputStream(validSepaSibsCtCvfHeaderString.getBytes()));
if (!validationErrorList.isEmpty()) {
handleValidationError(validationErrorList);
return;
}
//Fill the message with data from xml
cvfHeader.parseXML(validSepaSibsCtCvfHeaderString);
//Validate both the xml schema and rules
validationErrorList.addAll(cvfHeader.validate());
if (validationErrorList.isEmpty()) {
System.out.println("Message is valid");
System.out.println(cvfHeader.convertToXML()); //Get the generated xml
} else {
handleValidationError(validationErrorList);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
}
private static void handleValidationError(ValidationErrorList validationErrorList) {
System.err.println("Message is invalid, and the errors are the following:");
for (ValidationError error : validationErrorList) {
System.err.println(error.toString());
System.err.println(
"Error Code: " + error.getErrorCode() + "\n" +
"Error Description: " + error.getDescription() + "\n" +
"Line number in error inside the tag: " + error.getLine() + "\n"
);
}
}
private static final String validSepaSibsCtPacs002String = "<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10S2\">\n" +
" <FIToFIPmtStsRptS2>\n" +
" <GrpHdr>\n" +
" <MsgId>SCTREJ200020190314300000000001</MsgId>\n" +
" <CreDtTm>2019-03-14T00:00:00</CreDtTm>\n" +
" </GrpHdr>\n" +
" <OrgnlGrpInfAndSts>\n" +
" <OrgnlMsgId>SSSSSS111120190313090033395001</OrgnlMsgId>\n" +
" <OrgnlMsgNmId>pacs.008.001.02</OrgnlMsgNmId>\n" +
" <OrgnlNbOfTxs>1</OrgnlNbOfTxs>\n" +
" <OrgnlCtrlSum>1</OrgnlCtrlSum>\n" +
" <GrpSts>PART</GrpSts>\n" +
" <StsRsnInf>\n" +
" <Orgtr>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>TESTBICB</AnyBIC>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Orgtr>\n" +
" <Rsn>\n" +
" <Cd>AC01</Cd>\n" +
" </Rsn>\n" +
" </StsRsnInf>\n" +
" </OrgnlGrpInfAndSts>\n" +
" <TxInfAndSts>\n" +
" <StsId>000R907330000001</StsId>\n" +
" <OrgnlInstrId>b18332f58ca64ffd87ea9777b9edfba1</OrgnlInstrId>\n" +
" <OrgnlEndToEndId>NOTPROVIDED</OrgnlEndToEndId>\n" +
" <OrgnlTxId>111T9072000000000000000000000000006</OrgnlTxId>\n" +
" <TxSts>str1</TxSts>\n" +
" <StsRsnInf>\n" +
" <Orgtr>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>TESTBICB</AnyBIC>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Orgtr>\n" +
" <Rsn>\n" +
" <Cd>AC01</Cd>\n" +
" </Rsn>\n" +
" </StsRsnInf>\n" +
" <OrgnlTxRef>\n" +
" <IntrBkSttlmAmt Ccy=\"EUR\">9.95</IntrBkSttlmAmt>\n" +
" <IntrBkSttlmDt>2015-09-28</IntrBkSttlmDt>\n" +
" <DbtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICA</BICFI>\n" +
" </FinInstnId>\n" +
" </DbtrAgt>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICB</BICFI>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" </OrgnlTxRef>\n" +
" </TxInfAndSts>\n" +
" </FIToFIPmtStsRptS2>\n" +
"</Document>";
private static final String validSepaSibsCtCvfHeaderString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<S2SCTCvf:SCTCvfBlkCredTrf xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xmlns:S2SCTCvf=\"urn:S2SCTCvf:xsd:$SCTCvfBlkCredTrf\"\n" +
" xsi:schemaLocation=\"urn:S2SCTCvf:xsd:$SCTCvfBlkCredTrf SCTCvxBlkCredTrf.xsd\"\n" +
">\n" +
" <S2SCTCvf:SndgInst>TESTBICB</S2SCTCvf:SndgInst>\n" +
" <S2SCTCvf:RcvgInst>TESTBICA</S2SCTCvf:RcvgInst>\n" +
" <S2SCTCvf:SrvcId>SCT</S2SCTCvf:SrvcId>\n" +
" <S2SCTCvf:TstCode>T</S2SCTCvf:TstCode>\n" +
" <S2SCTCvf:FType>CVX</S2SCTCvf:FType>\n" +
" <S2SCTCvf:FileRef>2018111800000001</S2SCTCvf:FileRef>\n" +
" <S2SCTCvf:ClrSys>str</S2SCTCvf:ClrSys>\n" +
" <S2SCTCvf:FileDtTm>2018-11-17T00:00:00</S2SCTCvf:FileDtTm>\n" +
" <S2SCTCvf:OrigFRef>123456</S2SCTCvf:OrigFRef>\n" +
" <S2SCTCvf:OrigFName>Fname</S2SCTCvf:OrigFName>\n" +
" <S2SCTCvf:OrigDtTm>2018-11-17T00:00:00</S2SCTCvf:OrigDtTm>\n" +
" <S2SCTCvf:FileRjctRsn>ASD</S2SCTCvf:FileRjctRsn>\n" +
" <S2SCTCvf:FileBusDt>2018-11-18</S2SCTCvf:FileBusDt>\n" +
" <S2SCTCvf:FileCycleNo>01</S2SCTCvf:FileCycleNo>\n" +
" <S2SCTCvf:FIToFIPmtStsRptS2 xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10S2\">\n" +
" <GrpHdr>\n" +
" <MsgId>SCTREJ200020190314300000000001</MsgId>\n" +
" <CreDtTm>2019-03-14T00:00:00</CreDtTm>\n" +
" </GrpHdr>\n" +
" <OrgnlGrpInfAndSts>\n" +
" <OrgnlMsgId>SSSSSS111120190313090033395001</OrgnlMsgId>\n" +
" <OrgnlMsgNmId>pacs.008.001.02</OrgnlMsgNmId>\n" +
" <OrgnlNbOfTxs>1</OrgnlNbOfTxs>\n" +
" <OrgnlCtrlSum>1</OrgnlCtrlSum>\n" +
" <GrpSts>PART</GrpSts>\n" +
" <StsRsnInf>\n" +
" <Orgtr>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>TESTBICB</AnyBIC>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Orgtr>\n" +
" <Rsn>\n" +
" <Cd>AC01</Cd>\n" +
" </Rsn>\n" +
" </StsRsnInf>\n" +
" </OrgnlGrpInfAndSts>\n" +
" <TxInfAndSts>\n" +
" <StsId>000R907330000001</StsId>\n" +
" <OrgnlInstrId>b18332f58ca64ffd87ea9777b9edfba1</OrgnlInstrId>\n" +
" <OrgnlEndToEndId>NOTPROVIDED</OrgnlEndToEndId>\n" +
" <OrgnlTxId>111T9072000000000000000000000000006</OrgnlTxId>\n" +
" <TxSts>str1</TxSts>\n" +
" <StsRsnInf>\n" +
" <Orgtr>\n" +
" <Id>\n" +
" <OrgId>\n" +
" <AnyBIC>TESTBICB</AnyBIC>\n" +
" </OrgId>\n" +
" </Id>\n" +
" </Orgtr>\n" +
" <Rsn>\n" +
" <Cd>AC01</Cd>\n" +
" </Rsn>\n" +
" </StsRsnInf>\n" +
" <OrgnlTxRef>\n" +
" <IntrBkSttlmAmt Ccy=\"EUR\">9.95</IntrBkSttlmAmt>\n" +
" <IntrBkSttlmDt>2015-09-28</IntrBkSttlmDt>\n" +
" <DbtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICA</BICFI>\n" +
" </FinInstnId>\n" +
" </DbtrAgt>\n" +
" <CdtrAgt>\n" +
" <FinInstnId>\n" +
" <BICFI>TESTBICB</BICFI>\n" +
" </FinInstnId>\n" +
" </CdtrAgt>\n" +
" </OrgnlTxRef>\n" +
" </TxInfAndSts>\n" +
" </S2SCTCvf:FIToFIPmtStsRptS2>\n" +
"</S2SCTCvf:SCTCvfBlkCredTrf>\n";
}