gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] 02/02: Disk-space policy at Sandbox.


From: gnunet
Subject: [libeufin] 02/02: Disk-space policy at Sandbox.
Date: Tue, 13 Dec 2022 23:12:59 +0100

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

ms pushed a commit to branch master
in repository libeufin.

commit 7f81b4913a45ce96b3f41626651fbf75dd662f26
Author: MS <ms@taler.net>
AuthorDate: Tue Dec 13 23:10:42 2022 +0100

    Disk-space policy at Sandbox.
    
    Delete EBICS messages from the database along
    the 'receipt' phase.
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 49 ++++++++++++++++------
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  4 +-
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index a50d99b2..bb95b837 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -508,7 +508,8 @@ fun getLastBalance(bankAccount: BankAccountEntity): 
BigDecimal {
         BankAccountStatementsTable.bankAccount eq bankAccount.id
     }.firstOrNull()
     val lastBalance = if (lastStatement == null) {
-        BigDecimal.ZERO } else { BigDecimal(lastStatement.balanceClbd) }
+        BigDecimal.ZERO
+    } else { BigDecimal(lastStatement.balanceClbd) }
     return lastBalance
 }
 
@@ -520,17 +521,28 @@ fun getLastBalance(bankAccount: BankAccountEntity): 
BigDecimal {
 private fun constructCamtResponse(
     type: Int,
     subscriber: EbicsSubscriberEntity,
-    dateRange: Pair<Long, Long>?): List<String> {
+    dateRange: Pair<Long, Long>?
+): List<String> {
 
     if (type != 53 && type != 52) throw EbicsUnsupportedOrderType()
     val bankAccount = getBankAccountFromSubscriber(subscriber)
     if (type == 52) {
+        if (dateRange != null)
+            throw NotImplementedError() // FIXME: #6243.
+        /**
+         * Note: before addressing #6243, the C52 is always generated
+         * without taking the time range into consideration.  That means
+         * that the request is treated always as "give last non booked"
+         * transactions.  The current implementation returns non booked
+         * transactions only on the first request, when the time range is
+         * missing.
+         */
         val history = mutableListOf<RawPayment>()
         /**
-         * This block adds all the fresh transactions to the intermediate
+         * This block adds all the non booked transactions to the intermediate
          * history list and returns the last balance that was reported in a
          * C53 document.  This latter will be the base balance to calculate
-         * the final balance after the fresh transactions.
+         * the final balance after the non booked transactions.
          */
         val lastBalance = transaction {
             BankAccountFreshTransactionEntity.all().forEach {
@@ -559,13 +571,9 @@ private fun constructCamtResponse(
             ret
         } else ""
         logger.debug("camt.052 document '${camtData.messageId}' 
generated.$payments")
-        return listOf(
-            camtData.camtMessage
-        )
+        return listOf(camtData.camtMessage)
     }
     SandboxAssert(type == 53, "Didn't catch unsupported CAMT type")
-    logger.debug("Finding C$type records")
-
     /**
      * FIXME: when this function throws an exception, it makes a JSON response 
being responded.
      * That is bad, because here we're inside a Ebics handler and only XML 
should
@@ -575,10 +583,10 @@ private fun constructCamtResponse(
     val ret = mutableListOf<String>()
     /**
      * Retrieve all the records whose creation date lies into the
-     * time range given as a function's parameter.
+     * time range given in the function parameters.
      */
     if (dateRange != null) {
-        logger.debug("Querying C$type with date range: $dateRange")
+        logger.debug("Querying C53 with date range: $dateRange")
         BankAccountStatementEntity.find {
             BankAccountStatementsTable.creationTime.between(
                 dateRange.first,
@@ -589,7 +597,6 @@ private fun constructCamtResponse(
         /**
          * No time range was given, hence pick the latest statement.
          */
-        logger.debug("No date range was given for c$type, respond with latest 
document")
         BankAccountStatementEntity.find {
             BankAccountStatementsTable.bankAccount eq bankAccount.id
         }.lastOrNull().apply {
@@ -1445,10 +1452,26 @@ suspend fun ApplicationCall.ebicsweb() {
                             throw EbicsInvalidRequestError()
                         logger.debug("Handling download receipt for EBICS 
transaction: " +
                                 requestTransactionID)
+                        /**
+                         * The receipt phase means that the client has already
+                         * received all the data related to the current 
download
+                         * transaction.  Hence this data can now be removed 
from
+                         * the database.
+                         */
+                        val ebicsData = transaction {
+                            
EbicsDownloadTransactionEntity.findById(requestTransactionID)
+                        }
+                        if (ebicsData == null)
+                            throw SandboxError(
+                                HttpStatusCode.InternalServerError,
+                                "EBICS transaction $requestTransactionID was 
not" +
+                                        "found in the database for deletion.",
+                                
LibeufinErrorCode.LIBEUFIN_EC_INCONSISTENT_STATE
+                            )
+                        ebicsData.delete()
                         val receiptCode =
                             requestObject.body.transferReceipt?.receiptCode ?: 
throw EbicsInvalidRequestError()
                         
EbicsResponse.createForDownloadReceiptPhase(requestTransactionID, receiptCode 
== 0)
-
                     }
                 }
                 signEbicsResponse(ebicsResponse, requestContext.hostAuthPriv)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 52d0d86a..c4742f2d 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -1005,8 +1005,8 @@ val sandboxApp: Application.() -> Unit = {
                 throw EbicsProcessingError("Serving EBICS threw unmanaged 
UtilError: ${e.reason}")
             }
             catch (e: SandboxError) {
-                val payload: String = e.message ?: e.stackTraceToString()
-                logger.info(payload)
+                val errorInfo: String = e.message ?: e.stackTraceToString()
+                logger.info(errorInfo)
                 // Should translate to EBICS error code.
                 when (e.errorCode) {
                     LibeufinErrorCode.LIBEUFIN_EC_INVALID_STATE -> throw 
EbicsProcessingError("Invalid bank state.")

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