libeufin

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

commit 01bec0882980f72b6277a74c33fd581e5c13f25d
parent af3bc2ab7fa1cc3bc01cc310047f7373f852c3ae
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Fri, 24 Jan 2020 16:06:21 +0100

progress

Diffstat:
A.idea/jarRepositories.xml | 26++++++++++++++++++++++++++
Msandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 6++++--
Msandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt | 3++-
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 25++++++++++++++++---------
4 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RemoteRepositoriesConfiguration"> + <remote-repository> + <option name="id" value="central" /> + <option name="name" value="Maven Central repository" /> + <option name="url" value="https://repo1.maven.org/maven2" /> + </remote-repository> + <remote-repository> + <option name="id" value="jboss.community" /> + <option name="name" value="JBoss Community repository" /> + <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> + </remote-repository> + <remote-repository> + <option name="id" value="MavenRepo" /> + <option name="name" value="MavenRepo" /> + <option name="url" value="https://repo.maven.apache.org/maven2/" /> + </remote-repository> + <remote-repository> + <option name="id" value="BintrayJCenter" /> + <option name="name" value="BintrayJCenter" /> + <option name="url" value="https://jcenter.bintray.com/" /> + </remote-repository> + </component> +</project> +\ No newline at end of file diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -159,7 +159,8 @@ object BankTransactionsTable : IntIdTableWithAmount() { val counterpart = varchar("counterpart", MAX_ID_LENGTH) val amount = amount("amount") val subject = varchar("subject", MAX_SUBJECT_LENGTH) - val date = date("date") + val operationDate = datetime("operationDate") + val valueDate = datetime("valueDate") val localCustomer = reference("localCustomer", BankCustomersTable) } @@ -176,7 +177,8 @@ class BankTransactionEntity(id: EntityID<Int>) : IntEntity(id) { var counterpart by BankTransactionsTable.counterpart var subject by BankTransactionsTable.subject - var date by BankTransactionsTable.date + var operationDate by BankTransactionsTable.operationDate + var valueDate by BankTransactionsTable.valueDate var amount by BankTransactionsTable.amount } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt @@ -63,7 +63,8 @@ data class CustomerHistoryResponseElement( var amount: String, val subject: String, val counterpart: String, - val date: String + val operationDate: String, + val valueDate: String ) data class CustomerHistoryResponse( diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -38,6 +38,7 @@ import io.ktor.routing.post import io.ktor.routing.routing import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty +import org.jetbrains.exposed.sql.Date import org.jetbrains.exposed.sql.StdOutSqlLogger import org.jetbrains.exposed.sql.addLogger import org.jetbrains.exposed.sql.and @@ -162,7 +163,8 @@ fun sampleData() { counterpart = "IBAN" amount = i subject = "transaction $i" - date = DateTime.now() + operationDate = DateTime.now() + valueDate = DateTime.now() localCustomer = customerEntity } } @@ -170,7 +172,10 @@ fun sampleData() { } /** - * Finds the history for a customer + * Finds the history for a customer, given dates of 'value'. This date + * specifies the point in time where a operation settled. The other type + * of date is 'operation', that indicates the point in time where the + * transaction was created in the bank's system. * * @param id the customer whose history must be returned. This * id is local to the bank and is not reused/encoded into other @@ -179,15 +184,18 @@ fun sampleData() { */ fun extractHistoryForEach(id: Int, start: String?, end: String?, builder: (BankTransactionEntity) -> Any) { - LOGGER.debug("Fetching history from $start to $end") + 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") + transaction { + addLogger(StdOutSqlLogger) BankTransactionEntity.find { - BankTransactionsTable.localCustomer eq id and - BankTransactionsTable.date.between(s, e) + BankTransactionsTable.localCustomer eq id and BankTransactionsTable.valueDate.between(s, e) }.forEach { + LOGGER.debug("Found history element: $it") builder(it) } } @@ -201,7 +209,7 @@ fun calculateBalance(id: Int, start: String?, end: String?): BigDecimal { transaction { BankTransactionEntity.find { - BankTransactionsTable.localCustomer eq id and BankTransactionsTable.date.between(s, e) + BankTransactionsTable.localCustomer eq id and BankTransactionsTable.operationDate.between(s, e) }.forEach { ret += it.amount } } return ret @@ -246,8 +254,6 @@ fun main() { post("/{id}/history") { val req = call.receive<CustomerHistoryRequest>() - LOGGER.debug("Fetching history from ${req.start}, to ${req.end}") - val customer = findCustomer(call.parameters["id"]) val ret = CustomerHistoryResponse() @@ -257,7 +263,8 @@ fun main() { subject = it.subject, amount = "${it.amount.signToString()}${it.amount} EUR", counterpart = it.counterpart, - date = it.date.toString("Y-M-d") + operationDate = it.operationDate.toString("Y-M-d"), + valueDate = it.operationDate.toString("Y-M-d") ) ) }