use of net.petafuel.styx.core.xs2a.utils.sepa.camt052.EntryDetails1 in project styx by petafuel.
the class Camt052Converter method convertTransaction.
private void convertTransaction(AccountReport accountReport, ReportEntry2 originalPayment) {
List<EntryDetails1> entryDetails = originalPayment.getNtryDtls();
if (entryDetails != null && !entryDetails.isEmpty()) {
List<EntryTransaction2> transactionDetails = entryDetails.get(0).getTxDtls();
if (transactionDetails.isEmpty()) {
LOG.info("Transaction has no IBAN/BIC, sender/receiver information");
return;
}
if (transactionDetails.size() > 1) {
LOG.error("Input contains more than one NtryDtls/TxDtls, only FIRST processed!");
}
// this will be the new transaction element in JSON array
Transaction transaction = new Transaction();
// from here, extract data from XML and map to JSON object
// status
EntryStatus2Code camtBookingStatus = originalPayment.getSts();
if (camtBookingStatus.equals(EntryStatus2Code.BOOK) || camtBookingStatus.equals(EntryStatus2Code.INFO)) {
accountReport.getBooked().add(transaction);
} else {
accountReport.getPending().add(transaction);
}
// bookingDate if present
Optional.ofNullable(originalPayment.getBookgDt()).map(DateAndDateTimeChoice::getDt).map(XMLGregorianCalendar::toGregorianCalendar).map(GregorianCalendar::getTime).ifPresent(transaction::setBookingDate);
// valueDate if present
Optional.ofNullable(originalPayment.getValDt()).map(DateAndDateTimeChoice::getDt).map(XMLGregorianCalendar::toGregorianCalendar).map(GregorianCalendar::getTime).ifPresent(transaction::setValueDate);
// creditDebit
// amount
// currency
transaction.setTransactionAmount(new Amount());
if (originalPayment.getCdtDbtInd().equals(CreditDebitCode.DBIT)) {
BigDecimal amount = originalPayment.getAmt().getValue().negate();
transaction.getTransactionAmount().setAmount(amount.toString());
transaction.getTransactionAmount().setCurrency(Currency.valueOf(originalPayment.getAmt().getCcy()));
}
EntryTransaction2 firstTransactionDetails = transactionDetails.get(0);
// debtor account
TransactionParty2 transactionParty = firstTransactionDetails.getRltdPties();
transaction.setDebtorAccount(new AccountReference(transactionParty.getDbtrAcct().getId().getIBAN(), AccountReference.Type.IBAN));
// optionally set debtor name
Optional.ofNullable(transactionParty.getDbtr()).map(PartyIdentification32::getNm).ifPresent(transaction::setDebtorName);
// set debtor agent if present
Optional.ofNullable(firstTransactionDetails.getRltdAgts()).map(TransactionAgents2::getDbtrAgt).map(BranchAndFinancialInstitutionIdentification4::getFinInstnId).map(FinancialInstitutionIdentification7::getBIC).ifPresent(transaction::setDebtorAgent);
// creditor account
transaction.setCreditorAccount(new AccountReference(firstTransactionDetails.getRltdPties().getCdtrAcct().getId().getIBAN(), AccountReference.Type.IBAN));
// set creditor name if present
Optional.ofNullable(transactionParty.getCdtr()).map(PartyIdentification32::getNm).ifPresent(transaction::setCreditorName);
// set creditor agent if present
Optional.ofNullable(firstTransactionDetails.getRltdAgts()).map(TransactionAgents2::getCdtrAgt).map(BranchAndFinancialInstitutionIdentification4::getFinInstnId).map(FinancialInstitutionIdentification7::getBIC).ifPresent(transaction::setCreditorAgent);
// reference
transaction.setRemittanceInformationUnstructured(String.join("\n", firstTransactionDetails.getRmtInf().getUstrd()));
// set e2e reference if present
Optional.ofNullable(firstTransactionDetails.getRefs()).map(TransactionReferences2::getEndToEndId).ifPresent(transaction::setEndToEndId);
// set additional information
transaction.setAdditionalInformation(originalPayment.getAddtlNtryInf());
}
}
Aggregations