[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 02/08: more abstraction at sandbox
From: |
gnunet |
Subject: |
[libeufin] 02/08: more abstraction at sandbox |
Date: |
Fri, 04 Dec 2020 15:00:05 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit 5132e4e257e98ab3ecadb554641af3abb06b84f8
Author: MS <ms@taler.net>
AuthorDate: Fri Dec 4 11:08:09 2020 +0100
more abstraction at sandbox
factoring out the querying of account histories
from the Ebics logic.
---
.../tech/libeufin/sandbox/EbicsProtocolBackend.kt | 36 +--------------
.../src/main/kotlin/tech/libeufin/sandbox/Main.kt | 7 ++-
.../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
index 90215a6..5ced5e1 100644
--- 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
index 7f0f73f..7de0c95 100644
--- 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
new file mode 100644
index 0000000..aff6fa5
--- /dev/null
+++ 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
+}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libeufin] branch master updated (c8bcfc1 -> ae7897d), gnunet, 2020/12/04
- [libeufin] 02/08: more abstraction at sandbox,
gnunet <=
- [libeufin] 01/08: evolving sandbox, gnunet, 2020/12/04
- [libeufin] 03/08: Refactoring Camt generation., gnunet, 2020/12/04
- [libeufin] 07/08: prefer wrapping lists into JSON field, gnunet, 2020/12/04
- [libeufin] 06/08: Get unit tests from Sandbox to pass., gnunet, 2020/12/04
- [libeufin] 08/08: abstract over Camt type, gnunet, 2020/12/04
- [libeufin] 04/08: sandbox payment API: ask the payment direction too, gnunet, 2020/12/04
- [libeufin] 05/08: address validation issues, gnunet, 2020/12/04