[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated (c8e211a -> fde7d90)
From: |
gnunet |
Subject: |
[libeufin] branch master updated (c8e211a -> fde7d90) |
Date: |
Thu, 03 Dec 2020 13:45:35 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a change to branch master
in repository libeufin.
from c8e211a Camt parsing.
new 3f4ce8c Camt.053 parsing.
new e31a3f7 makefile
new fde7d90 Testing Camt ingestion.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
Makefile | 2 +-
.../kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 41 +++++-----
.../tech/libeufin/nexus/iso20022/Iso20022.kt | 92 ++++------------------
.../tech/libeufin/nexus/server/NexusServer.kt | 9 +++
parsing-tests | 2 +-
util/src/main/kotlin/Encoding.kt | 1 -
6 files changed, 48 insertions(+), 99 deletions(-)
diff --git a/Makefile b/Makefile
index 8445f6e..523d884 100644
--- a/Makefile
+++ b/Makefile
@@ -47,5 +47,5 @@ tests:
.PHONY: parse
parse:
- @cd parsing-tests; git pull || true
+ @cd parsing-tests; git pull origin master || true
@cd parsing-tests; py.test -s checks.py
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/iso20022/Iso20022.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/iso20022/Iso20022.kt
index b534244..33a0f3d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/iso20022/Iso20022.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/iso20022/Iso20022.kt
@@ -680,86 +680,25 @@ private fun XmlElementDestructor.extractBatches(
inheritableAmount: CurrencyAmount?,
outerCreditDebitIndicator: CreditDebitIndicator
): List<Batch> {
- return mapEachChildNamed("NtryDtls") {
- var batchAmount = maybeUniqueChildNamed("Btch") {
- maybeUniqueChildNamed("TtlAmt") {
- CurrencyAmount(
- value = BigDecimal(focusElement.textContent),
- currency = focusElement.getAttribute("Ccy")
- )
- }
- }
- if (inheritableAmount != null && batchAmount != null) {
- NexusAssert(
- inheritableAmount.value == batchAmount.value,
- "Inconsistent amount from parent."
- )
- }
- batchAmount = batchAmount ?: inheritableAmount
- val numTxs: Int = mapEachChildNamed("TxDtls") { }.count()
- val inheritableBatchAmount = if (numTxs <= 1) batchAmount ?:
inheritableAmount else null
-
- val batchDirection = maybeUniqueChildNamed("Btch") {
- maybeExtractCreditDebitIndicator()
+ if (mapEachChildNamed("NtryDtls") {}.size != 1) return mutableListOf()
+ var txs = requireUniqueChildNamed("NtryDtls") {
+ if (mapEachChildNamed("TxDtls") {}.size != 1) {
+ return@requireUniqueChildNamed mutableListOf<BatchTransaction>()
}
- if (batchDirection != null) {
- NexusAssert(
- batchDirection == outerCreditDebitIndicator,
- "Divergent credit-debit indicator (1)"
- )
- }
- var amountChecksum: CurrencyAmount? = null
- var txs = mapEachChildNamed("TxDtls") {
+ requireUniqueChildNamed("TxDtls") {
val details = extractTransactionDetails(outerCreditDebitIndicator)
- val txCreditDebitIndicator = maybeExtractCreditDebitIndicator()
- if (txCreditDebitIndicator != null) {
- NexusAssert(
- txCreditDebitIndicator == outerCreditDebitIndicator,
- "Divergent credit-debit indicator (2)
$txCreditDebitIndicator vs $outerCreditDebitIndicator"
+ mutableListOf(
+ BatchTransaction(
+ inheritableAmount,
+ outerCreditDebitIndicator,
+ details
)
- }
- var txAmount = maybeExtractCurrencyAmount() ?:
maybeExtractTxCurrencyAmount()
- if (txAmount == null) {
- NexusAssert(
- inheritableBatchAmount != null,
- "Singleton transaction has no amount and can't inherit it
from its container."
- )
- txAmount = inheritableBatchAmount
- }
- amountChecksum = currencyAmountSum(amountChecksum, txAmount)
- BatchTransaction(
- txAmount,
- outerCreditDebitIndicator,
- details
)
}
- if (amountChecksum == null) {
- NexusAssert(
- txs.isEmpty(),
- "Missing or inconsistent information about singleton
sub-transaction(s) amount(s) (1)"
- )
- // Without ANY sub-transaction defined, the batch MUST have it
mentioned ALREADY somewhere "before".
- NexusAssert(
- inheritableBatchAmount != null,
- "Missing or inconsistent information about singleton
sub-transaction(s) amount(s) (2)"
- )
- amountChecksum = batchAmount
- txs = mutableListOf(
- BatchTransaction(batchAmount, outerCreditDebitIndicator, null)
- )
- }
- NexusAssert(
- amountChecksum != null,
- "Internal amount-check failed (1): $amountChecksum"
- )
- if (batchAmount != null) {
- NexusAssert(
- amountChecksum?.value == batchAmount.value,
- "Internal amount-check failed (2)"
- )
- }
- Batch(messageId = null, paymentInformationId = null, batchTransactions
= txs)
}
+ return mutableListOf(
+ Batch(messageId = null, paymentInformationId = null, batchTransactions
= txs)
+ )
}
private fun XmlElementDestructor.maybeExtractCreditDebitIndicator():
CreditDebitIndicator? {
@@ -951,10 +890,7 @@ private fun
XmlElementDestructor.extractInnerTransactions(): CamtReport {
instructedAmount = instructedAmount,
creditDebitIndicator = creditDebitIndicator,
bankTransactionCode = btc,
- batches = extractBatches(
- if (mapEachChildNamed("NtryDtls") {}.count() == 1) amount else
null,
- creditDebitIndicator
- ),
+ batches = extractBatches(amount, creditDebitIndicator),
bookingDate = maybeUniqueChildNamed("BookgDt") {
extractDateOrDateTime() },
valueDate = maybeUniqueChildNamed("ValDt") {
extractDateOrDateTime() },
accountServicerRef = acctSvcrRef,
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.
- [libeufin] branch master updated (c8e211a -> fde7d90),
gnunet <=