libeufin

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

commit c8e211af05fd8727fc2e6d706b2c4bd92328e2cb
parent 786086d3779d15ccace3d80788530405a2aa1fbc
Author: MS <ms@taler.net>
Date:   Tue,  1 Dec 2020 13:15:19 +0100

Camt parsing.

Handling the case where one batch has multiple individual
transactions.  In this case, the individual transaction's amount
should be retrieved from a field named "AmtDtls", instead of the more
general "Amt".

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/iso20022/Iso20022.kt | 32++++++++++++++------------------
1 file changed, 14 insertions(+), 18 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 @@ -630,6 +630,18 @@ private fun XmlElementDestructor.extractCurrencyAmount(): CurrencyAmount { ) } +private fun XmlElementDestructor.maybeExtractTxCurrencyAmount(): CurrencyAmount? { + NexusAssert( + this.focusElement.tagName == "TxDtls", + "Wrong place to fetch a detailed amount" + ) + return maybeUniqueChildNamed("AmtDtls") { + requireUniqueChildNamed("TxAmt") { + maybeExtractCurrencyAmount() + } + } +} + private fun XmlElementDestructor.maybeExtractCurrencyAmount(): CurrencyAmount? { return maybeUniqueChildNamed("Amt") { CurrencyAmount( @@ -652,21 +664,6 @@ private fun XmlElementDestructor.extractMaybeCurrencyExchange(): CurrencyExchang } } -/* - * 1, see if TxDtls add to a sum. - * 2, if not, see if Btch provides a sum. - * 3, if not, see if NtryDtls provides a sum. - * 4, if not, keep the batch without a sum (it's not required to have one, - * only the very outer Ntry must have one. In fact, what goes in the DB - * is only the outer Ntry's amount). - * - * note: condition 4 should be rare, therefore a check on the batched - * amount could be done towards the end, and complain if none is found. - * - * Right now, the code assumes that one Ntry has only one NtryDtls with only - * one TxDtls; this assumption is too strong, and ideally should be removed. - * */ - // FIXME: move to util module. private fun currencyAmountSum(amount1: CurrencyAmount?, amount2: CurrencyAmount?): CurrencyAmount? { if (amount1 == null) return amount2 @@ -679,7 +676,6 @@ private fun currencyAmountSum(amount1: CurrencyAmount?, amount2: CurrencyAmount? return CurrencyAmount(currency = amount1.currency, value = amount1.value + amount2.value) } -// this function runs with a Ntry as its context. private fun XmlElementDestructor.extractBatches( inheritableAmount: CurrencyAmount?, outerCreditDebitIndicator: CreditDebitIndicator @@ -722,11 +718,11 @@ private fun XmlElementDestructor.extractBatches( "Divergent credit-debit indicator (2) $txCreditDebitIndicator vs $outerCreditDebitIndicator" ) } - var txAmount = maybeExtractCurrencyAmount() + var txAmount = maybeExtractCurrencyAmount() ?: maybeExtractTxCurrencyAmount() if (txAmount == null) { NexusAssert( inheritableBatchAmount != null, - "Missing or inconsistent information about singleton sub-transaction(s) amount(s) (0)" + "Singleton transaction has no amount and can't inherit it from its container." ) txAmount = inheritableBatchAmount }