libeufin

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

commit fde7d90ef5a3638cb36b197340f4fd068282b8f1
parent e31a3f710db050b75b72108f8501ad85a4ab276f
Author: MS <ms@taler.net>
Date:   Thu,  3 Dec 2020 13:43:21 +0100

Testing Camt ingestion.

This commit adds a new endpoint to POST directly
a XML document into the Camt parser, in order to
facilitate the checking of ingested history.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 41+++++++++++++++++++++++------------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 9+++++++++
Mutil/src/main/kotlin/Encoding.kt | 1-
3 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -163,6 +163,28 @@ suspend fun fetchEbicsBySpec( } } +fun storeCamt(bankConnectionId: String, camt: String, historyType: String) { + val camt53doc = XMLUtil.parseStringIntoDom(camt) + val msgId = camt53doc.pickStringWithRootNs("/*[1]/*[1]/root:GrpHdr/root:MsgId") + logger.info("msg id $msgId") + transaction { + val conn = NexusBankConnectionEntity.findById(bankConnectionId) + if (conn == null) { + throw NexusError(HttpStatusCode.InternalServerError, "bank connection missing") + } + val oldMsg = NexusBankMessageEntity.find { NexusBankMessagesTable.messageId eq msgId }.firstOrNull() + if (oldMsg == null) { + NexusBankMessageEntity.new { + this.bankConnection = conn + this.code = historyType + this.messageId = msgId + this.message = ExposedBlob(camt.toByteArray(Charsets.UTF_8)) + } + } + } + +} + /** * Fetch EBICS C5x and store it locally, but do not update bank accounts. */ @@ -192,24 +214,7 @@ private suspend fun fetchEbicsC5x( is EbicsDownloadSuccessResult -> { response.orderData.unzipWithLambda { logger.debug("Camt entry: ${it.second}") - val camt53doc = XMLUtil.parseStringIntoDom(it.second) - val msgId = camt53doc.pickStringWithRootNs("/*[1]/*[1]/root:GrpHdr/root:MsgId") - logger.info("msg id $msgId") - transaction { - val conn = NexusBankConnectionEntity.findById(bankConnectionId) - if (conn == null) { - throw NexusError(HttpStatusCode.InternalServerError, "bank connection missing") - } - val oldMsg = NexusBankMessageEntity.find { NexusBankMessagesTable.messageId eq msgId }.firstOrNull() - if (oldMsg == null) { - NexusBankMessageEntity.new { - this.bankConnection = conn - this.code = historyType - this.messageId = msgId - this.message = ExposedBlob(it.second.toByteArray(Charsets.UTF_8)) - } - } - } + storeCamt(bankConnectionId, it.second, historyType) } } is EbicsDownloadBankErrorResult -> { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -377,6 +377,15 @@ fun serverMain(dbName: String, host: String) { call.respond(bankAccounts) return@get } + post("/bank-accounts/{accountId}/test-camt-ingestion/{type}") { + processCamtMessage( + ensureNonNull(call.parameters["accountId"]), + XMLUtil.parseStringIntoDom(call.receiveText()), + ensureNonNull(call.parameters["type"]) + ) + call.respond({ }) + return@post + } get("/bank-accounts/{accountid}/schedule") { val resp = jacksonObjectMapper().createObjectNode() val ops = jacksonObjectMapper().createObjectNode() diff --git a/util/src/main/kotlin/Encoding.kt b/util/src/main/kotlin/Encoding.kt @@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream class EncodingException : Exception("Invalid encoding") - object Base32Crockford { private fun ByteArray.getIntAt(index: Int): Int {