libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit c3da16f57bd56860a604f9b92ce118ce67e61007
parent bafc34599d430d11e0b18d22fac1e5654cc39ec8
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Tue, 17 Mar 2020 18:11:51 +0100

shortening time conversions..

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 23++++++++++-------------
Msandbox/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 @@ -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 @@ -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(