use of net.petafuel.styx.core.xs2a.utils.sepa.camt052.BankToCustomerAccountReportV02 in project styx by petafuel.
the class Camt052Converter method processReport.
public TransactionContainer processReport(String xmlData) throws SEPAParsingException {
BankToCustomerAccountReportV02 originalReport = parseReport(xmlData);
TransactionContainer transactionContainer = new TransactionContainer();
transactionContainer.setTransactions(new AccountReport());
transactionContainer.getTransactions().setBooked(new ArrayList<>());
transactionContainer.getTransactions().setPending(new ArrayList<>());
transactionContainer.getTransactions().setInformation(new ArrayList<>());
for (AccountReport11 generalInfoAndTXNs : originalReport.getRpt()) {
for (ReportEntry2 transactionInfo : generalInfoAndTXNs.getNtry()) {
convertTransaction(transactionContainer.getTransactions(), transactionInfo);
}
}
return transactionContainer;
}
use of net.petafuel.styx.core.xs2a.utils.sepa.camt052.BankToCustomerAccountReportV02 in project styx by petafuel.
the class Camt052Converter method parseReport.
private BankToCustomerAccountReportV02 parseReport(String xmlData) throws SEPAParsingException {
try {
// schema factory is required to initialize the validator object (XSD based validator)
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// extract XSD file from the JAR bundle
URL resource = getClass().getClassLoader().getResource("schema/camt.052.001.02.xsd");
// schema object will be initialized for validation
Schema schema = sf.newSchema(resource);
// jaxb context is required to initialize the unmarshaller, here we have to pass the GENERATED ObjectFactory class
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
// now, the unmarshaller (make java object out of XML string) itself gets initialized
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// connect the validator and unmarshaller. from here, the validation is activated
unmarshaller.setSchema(schema);
// now, validate and unmarshal the XML string
Document document = ((JAXBElement<Document>) unmarshaller.unmarshal(new StringReader(xmlData))).getValue();
LOG.info("camt052 xml parsing successful");
// extract relevant element from the whole XML. this steps is specific to the XML format we work with
return document.getBkToCstmrAcctRpt();
} catch (JAXBException | SAXException error) {
LOG.error("parseReport failed, invalid input", error);
throw new SEPAParsingException("Camt052 XML unmarshalling failed!", error);
}
}
Aggregations