gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: Implementing date range search in C53.


From: gnunet
Subject: [libeufin] branch master updated: Implementing date range search in C53.
Date: Tue, 31 Aug 2021 14:43:20 +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 3967193  Implementing date range search in C53.
3967193 is described below

commit 3967193487e42335b43b80ee7407fa44ad39cf70
Author: ms <ms@taler.net>
AuthorDate: Tue Aug 31 14:42:28 2021 +0200

    Implementing date range search in C53.
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 82 ++++++++++++++--------
 1 file changed, 52 insertions(+), 30 deletions(-)

diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index e10af80..fddfc93 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -462,21 +462,12 @@ fun buildCamtString(
  *
  * @param type 52 or 53.
  */
-private fun constructCamtResponse(type: Int, subscriber: 
EbicsSubscriberEntity): String {
-
-    /**
-     *  Currently unused: see #6243.
-     *
-
-    val dateRange = (header.static.orderDetails?.orderParams as 
EbicsRequest.StandardOrderParams).dateRange
-    val (start: LocalDateTime, end: LocalDateTime) = if (dateRange != null) {
-        Pair(
-            
importDateFromMillis(dateRange.start.toGregorianCalendar().timeInMillis),
-            
importDateFromMillis(dateRange.end.toGregorianCalendar().timeInMillis)
-        )
-    } else Pair(parseDashedDate("1970-01-01"), LocalDateTime.now())
+private fun constructCamtResponse(
+    type: Int,
+    subscriber: EbicsSubscriberEntity,
+    // fixes #6243
+    dateRange: Pair<Long, Long>?): List<String> {
 
-    */
     if (type != 53) throw EbicsUnsupportedOrderType()
     /**
      * FIXME: when this function throws an exception, it makes a JSON response 
being responded.
@@ -485,15 +476,32 @@ private fun constructCamtResponse(type: Int, subscriber: 
EbicsSubscriberEntity):
      * return XML" message appear in the Nexus logs.
      */
     val bankAccount = getBankAccountFromSubscriber(subscriber)
-    val camtMessage = transaction {
+    val ret = mutableListOf<String>()
+    /**
+     * Retrieve all the records whose creation date lies into the
+     * time range given as a function's parameter.
+     */
+    if (dateRange != null) {
+        BankAccountStatementEntity.find {
+            BankAccountStatementsTable.creationTime.between(dateRange.first, 
dateRange.second)
+        }.forEach { ret.add(it.xmlMessage) }
+    } else {
+        /**
+         * No time range was given, hence pick the latest statement.
+         */
         BankAccountStatementEntity.find {
             BankAccountStatementsTable.bankAccount eq bankAccount.id
-        }.lastOrNull()?.xmlMessage ?: throw EbicsRequestError(
-            "[EBICS_NO_DOWNLOAD_DATA_AVAILABE]",
-            "090005"
-        )
+        }.lastOrNull().apply {
+            if (this != null) {
+                ret.add(this.xmlMessage)
+            }
+        }
     }
-    return camtMessage
+    if (ret.size == 0) throw EbicsRequestError(
+        "[EBICS_NO_DOWNLOAD_DATA_AVAILABLE]",
+        "090005"
+    )
+    return ret
 }
 
 /**
@@ -648,22 +656,36 @@ private fun handleCct(paymentRequest: String) {
 private fun handleEbicsC53(requestContext: RequestContext): ByteArray {
     logger.debug("Handling C53 request")
 
+    // Fetch date range.
+    val orderParams = 
requestContext.requestObject.header.static.orderDetails?.orderParams // as 
EbicsRequest.StandardOrderParams
+    val dateRange = if (orderParams != null) {
+        val standardOrderParams = orderParams as 
EbicsRequest.StandardOrderParams
+        val start = 
standardOrderParams.dateRange?.start?.toGregorianCalendar()?.timeInMillis
+        val end = 
standardOrderParams.dateRange?.end?.toGregorianCalendar()?.timeInMillis
+        if (start == null || end == null) {
+            // only accepting when both start/end are given.
+            null
+        } else {
+            Pair(start, end)
+        }
+    } else {
+        null
+    }
     /**
      * By multiple statements, this function is responsible to return
      * a list of Strings: one for each statement.
      */
-    val camt = constructCamtResponse(
+    val camtStatements = constructCamtResponse(
         53,
-        requestContext.subscriber
+        requestContext.subscriber,
+        dateRange
     )
-   if (!XMLUtil.validateFromString(camt)) throw EbicsProcessingError(
-       "Sandbox generated a invalid XML response."
-   )
-    /**
-     * Here, the list of strings will be converted to list of
-     * ByteArray and passed to the zip() method.
-     */
-    return listOf(camt.toByteArray(Charsets.UTF_8)).zip()
+    camtStatements.forEach {
+        if (!XMLUtil.validateFromString(it)) throw EbicsProcessingError(
+            "One statement was found invalid."
+        )
+    }
+    return camtStatements.map { it.toByteArray() }.zip()
 }
 
 private suspend fun ApplicationCall.handleEbicsHia(header: 
EbicsUnsecuredRequest.Header, orderData: ByteArray) {

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