gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 03/03: Testing Camt ingestion.


From: gnunet
Subject: [libeufin] 03/03: Testing Camt ingestion.
Date: Thu, 03 Dec 2020 13:45:38 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit fde7d90ef5a3638cb36b197340f4fd068282b8f1
Author: MS <ms@taler.net>
AuthorDate: Thu Dec 3 13:43:21 2020 +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.
---
 .../kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 41 ++++++++++++----------
 .../tech/libeufin/nexus/server/NexusServer.kt      |  9 +++++
 parsing-tests                                      |  2 +-
 util/src/main/kotlin/Encoding.kt                   |  1 -
 4 files changed, 33 insertions(+), 20 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
index d4d160f..e5877fd 100644
--- 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
index 6cfa8f2..13278cd 100644
--- 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/parsing-tests b/parsing-tests
index e1e2d28..805ed54 160000
--- a/parsing-tests
+++ b/parsing-tests
@@ -1 +1 @@
-Subproject commit e1e2d28ec38d67c0ce48394652abbfde856d84f9
+Subproject commit 805ed54ca6ba297b527e61551fb95ba31b467e4e
diff --git a/util/src/main/kotlin/Encoding.kt b/util/src/main/kotlin/Encoding.kt
index 25a59be..db0c269 100644
--- 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 {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]