libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 3b548a61b61f3308cff2d54b20edb5636a354a98
parent f974215e759a3ecf9d5b65a3f396696aa03e548c
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 26 Mar 2020 10:37:30 +0100

Extract data from CAMT.053 returned by the bank.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 1+
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 38+++++++++++++++++++++++++++++++++-----
Mutil/src/main/kotlin/zip.kt | 6++++--
3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -18,6 +18,7 @@ object EbicsRawBankTransactionsTable : IdTable<Long>() { val nexusSubscriber = reference("subscriber", EbicsSubscribersTable) // How did we learn about this transaction? C52 / C53 / C54 val sourceType = text("sourceType") + // Name of the ZIP entry val sourceFileName = text("sourceFileName") // "Subject" of the SEPA transaction val unstructuredRemittanceInformation = text("unstructuredRemittanceInformation") diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -643,11 +643,39 @@ fun main() { * at all. */ response.orderData.unzipWithLoop { - // parse the camt.053 here, and persist into database. - val camt53doc = XMLUtil.parseStringIntoDom(it) - val creditorIban = XMLUtil.getStringViaXpath(camt53doc, "//CdtrAcct/Id/IBAN") - val creditOrDebit = XMLUtil.getStringViaXpath(camt53doc, "//Ntry/CdtDbtInd") - logger.debug("Creditor IBAN: $creditorIban, credit-or-debit: $creditOrDebit") + val fileName = it.first + val camt53doc = XMLUtil.parseStringIntoDom(it.second) + val creditorIban = XMLUtil.getStringFromXpath( + camt53doc, + "//*[local-name()='CdtrAcct']//*[local-name()='IBAN']" + ) + val debitorIban = XMLUtil.getStringFromXpath( + camt53doc, + "//*[local-name()='DbtrAcct']//*[local-name()='IBAN']" + ) + val creditOrDebit = XMLUtil.getStringFromXpath( + camt53doc, + "//*[local-name()='Ntry']//*[local-name()='CdtDbtInd']" + ) + val amount = XMLUtil.getNodeFromXpath( + camt53doc, + "//*[local-name()='Ntry']//*[local-name()='Amt']" + ) + val subject = XMLUtil.getStringFromXpath( + camt53doc, + "//*[local-name()='RmtInf']//*[local-name()='Ustrd']" + ) + val currency = amount?.attributes?.getNamedItem("Ccy")?.nodeValue + + println( + "####" + + "\n\tCreditor IBAN: $creditorIban," + + "\n\tDebitor IBAN: $debitorIban," + + "\n\tCurrency: $currency," + + "\n\tAmount: ${amount?.firstChild?.nodeValue}" + + "\n\tSubject: $subject," + + "\n\tFile name: $fileName" + ) } call.respondText( "C53 data persisted into the database (WIP).", diff --git a/util/src/main/kotlin/zip.kt b/util/src/main/kotlin/zip.kt @@ -37,10 +37,12 @@ fun ByteArray.prettyPrintUnzip(): String { return s.toString() } -fun ByteArray.unzipWithLoop(process: (String) -> Unit) { +fun ByteArray.unzipWithLoop(process: (Pair<String, String>) -> Unit) { val mem = SeekableInMemoryByteChannel(this) val zipFile = ZipFile(mem) zipFile.getEntriesInPhysicalOrder().iterator().forEach { - process(zipFile.getInputStream(it).readAllBytes().toString(Charsets.UTF_8)) + process( + Pair(it.name, zipFile.getInputStream(it).readAllBytes().toString(Charsets.UTF_8)) + ) } } \ No newline at end of file