gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/08: evolving sandbox


From: gnunet
Subject: [libeufin] 01/08: evolving sandbox
Date: Fri, 04 Dec 2020 15:00:04 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit ebaf98b38fe96446f03bd12778f14baac9e83045
Author: MS <ms@taler.net>
AuthorDate: Thu Dec 3 23:00:21 2020 +0100

    evolving sandbox
---
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 43 +------------
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 70 +++++++++++-----------
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 63 +------------------
 sandbox/src/test/kotlin/CamtTest.kt                |  3 +-
 util/src/main/kotlin/JSON.kt                       | 10 ++--
 5 files changed, 47 insertions(+), 142 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 2a34039..5d9a6ca 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -248,10 +248,10 @@ class EbicsUploadTransactionChunkEntity(id: 
EntityID<String>) : Entity<String>(i
  */
 object BankAccountTransactionsTable : Table() {
     val creditorIban = text("creditorIban")
-    val creditorBic = text("creditorBic").nullable()
+    val creditorBic = text("creditorBic")
     val creditorName = text("creditorName")
     val debitorIban = text("debitorIban")
-    val debitorBic = text("debitorBic").nullable()
+    val debitorBic = text("debitorBic")
     val debitorName = text("debitorName")
     val subject = text("subject")
     val amount = text("amount")
@@ -259,31 +259,12 @@ object BankAccountTransactionsTable : Table() {
     val date = long("date")
     val pmtInfId = text("pmtInfId")
     val msgId = text("msgId")
+    val direction = text("direction")
     val account = reference("account", BankAccountsTable)
 
     override val primaryKey = PrimaryKey(pmtInfId, msgId)
 }
 
-/*
-class BankAccountTransactionsEntity(id: EntityID<Int>) : IntEntity(id) {
-    companion object : 
IntEntityClass<BankAccountTransactionsEntity>(BankAccountTransactionsTable)
-
-    var creditorIban by BankAccountTransactionsTable.creditorIban
-    var creditorBic by BankAccountTransactionsTable.creditorBic
-    var creditorName by BankAccountTransactionsTable.creditorName
-    var debitorIban by BankAccountTransactionsTable.debitorIban
-    var debitorBic by BankAccountTransactionsTable.debitorBic
-    var debitorName by BankAccountTransactionsTable.debitorName
-    var subject by BankAccountTransactionsTable.subject
-    var amount by BankAccountTransactionsTable.amount
-    var currency by BankAccountTransactionsTable.currency
-    var date by BankAccountTransactionsTable.date
-    var pmtInfId by BankAccountTransactionsTable.pmtInfId
-    var msgId by BankAccountTransactionsTable.msgId
-    var account by BankAccountEntity referencedOn 
BankAccountTransactionsTable.account
-}
-*/
-
 /**
  * Table that keeps information about which bank accounts (iban+bic+name)
  * are active in the system.
@@ -313,15 +294,6 @@ object BankAccountStatementsTable : IntIdTable() {
     val bankAccount = reference("bankAccount", BankAccountsTable)
 }
 
-class BankAccountStatementsEntity(id: EntityID<Int>) : IntEntity(id) {
-    companion object : 
IntEntityClass<BankAccountStatementsEntity>(BankAccountStatementsTable)
-
-    var statementId by BankAccountStatementsTable.statementId
-    var xmlMessage by BankAccountStatementsTable.xmlMessage
-    var creationTime by BankAccountStatementsTable.creationTime
-    var bankAccount by BankAccountEntity referencedOn 
BankAccountStatementsTable.bankAccount
-}
-
 object BankAccountReportsTable : IntIdTable() {
     val reportId = text("reportId")
     val creationTime = long("creationTime")
@@ -329,15 +301,6 @@ object BankAccountReportsTable : IntIdTable() {
     val bankAccount = reference("bankAccount", BankAccountsTable)
 }
 
-class BankAccountReportsTableEntity(id: EntityID<Int>) : IntEntity(id) {
-    companion object : 
IntEntityClass<BankAccountReportsTableEntity>(BankAccountReportsTable)
-
-    var reportId by BankAccountReportsTable.reportId
-    var xmlMessage by BankAccountReportsTable.xmlMessage
-    var creationTime by BankAccountReportsTable.creationTime
-    var bankAccount by BankAccountEntity referencedOn 
BankAccountReportsTable.bankAccount
-}
-
 fun dbCreateTables(dbName: String) {
     Database.connect("jdbc:sqlite:${dbName}", "org.sqlite.JDBC")
     TransactionManager.manager.defaultIsolationLevel = 
Connection.TRANSACTION_SERIALIZABLE
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index e93c79d..90215a6 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -42,7 +42,7 @@ import tech.libeufin.sandbox.BankAccountTransactionsTable.date
 import tech.libeufin.sandbox.BankAccountTransactionsTable.debitorBic
 import tech.libeufin.sandbox.BankAccountTransactionsTable.debitorIban
 import tech.libeufin.sandbox.BankAccountTransactionsTable.debitorName
-import tech.libeufin.sandbox.BankAccountTransactionsTable.msgId
+import tech.libeufin.sandbox.BankAccountTransactionsTable.direction
 import tech.libeufin.sandbox.BankAccountTransactionsTable.pmtInfId
 import tech.libeufin.sandbox.BankAccountTransactionsTable.subject
 import tech.libeufin.util.*
@@ -54,7 +54,6 @@ import tech.libeufin.util.ebics_s001.SignatureTypes
 import tech.libeufin.util.ebics_s001.UserSignatureData
 import java.security.interfaces.RSAPrivateCrtKey
 import java.security.interfaces.RSAPublicKey
-import java.sql.SQLException
 import java.time.Instant
 import java.time.LocalDateTime
 import java.util.*
@@ -167,6 +166,37 @@ fun <T> expectNonNull(x: T?): T {
     return x;
 }
 
+private fun getRelatedParty(branch: XmlElementBuilder, payment: RawPayment) {
+    val otherParty = object {
+        var ibanPath = "CdtrAcct/Id/IBAN"
+        var namePath = "Cdtr/Nm"
+        var iban = payment.creditorIban
+        var name = payment.creditorName
+        var bicPath = "CdtrAgt"
+        var bic = payment.creditorBic
+    }
+    if (payment.direction == "CRDT") {
+        otherParty.iban = payment.debitorIban
+        otherParty.ibanPath = "DbtrAcct/Id/IBAN"
+        otherParty.namePath = "Dbtr/Nm"
+        otherParty.name = payment.debitorName
+        otherParty.bic = payment.debitorBic
+    }
+    branch.element("RltdPties") {
+        element(otherParty.ibanPath) {
+            text(otherParty.iban)
+        }
+        element(otherParty.namePath) {
+            text(otherParty.name)
+        }
+    }
+    branch.element("RltdAgts") {
+        element(otherParty.bicPath) {
+            text(otherParty.bic)
+        }
+    }
+}
+
 /**
  * Returns a list of camt strings.  Note: each element in the
  * list accounts for only one payment in the history.  In other
@@ -397,37 +427,7 @@ fun buildCamtString(type: Int, subscriberIban: String, 
history: MutableList<RawP
                                             }
                                         }
                                     }
-                                    element("RltdPties") {
-                                        element("Dbtr/Nm") {
-                                            text(it.debitorName)
-                                        }
-                                        element("DbtrAcct/Id/IBAN") {
-                                            text(it.debitorIban)
-                                        }
-                                        element("Cdtr/Nm") {
-                                            text(it.creditorName)
-                                        }
-                                        element("CdtrAcct/Id/IBAN") {
-                                            text(it.creditorIban)
-                                        }
-                                    }
-//                                    element("RltdAgts") {
-//                                        element("CdtrAgt/FinInstnId/BIC") {
-//                                            // FIXME: explain this!
-//                                            text(
-//                                                if 
(subscriberIban.equals(it.creditorIban))
-//                                                    it.debitorBic else 
it.creditorBic
-//                                            )
-//                                        }
-//                                        element("DbtrAgt/FinInstnId/BIC") {
-//                                            // FIXME: explain this!
-//                                            text(
-//                                                if 
(subscriberIban.equals(it.creditorIban))
-//                                                    it.creditorBic else 
it.debitorBic
-//                                            )
-//                                        }
-//
-//                                    }
+                                    getRelatedParty(this, it)
                                     element("RmtInf/Ustrd") {
                                         text(it.subject)
                                     }
@@ -487,7 +487,8 @@ private fun constructCamtResponse(
                     // The line below produces a value too long (>35 chars),
                     // and it makes the document invalid!
                     // uid = "${it[pmtInfId]}-${it[msgId]}"
-                    uid = "${it[pmtInfId]}"
+                    uid = "${it[pmtInfId]}",
+                    direction = it[direction]
                 )
             )
         }
@@ -585,6 +586,7 @@ private fun handleCct(paymentRequest: String, 
initiatorName: String, ctx: Reques
                 it[date] = Instant.now().toEpochMilli()
                 it[pmtInfId] = parseResult.pmtInfId
                 it[msgId] = parseResult.msgId
+                it[direction] = "DBIT"
             }
         } catch (e: ExposedSQLException) {
             logger.warn("Could not insert new payment into the database: ${e}")
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 38469a9..7f0f73f 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -249,7 +249,8 @@ fun serverMain(dbName: String) {
                                 creditorName = it[creditorName],
                                 debitorBic = it[debitorBic],
                                 debitorName = it[debitorName],
-                                currency = it[currency]
+                                currency = it[currency],
+                                direction = "FIXME"
                             )
                         )
                     }
@@ -388,66 +389,6 @@ fun serverMain(dbName: String) {
             post("/ebicsweb") {
                 call.ebicsweb()
             }
-            /**
-             * Shows all bank account statements.
-             */
-            /*
-              FIXME: Heng Yeow.
-
-            get("/admin/statements") {
-                var ret = BankAccountStatement()
-                ret.creationTime = Instant.now().toEpochMilli()
-                ret.statementId = "C52-" + 
Instant.now().toEpochMilli().toHttpDateString() + "-" + 
UUID.randomUUID().toString()
-                ret.message = mutableListOf<String>()
-                transaction {
-                    BankAccountTransactionsTable.selectAll().forEach {
-                        ret.message.add(
-                            constructXml(indent = true) {
-                                root("Document") {
-                                    attribute("xmlns", 
"urn:iso:std:iso:20022:tech:xsd:camt.053.001.02")
-                                    attribute("xmlns:xsi", 
"http://www.w3.org/2001/XMLSchema-instance";)
-                                    attribute(
-                                        "xsi:schemaLocation",
-                                        
"urn:iso:std:iso:20022:tech:xsd:camt.053.001.02 camt.053.001.02.xsd"
-                                    )
-                                    element("Ntry") {
-                                        element("Amt") {
-                                            attribute("Ccy", it.currency)
-                                            text(it.amount)
-                                        }
-                                    }
-                                }
-                            }
-                        )
-                    }
-                }
-                transaction {
-                    BankAccountStatementsTable.insert {
-                        it[statementId] = ret.statementId
-                        it[creationTime] = ret.creationTime
-                        it[xmlMessage] = ret.message.toString()
-                    }
-                }
-                call.respond(ret)
-                return@get
-            }
-
-             */
-            /**
-             * Shows all bank account reports.
-             */
-            /*
-              FIXME: Heng Yeow.
-
-            get("/admin/reports") {
-                val body = call.receive<DateRange>()
-                var ret = BankAccountReport()
-
-                call.respond(ret)
-                return@get
-            }
-            
-             */
         }
     }
     LOGGER.info("Up and running")
