libeufin

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

commit 7794a6b2c1e7bcd79a242605337cd36004983456
parent 37eeee8edc13664fc91004e59840172a2001050c
Author: MS <ms@taler.net>
Date:   Tue, 12 Jan 2021 18:15:08 +0100

Telling how many new transactions arrived from bank.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt | 10+++++++---
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 8++------
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -207,7 +207,8 @@ fun processCamtMessage(bankAccountId: String, camtDoc: Document, code: String): * Create new transactions for an account based on bank messages it * did not see before. */ -fun ingestBankMessagesIntoAccount(bankConnectionId: String, bankAccountId: String) { +fun ingestBankMessagesIntoAccount(bankConnectionId: String, bankAccountId: String): Int { + var totalNew = 0 transaction { val conn = NexusBankConnectionEntity.findById(bankConnectionId) if (conn == null) { @@ -222,6 +223,7 @@ fun ingestBankMessagesIntoAccount(bankConnectionId: String, bankAccountId: Strin (NexusBankMessagesTable.bankConnection eq conn.id) and (NexusBankMessagesTable.id greater acct.highestSeenBankMessageId) }.orderBy(Pair(NexusBankMessagesTable.id, SortOrder.ASC)).forEach { + totalNew++ val doc = XMLUtil.parseStringIntoDom(it.message.bytes.toString(Charsets.UTF_8)) if (!processCamtMessage(bankAccountId, doc, it.code)) { it.errors = true @@ -231,6 +233,7 @@ fun ingestBankMessagesIntoAccount(bankConnectionId: String, bankAccountId: Strin } acct.highestSeenBankMessageId = lastId } + return totalNew } /** @@ -280,7 +283,7 @@ suspend fun fetchBankAccountTransactions( client: HttpClient, fetchSpec: FetchSpecJson, accountId: String -) { +): Int { val res = transaction { val acct = NexusBankAccountEntity.findById(accountId) if (acct == null) { @@ -315,8 +318,9 @@ suspend fun fetchBankAccountTransactions( "Connection type '${res.connectionType}' not implemented" ) } - ingestBankMessagesIntoAccount(res.connectionName, accountId) + val newMessages = ingestBankMessagesIntoAccount(res.connectionName, accountId) ingestTalerTransactions() + return newMessages } fun importBankAccount(call: ApplicationCall, offeredBankAccountId: String, nexusBankAccountId: String) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -650,12 +650,8 @@ fun serverMain(dbName: String, host: String, port: Int) { null ) } - fetchBankAccountTransactions( - client, - fetchSpec, - accountid - ) - call.respond(object {}) + val newMessages = fetchBankAccountTransactions(client, fetchSpec, accountid) + call.respond(object {val newMessages = newMessages}) return@post }