gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: shortening time conversions..


From: gnunet
Subject: [libeufin] branch master updated: shortening time conversions..
Date: Tue, 17 Mar 2020 18:12:06 +0100

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

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new c3da16f  shortening time conversions..
c3da16f is described below

commit c3da16f57bd56860a604f9b92ce118ce67e61007
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Mar 17 18:11:51 2020 +0100

    shortening time conversions..
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  | 23 ++++++++++------------
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 16 +++++++--------
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 0b79c81..72e28de 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -52,8 +52,11 @@ import javax.xml.datatype.DatatypeFactory
 import org.apache.commons.compress.archivers.ArchiveStreamFactory
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
 import org.apache.commons.compress.utils.IOUtils
+import org.joda.time.DateTime
+import org.joda.time.Instant
 import java.io.BufferedInputStream
 import java.io.ByteArrayInputStream
+import javax.xml.datatype.XMLGregorianCalendar
 
 
 open class EbicsRequestError(errorText: String, errorCode: String) :
@@ -190,7 +193,6 @@ private fun buildCamtString(history: 
SizedIterable<BankTransactionEntity>, type:
                              */
                         }
                     }
-
                     history.forEach {
                         element("Ntry") {
                             /* FIXME: one entry in an account history.
@@ -247,21 +249,16 @@ private fun buildCamtString(history: 
SizedIterable<BankTransactionEntity>, type:
  */
 private fun constructCamtResponse(type: Int, customerId: Int, header: 
EbicsRequest.Header): String {
 
+    val dateRange = (header.static.orderDetails?.orderParams as 
EbicsRequest.StandardOrderParams).dateRange
+    val (start, end) = if (dateRange != null) {
+        Pair(DateTime(Instant(dateRange.start)), 
DateTime(Instant(dateRange.end)))
+    } else Pair(DateTime(0), DateTime.now())
     val history = extractHistory(
         customerId,
-        try {
-            (header.static.orderDetails?.orderParams as 
EbicsRequest.StandardOrderParams).dateRange!!.start.toString()
-        } catch (e: Exception) {
-            LOGGER.debug("Asked to iterate over history with NO start date; 
default to now")
-            
DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar()).toString()
-        },
-        try {
-            (header.static.orderDetails?.orderParams as 
EbicsRequest.StandardOrderParams).dateRange!!.end.toString()
-        } catch (e: Exception) {
-            LOGGER.debug("Asked to iterate over history with NO end date; 
default to now")
-            
DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar()).toString()
-        }
+        start,
+        end
     )
+    logger.debug("${history.count()} history elements found for account 
$customerId")
     return buildCamtString(history, type)
 }
 
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 63a8561..e4338eb 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -167,16 +167,12 @@ fun sampleData() {
  * @return result set of all the operations related to the customer
  * identified by @p id.
  */
-fun extractHistory(id: Int, start: String?, end: String?): 
SizedIterable<BankTransactionEntity> {
-    val s = if (start != null) DateTime.parse(start) else DateTime(0)
-    val e = if (end != null) DateTime.parse(end) else DateTime.now()
-
-    LOGGER.debug("Fetching history from $s to $e")
-
+fun extractHistory(id: Int, start: DateTime, end: DateTime): 
SizedIterable<BankTransactionEntity> {
+    LOGGER.debug("Fetching history from ${start.toLocalDateTime()} to 
${end.toLocalDateTime()}")
     return transaction {
         addLogger(StdOutSqlLogger)
         BankTransactionEntity.find {
-            BankTransactionsTable.localCustomer eq id and 
BankTransactionsTable.valueDate.between(s.millis, e.millis)
+            BankTransactionsTable.localCustomer eq id and 
BankTransactionsTable.valueDate.between(start.millis, end.millis)
         }
     }
 }
@@ -234,7 +230,11 @@ fun main() {
                 val req = call.receive<CustomerHistoryRequest>()
                 val customer = findCustomer(call.parameters["id"])
                 val ret = CustomerHistoryResponse()
-                val history = extractHistory(customer.id.value, req.start, 
req.end)
+                val history = extractHistory(
+                    customer.id.value,
+                    DateTime.parse(req.start),
+                    DateTime(req.end)
+                )
                 transaction {
                     history.forEach {
                         ret.history.add(

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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