libeufin

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

commit 5132e4e257e98ab3ecadb554641af3abb06b84f8
parent ebaf98b38fe96446f03bd12778f14baac9e83045
Author: MS <ms@taler.net>
Date:   Fri,  4 Dec 2020 11:08:09 +0100

more abstraction at sandbox

factoring out the querying of account histories
from the Ebics logic.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 36++----------------------------------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 7+++++--
Asandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -203,7 +203,7 @@ private fun getRelatedParty(branch: XmlElementBuilder, payment: RawPayment) { * words, the camt constructor does create always only one "Ntry" * node. */ -fun buildCamtString(type: Int, subscriberIban: String, history: MutableList<RawPayment>): MutableList<String> { +fun buildCamtString(type: Int, subscriberIban: String, history: List<RawPayment>): MutableList<String> { /** * ID types required: * @@ -462,39 +462,7 @@ private fun constructCamtResponse( } else Pair(parseDashedDate("1970-01-01"), LocalDateTime.now()) val history = mutableListOf<RawPayment>() val bankAccount = getBankAccountFromSubscriber(subscriber) - transaction { - logger.debug("Querying transactions involving: ${bankAccount.iban}") - BankAccountTransactionsTable.select { - BankAccountTransactionsTable.creditorIban eq bankAccount.iban or - (BankAccountTransactionsTable.debitorIban eq bankAccount.iban) - /** - FIXME: add the following condition too: - and (BankAccountTransactionsTable.date.between(start.millis, end.millis)) - */ - }.forEach { - history.add( - RawPayment( - subject = it[subject], - creditorIban = it[creditorIban], - creditorBic = it[creditorBic], - creditorName = it[creditorName], - debitorIban = it[debitorIban], - debitorBic = it[debitorBic], - debitorName = it[debitorName], - date = importDateFromMillis(it[date]).toDashedDate(), - amount = it[amount], - currency = it[currency], - // The line below produces a value too long (>35 chars), - // and it makes the document invalid! - // uid = "${it[pmtInfId]}-${it[msgId]}" - uid = "${it[pmtInfId]}", - direction = it[direction] - ) - ) - } - history - } - return buildCamtString(type, bankAccount.iban, history) + return buildCamtString(type, bankAccount.iban, historyForAccount(bankAccount.iban)) } /** diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -28,8 +28,6 @@ import io.ktor.features.ContentNegotiation import io.ktor.features.StatusPages import io.ktor.http.ContentType import io.ktor.http.HttpStatusCode -import io.ktor.request.receive -import io.ktor.request.uri import io.ktor.response.respond import io.ktor.response.respondText import io.ktor.routing.get @@ -61,6 +59,7 @@ import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.subcommands import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option +import io.ktor.request.* import io.ktor.util.AttributeKey import tech.libeufin.sandbox.BankAccountTransactionsTable import tech.libeufin.sandbox.BankAccountTransactionsTable.amount @@ -234,6 +233,10 @@ fun serverMain(dbName: String) { get("/") { call.respondText("Hello, this is Sandbox\n", ContentType.Text.Plain) } + // only reason for a post is to hide the iban to some degree. + post("/admin/payments/camt53") { + val iban = call.receiveText() + } get("/admin/payments") { val ret = PaymentsResponse() transaction { diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt @@ -0,0 +1,52 @@ +package tech.libeufin.sandbox + +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.or +import org.jetbrains.exposed.sql.select +import org.jetbrains.exposed.sql.transactions.transaction +import tech.libeufin.util.RawPayment +import tech.libeufin.util.importDateFromMillis +import tech.libeufin.util.logger +import tech.libeufin.util.toDashedDate + +fun historyForAccount(iban: String): List<RawPayment> { + val history = mutableListOf<RawPayment>() + transaction { + logger.debug("Querying transactions involving: ${iban}") + BankAccountTransactionsTable.select { + BankAccountTransactionsTable.creditorIban eq iban or + (BankAccountTransactionsTable.debitorIban eq iban) + /** + FIXME: add the following condition too: + and (BankAccountTransactionsTable.date.between(start.millis, end.millis)) + */ + /** + FIXME: add the following condition too: + and (BankAccountTransactionsTable.date.between(start.millis, end.millis)) + */ + + }.forEach { + history.add( + RawPayment( + subject = it[BankAccountTransactionsTable.subject], + creditorIban = it[BankAccountTransactionsTable.creditorIban], + creditorBic = it[BankAccountTransactionsTable.creditorBic], + creditorName = it[BankAccountTransactionsTable.creditorName], + debitorIban = it[BankAccountTransactionsTable.debitorIban], + debitorBic = it[BankAccountTransactionsTable.debitorBic], + debitorName = it[BankAccountTransactionsTable.debitorName], + date = importDateFromMillis(it[BankAccountTransactionsTable.date]).toDashedDate(), + amount = it[BankAccountTransactionsTable.amount], + currency = it[BankAccountTransactionsTable.currency], + // The line below produces a value too long (>35 chars), + // and it makes the document invalid! + // uid = "${it[pmtInfId]}-${it[msgId]}" + uid = "${it[BankAccountTransactionsTable.pmtInfId]}", + direction = it[BankAccountTransactionsTable.direction] + ) + ) + } + + } + return history +}