Search in sources :

Example 1 with BankToCustomerAccountReportV02

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;
}
Also used : TransactionContainer(net.petafuel.styx.core.xs2a.entities.TransactionContainer) BankToCustomerAccountReportV02(net.petafuel.styx.core.xs2a.utils.sepa.camt052.BankToCustomerAccountReportV02) AccountReport11(net.petafuel.styx.core.xs2a.utils.sepa.camt052.AccountReport11) AccountReport(net.petafuel.styx.core.xs2a.entities.AccountReport) ReportEntry2(net.petafuel.styx.core.xs2a.utils.sepa.camt052.ReportEntry2)

Example 2 with BankToCustomerAccountReportV02

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);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) JAXBException(javax.xml.bind.JAXBException) SEPAParsingException(net.petafuel.jsepa.exception.SEPAParsingException) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Document(net.petafuel.styx.core.xs2a.utils.sepa.camt052.Document) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Aggregations

StringReader (java.io.StringReader)1 URL (java.net.URL)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 SEPAParsingException (net.petafuel.jsepa.exception.SEPAParsingException)1 AccountReport (net.petafuel.styx.core.xs2a.entities.AccountReport)1 TransactionContainer (net.petafuel.styx.core.xs2a.entities.TransactionContainer)1 AccountReport11 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.AccountReport11)1 BankToCustomerAccountReportV02 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.BankToCustomerAccountReportV02)1 Document (net.petafuel.styx.core.xs2a.utils.sepa.camt052.Document)1 ReportEntry2 (net.petafuel.styx.core.xs2a.utils.sepa.camt052.ReportEntry2)1 SAXException (org.xml.sax.SAXException)1