gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: Server side EBICS date range.


From: gnunet
Subject: [libeufin] branch master updated: Server side EBICS date range.
Date: Wed, 02 Aug 2023 12:13:34 +0200

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

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 219bc3cc Server side EBICS date range.
219bc3cc is described below

commit 219bc3cc2dae211b18b9d6de7953e69b34fbae9e
Author: MS <ms@taler.net>
AuthorDate: Wed Aug 2 12:13:09 2023 +0200

    Server side EBICS date range.
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 37 ++++++++++++++++------
 .../kotlin/tech/libeufin/sandbox/bankAccount.kt    |  2 ++
 util/src/main/kotlin/Config.kt                     |  6 ++--
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 658d6373..48f5d8a4 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -27,6 +27,7 @@ import io.ktor.server.request.*
 import io.ktor.server.response.respond
 import io.ktor.server.response.respondText
 import io.ktor.util.AttributeKey
+import io.ktor.util.date.*
 import org.apache.xml.security.binding.xmldsig.RSAKeyValueType
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
@@ -476,20 +477,27 @@ private fun constructCamtResponse(
     subscriber: EbicsSubscriberEntity,
     dateRange: Pair<Long, Long>?
 ): List<String> {
-
     if (type != 53 && type != 52) throw EbicsUnsupportedOrderType()
     val bankAccount = getBankAccountFromSubscriber(subscriber)
+    val history = mutableListOf<XLibeufinBankTransaction>()
     if (type == 52) {
-        if (dateRange != null)
-            throw EbicsOrderParamsIgnored("C52 does not support date ranges.")
-        val history = mutableListOf<XLibeufinBankTransaction>()
-        transaction {
-            BankAccountFreshTransactionEntity.all().forEach {
-                if (it.transactionRef.account.label == bankAccount.label) {
-                    history.add(getHistoryElementFromTransactionRow(it))
+        if (dateRange != null) {
+            transaction {
+                BankAccountTransactionEntity.find {
+                    BankAccountTransactionsTable.account eq bankAccount.id and
+                            BankAccountTransactionsTable.date.between(
+                                dateRange.first, dateRange.second
+                            )
+                }.forEach { 
history.add(getHistoryElementFromTransactionRow(it)) }
+            }
+        } else
+            transaction {
+                BankAccountFreshTransactionEntity.all().forEach {
+                    if (it.transactionRef.account.label == bankAccount.label) {
+                        history.add(getHistoryElementFromTransactionRow(it))
+                    }
                 }
             }
-        }
         if (history.size == 0) throw EbicsNoDownloadDataAvailable()
         val camtData = buildCamtString(
             type,
@@ -678,6 +686,9 @@ private fun handleCct(
             )
             return@transaction
         }
+        /**
+         * FIXME: here call wire_transfer(), because it'll set the balances 
too.
+         */
         val bankAccount = getBankAccountFromIban(parseResult.debtorIban)
         if (parseResult.currency != bankAccount.demoBank.config.currency) 
throw EbicsRequestError(
             "[EBICS_PROCESSING_ERROR] Currency (${parseResult.currency}) not 
supported.",
@@ -740,10 +751,16 @@ private fun handleCct(
  * to the querying subscriber.
  */
 private fun handleEbicsC52(requestContext: RequestContext): ByteArray {
+    val maybeDateRange = 
requestContext.requestObject.header.static.orderDetails?.orderParams
+    val dateRange: Pair<Long, Long>? = if (maybeDateRange is 
EbicsRequest.StandardOrderParams) {
+        val start: Long? = 
maybeDateRange.dateRange?.start?.toGregorianCalendar()?.timeInMillis
+        val end: Long? = 
maybeDateRange.dateRange?.end?.toGregorianCalendar()?.timeInMillis
+        Pair(start ?: 0L, end ?: getTimeMillis())
+    } else null
     val report = constructCamtResponse(
         52,
         requestContext.subscriber,
-        dateRange = null
+        dateRange = dateRange
     )
     sandboxAssert(
         report.size == 1,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index faedcdd9..5adb1af0 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -241,8 +241,10 @@ data class HistoryParams(
     val untilMs: Long,
     val bankAccount: BankAccountEntity
 )
+
 fun extractTxHistory(params: HistoryParams): List<XLibeufinBankTransaction> {
     val ret = mutableListOf<XLibeufinBankTransaction>()
+
     /**
      * Helper that gets transactions earlier than the 'firstElementId'
      * transaction AND that match the URI parameters.
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
index c7958a75..17ec8a56 100644
--- a/util/src/main/kotlin/Config.kt
+++ b/util/src/main/kotlin/Config.kt
@@ -71,10 +71,10 @@ fun getValueFromEnv(varName: String): String? {
 fun getDbConnFromEnv(varName: String): String {
     val dbConnStr = System.getenv(varName)
     if (dbConnStr.isNullOrBlank() or dbConnStr.isNullOrEmpty()) {
-        printLnErr("\nError: DB connection string undefined or invalid in the 
env variable $varName.")
+        printLnErr("\nError: DB connection string undefined in the env 
variable $varName.")
         printLnErr("\nThe following two examples are valid connection 
strings:")
-        printLnErr("\njdbc:sqlite:/tmp/libeufindb.sqlite3")
-        
printLnErr("jdbc:postgresql://localhost:5432/libeufindb?user=Foo&password=secret\n")
+        printLnErr("\npostgres:///libeufindb")
+        
printLnErr("postgresql://localhost:5432/libeufindb?user=Foo&password=secret\n")
         exitProcess(1)
     }
     return dbConnStr

-- 
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]