commit 9b0aafb5e814fbb4328392fbd28e80e04ca95a60 parent f16ab461f917b03dca44487c9d2c7b9084a7431c Author: MS <ms@taler.net> Date: Mon, 3 Apr 2023 01:32:14 +0200 comments, indentation, helpers Diffstat:
6 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt @@ -391,7 +391,7 @@ fun maybeTalerRefunds(bankAccount: NexusBankAccountEntity, lastSeenId: Long) { NexusAssert( it[NexusBankTransactionsTable.creditDebitIndicator] == "CRDT" && it[NexusBankTransactionsTable.bankAccount] == bankAccount.id, - "Cannot refund a _outgoing_ payment!" + "Cannot refund an _outgoing_ payment!" ) // FIXME #7116 addPaymentInitiation( diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -396,6 +396,11 @@ suspend fun fetchBankAccountTransactions( connectionDetails.connectionName, accountId ) + /** + * Here it MIGHT just return in case of errors, but sometimes the + * fetcher asks for multiple results (e.g. C52 and C53), and what + * went through SHOULD be ingested. + */ /** * This block causes new NexusBankAccountTransactions rows to be diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -800,12 +800,13 @@ class EbicsBankConnectionProtocol: BankConnectionProtocol { HttpStatusCode.NotFound, "bank connection not found" ) - + // Avoiding to store twice one downloaded bank account. val isDuplicate = OfferedBankAccountsTable.select { OfferedBankAccountsTable.bankConnection eq conn.id and ( OfferedBankAccountsTable.offeredAccountId eq accountInfo.id) }.firstOrNull() if (isDuplicate != null) return@forEach + // Storing every new bank account. OfferedBankAccountsTable.insert { newRow -> newRow[accountHolder] = accountInfo.accountHolder ?: "NOT GIVEN" newRow[iban] = diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/iso20022/Iso20022.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/iso20022/Iso20022.kt @@ -43,7 +43,8 @@ import java.time.ZonedDateTime import java.time.format.DateTimeFormatter enum class CreditDebitIndicator { - DBIT, CRDT + DBIT, + CRDT } enum class CashManagementResponseType(@get:JsonValue val jsonName: String) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt @@ -1,11 +1,20 @@ package tech.libeufin.nexus.server +import io.ktor.http.* import org.jetbrains.exposed.sql.transactions.transaction import tech.libeufin.nexus.NexusBankConnectionEntity import tech.libeufin.nexus.NexusBankConnectionsTable +import tech.libeufin.nexus.NexusError import tech.libeufin.util.internalServerError import tech.libeufin.util.notFound +fun unknownBankAccount(bankAccountLabel: String): NexusError { + return NexusError( + HttpStatusCode.NotFound, + "Bank account $bankAccountLabel was not found" + ) +} + /** * FIXME: * enum type names were introduced after 0.9.2 and need to diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -456,7 +456,7 @@ val nexusApp: Application.() -> Unit = { resp.set<JsonNode>("schedule", ops) transaction { NexusBankAccountEntity.findByName(accountId) - ?: throw NexusError(HttpStatusCode.NotFound, "unknown bank account") + ?: throw unknownBankAccount(accountId) NexusScheduledTaskEntity.find { (NexusScheduledTasksTable.resourceType eq "bank-account") and (NexusScheduledTasksTable.resourceId eq accountId) @@ -479,7 +479,7 @@ val nexusApp: Application.() -> Unit = { val accountId = ensureNonNull(call.parameters["accountId"]) transaction { NexusBankAccountEntity.findByName(accountId) - ?: throw NexusError(HttpStatusCode.NotFound, "unknown bank account") + ?: throw unknownBankAccount(accountId) try { NexusCron.parser.parse(schedSpec.cronspec) } catch (e: IllegalArgumentException) { @@ -550,7 +550,7 @@ val nexusApp: Application.() -> Unit = { transaction { val bankAccount = NexusBankAccountEntity.findByName(accountId) if (bankAccount == null) { - throw NexusError(HttpStatusCode.NotFound, "unknown bank account") + throw unknownBankAccount(accountId) } val oldSchedTask = NexusScheduledTaskEntity.find { (NexusScheduledTasksTable.taskName eq taskId) and @@ -571,7 +571,7 @@ val nexusApp: Application.() -> Unit = { val res = transaction { val bankAccount = NexusBankAccountEntity.findByName(accountId) if (bankAccount == null) { - throw NexusError(HttpStatusCode.NotFound, "unknown bank account") + throw unknownBankAccount(accountId) } val holderEnc = URLEncoder.encode(bankAccount.accountHolder, Charsets.UTF_8) val lastSeenBalance = NexusBankBalanceEntity.find { @@ -693,7 +693,7 @@ val nexusApp: Application.() -> Unit = { val res = transaction { val bankAccount = NexusBankAccountEntity.findByName(accountId) if (bankAccount == null) { - throw NexusError(HttpStatusCode.NotFound, "unknown bank account ($accountId)") + throw unknownBankAccount(accountId) } val amount = parseAmount(body.amount) val paymentEntity = addPaymentInitiation( @@ -767,7 +767,7 @@ val nexusApp: Application.() -> Unit = { transaction { val bankAccount = NexusBankAccountEntity.findByName(bankAccountId) if (bankAccount == null) { - throw NexusError(HttpStatusCode.NotFound, "unknown bank account") + throw unknownBankAccount(bankAccountId) } NexusBankTransactionEntity.find { NexusBankTransactionsTable.bankAccount eq bankAccount.id }.map { val tx = jacksonObjectMapper().readValue(