Created
August 31, 2023 11:26
-
-
Save gantoniadispc14/ae339065b6ccbe47aa7b802633c12f24 to your computer and use it in GitHub Desktop.
ParseAndValidateSepaEpcInstMessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gr.datamation.iso20022.sepa.epc.inst.pacs.FIToFICustomerCreditTransfer08SepaEpcInst; | |
import gr.datamation.validation.error.ValidationError; | |
import gr.datamation.validation.error.ValidationErrorList; | |
import java.io.ByteArrayInputStream; | |
class ParseAndValidateSepaEpcInstMessage { | |
public static void main(String... args) { | |
execute(); | |
} | |
public static void execute() { | |
constructSepaEpcInstMessage(); | |
parseAndValidateSepaEpcInstMessage(); | |
} | |
public static void constructSepaEpcInstMessage() { | |
try { | |
//Initialize the message object | |
FIToFICustomerCreditTransfer08SepaEpcInst fIToFIPaymentStatusReport10 = new FIToFICustomerCreditTransfer08SepaEpcInst(); | |
//Optionally, use an existing message if we do not want to create the object from scratch | |
fIToFIPaymentStatusReport10.parseXML(validSepaEpcInstPacs008string); | |
//We fill the elements with the message object using setters | |
// fIToFIPaymentStatusReport10.getMessage().setGrpHdr(new GroupHeader93()); | |
// 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 parseAndValidateSepaEpcInstMessage() { | |
try { | |
//Initialize the message object | |
FIToFICustomerCreditTransfer08SepaEpcInst fiCustomerCreditTransfer08SepaEpcInst = new FIToFICustomerCreditTransfer08SepaEpcInst(); | |
//Validate against the xml schema | |
ValidationErrorList validationErrorList = fiCustomerCreditTransfer08SepaEpcInst.validateXML(new ByteArrayInputStream(validSepaEpcInstPacs008string.getBytes())); | |
if (!validationErrorList.isEmpty()) { | |
handleValidationError(validationErrorList); | |
return; | |
} | |
//Fill the message with data from xml | |
fiCustomerCreditTransfer08SepaEpcInst.parseXML(validSepaEpcInstPacs008string); | |
//Validate both the xml schema and rules | |
validationErrorList.addAll(fiCustomerCreditTransfer08SepaEpcInst.validate()); | |
if (validationErrorList.isEmpty()) { | |
System.out.println("Message is valid"); | |
System.out.println(fiCustomerCreditTransfer08SepaEpcInst.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.out.println("Message is invalid"); | |
for (ValidationError validationError : validationErrorList) { | |
System.out.println(validationError.getMessage()); | |
} | |
} | |
private static final String validSepaEpcInstPacs008string = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + | |
"<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08\">\n" + | |
" <FIToFICstmrCdtTrf>\n" + | |
" <GrpHdr>\n" + | |
" <MsgId>SSSSSS200020190305ORD000011119</MsgId>\n" + | |
" <CreDtTm>2019-03-06T14:56:10</CreDtTm>\n" + | |
" <NbOfTxs>1</NbOfTxs>\n" + | |
" <TtlIntrBkSttlmAmt Ccy=\"EUR\">228.71</TtlIntrBkSttlmAmt>\n" + | |
" <IntrBkSttlmDt>2019-03-06</IntrBkSttlmDt>\n" + | |
" <SttlmInf>\n" + | |
" <SttlmMtd>CLRG</SttlmMtd>\n" + | |
" <ClrSys>\n" + | |
" <Cd>REP</Cd>\n" + | |
" </ClrSys>\n" + | |
" </SttlmInf>\n" + | |
" <PmtTpInf>\n" + | |
" <SvcLvl>\n" + | |
" <Cd>SEPA</Cd>\n" + | |
" </SvcLvl>\n" + | |
" <LclInstrm>\n" + | |
" <Cd>INST</Cd>\n" + | |
" </LclInstrm>\n" + | |
" </PmtTpInf>\n" + | |
" <InstgAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BICFI>TESTBICX</BICFI>\n" + | |
" </FinInstnId>\n" + | |
" </InstgAgt>\n" + | |
" <InstdAgt>\n" + | |
" <FinInstnId>\n" + | |
" <BICFI>TESTBICB</BICFI>\n" + | |
" </FinInstnId>\n" + | |
" </InstdAgt>\n" + | |
" </GrpHdr>\n" + | |
" <CdtTrfTxInf>\n" + | |
" <PmtId>\n" + | |
" <InstrId>BSCHESMMCT1201903054095263553</InstrId>\n" + | |
" <EndToEndId>NOT PROVIDED</EndToEndId>\n" + | |
" <TxId>00730100632BHGCRWC</TxId>\n" + | |
" </PmtId>\n" + | |
" <IntrBkSttlmAmt Ccy=\"EUR\">228.71</IntrBkSttlmAmt>\n" + | |
" <AccptncDtTm>2022-11-03T15:43:44.074+02:00</AccptncDtTm>\n" + | |
" <ChrgBr>SLEV</ChrgBr>\n" + | |
" <Dbtr>\n" + | |
" <Nm>JOHN DOE</Nm>\n" + | |
" <PstlAdr>\n" + | |
" <Ctry>ES</Ctry>\n" + | |
" <AdrLine>ADDRESS 1</AdrLine>\n" + | |
" <AdrLine>ADDRESS 2</AdrLine>\n" + | |
" </PstlAdr>\n" + | |
" <Id>\n" + | |
" <PrvtId>\n" + | |
" <DtAndPlcOfBirth>\n" + | |
" <BirthDt>1982-02-12</BirthDt>\n" + | |
" <PrvcOfBirth>TEST</PrvcOfBirth>\n" + | |
" <CityOfBirth>Athens</CityOfBirth>\n" + | |
" <CtryOfBirth>GR</CtryOfBirth>\n" + | |
" </DtAndPlcOfBirth>\n" + | |
" </PrvtId>\n" + | |
" </Id>\n" + | |
" </Dbtr>\n" + | |
" <DbtrAcct>\n" + | |
" <Id>\n" + | |
" <IBAN>ES5300730100503232323232</IBAN>\n" + | |
" </Id>\n" + | |
" </DbtrAcct>\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" + | |
" <Cdtr>\n" + | |
" <Nm>Jane Doe</Nm>\n" + | |
" <PstlAdr>\n" + | |
" <Ctry>GR</Ctry>\n" + | |
" <AdrLine>AdressLine 1</AdrLine>\n" + | |
" <AdrLine>AdressLine 2</AdrLine>\n" + | |
" </PstlAdr>\n" + | |
" <Id>\n" + | |
" <PrvtId>\n" + | |
" <Othr>\n" + | |
" <Id>SOMEID 1</Id>\n" + | |
" <SchmeNm>\n" + | |
" <Prtry>PRTRY</Prtry>\n" + | |
" </SchmeNm>\n" + | |
" <Issr>ISSUER</Issr>\n" + | |
" </Othr>\n" + | |
" </PrvtId>\n" + | |
" </Id>\n" + | |
" </Cdtr>\n" + | |
" <CdtrAcct>\n" + | |
" <Id>\n" + | |
" <IBAN>ES1911110001063300445566</IBAN>\n" + | |
" </Id>\n" + | |
" </CdtrAcct>\n" + | |
" </CdtTrfTxInf>\n" + | |
" </FIToFICstmrCdtTrf>\n" + | |
"</Document>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment