gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 01/03: Camt.053 parsing.


From: gnunet
Subject: [libeufin] 01/03: Camt.053 parsing.
Date: Thu, 03 Dec 2020 13:45:36 +0100

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

ms pushed a commit to branch master
in repository libeufin.

commit 3f4ce8c575e9f418b8f3a20482d81a6ac9dcaa99
Author: MS <ms@taler.net>
AuthorDate: Tue Dec 1 21:21:11 2020 +0100

    Camt.053 parsing.
    
    Admit only the following style:
    
    - Ntry [1..]
    -- NtryDtls [1]
    --- TxDtls [1]
---
 .../tech/libeufin/nexus/iso20022/Iso20022.kt       | 92 ++++------------------
 1 file changed, 14 insertions(+), 78 deletions(-)

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,

-- 
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]