diff --git a/sandbox/src/test/kotlin/CamtTest.kt 
b/sandbox/src/test/kotlin/CamtTest.kt
index 8c06558..b7f7294 100644
--- a/sandbox/src/test/kotlin/CamtTest.kt
+++ b/sandbox/src/test/kotlin/CamtTest.kt
@@ -19,7 +19,8 @@ class CamtTest {
             currency = "EUR",
             subject = "reimbursement",
             date = "1000-02-02",
-            uid = "0"
+            uid = "0",
+            direction = "DBIT"
         )
         val xml = buildCamtString(
             53,
diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt
index d7ddd89..834f4b0 100644
--- a/util/src/main/kotlin/JSON.kt
+++ b/util/src/main/kotlin/JSON.kt
@@ -26,17 +26,15 @@ package tech.libeufin.util
  */
 data class RawPayment(
     val creditorIban: String,
-    val creditorBic: String? = null,
+    val creditorBic: String,
     val creditorName: String,
     val debitorIban: String,
-    val debitorBic: String? = null,
+    val debitorBic: String,
     val debitorName: String,
     val amount: String,
     val currency: String,
     val subject: String,
     val date: String? = null,
-    // this (uid) field is null when RawPayment is a _requested_ payment
-    // over the admin API, and it's not null when RawPayment represent
-    // a database row of a settled payment.
-    val uid: String? = null
+    val uid: String? = null,
+    val direction: String
 )
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]