commit 219bc3cc2dae211b18b9d6de7953e69b34fbae9e
parent 8ed318feb46099f3531bfef02b2dcf13de557b6f
Author: MS <ms@taler.net>
Date: Wed, 2 Aug 2023 12:13:09 +0200
Server side EBICS date range.
Diffstat:
3 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -27,6 +27,7 @@ import io.ktor.server.request.*
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.util.AttributeKey
+import io.ktor.util.date.*
import org.apache.xml.security.binding.xmldsig.RSAKeyValueType
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
@@ -476,20 +477,27 @@ private fun constructCamtResponse(
subscriber: EbicsSubscriberEntity,
dateRange: Pair<Long, Long>?
): List<String> {
-
if (type != 53 && type != 52) throw EbicsUnsupportedOrderType()
val bankAccount = getBankAccountFromSubscriber(subscriber)
+ val history = mutableListOf<XLibeufinBankTransaction>()
if (type == 52) {
- if (dateRange != null)
- throw EbicsOrderParamsIgnored("C52 does not support date ranges.")
- val history = mutableListOf<XLibeufinBankTransaction>()
- transaction {
- BankAccountFreshTransactionEntity.all().forEach {
- if (it.transactionRef.account.label == bankAccount.label) {
- history.add(getHistoryElementFromTransactionRow(it))
+ if (dateRange != null) {
+ transaction {
+ BankAccountTransactionEntity.find {
+ BankAccountTransactionsTable.account eq bankAccount.id and
+ BankAccountTransactionsTable.date.between(
+ dateRange.first, dateRange.second
+ )
+ }.forEach { history.add(getHistoryElementFromTransactionRow(it)) }
+ }
+ } else
+ transaction {
+ BankAccountFreshTransactionEntity.all().forEach {
+ if (it.transactionRef.account.label == bankAccount.label) {
+ history.add(getHistoryElementFromTransactionRow(it))
+ }
}
}
- }
if (history.size == 0) throw EbicsNoDownloadDataAvailable()
val camtData = buildCamtString(
type,
@@ -678,6 +686,9 @@ private fun handleCct(
)
return@transaction
}
+ /**
+ * FIXME: here call wire_transfer(), because it'll set the balances too.
+ */
val bankAccount = getBankAccountFromIban(parseResult.debtorIban)
if (parseResult.currency != bankAccount.demoBank.config.currency) throw EbicsRequestError(
"[EBICS_PROCESSING_ERROR] Currency (${parseResult.currency}) not supported.",
@@ -740,10 +751,16 @@ private fun handleCct(
* to the querying subscriber.
*/
private fun handleEbicsC52(requestContext: RequestContext): ByteArray {
+ val maybeDateRange = requestContext.requestObject.header.static.orderDetails?.orderParams
+ val dateRange: Pair<Long, Long>? = if (maybeDateRange is EbicsRequest.StandardOrderParams) {
+ val start: Long? = maybeDateRange.dateRange?.start?.toGregorianCalendar()?.timeInMillis
+ val end: Long? = maybeDateRange.dateRange?.end?.toGregorianCalendar()?.timeInMillis
+ Pair(start ?: 0L, end ?: getTimeMillis())
+ } else null
val report = constructCamtResponse(
52,
requestContext.subscriber,
- dateRange = null
+ dateRange = dateRange
)
sandboxAssert(
report.size == 1,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -241,8 +241,10 @@ data class HistoryParams(
val untilMs: Long,
val bankAccount: BankAccountEntity
)
+
fun extractTxHistory(params: HistoryParams): List<XLibeufinBankTransaction> {
val ret = mutableListOf<XLibeufinBankTransaction>()
+
/**
* Helper that gets transactions earlier than the 'firstElementId'
* transaction AND that match the URI parameters.
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
@@ -71,10 +71,10 @@ fun getValueFromEnv(varName: String): String? {
fun getDbConnFromEnv(varName: String): String {
val dbConnStr = System.getenv(varName)
if (dbConnStr.isNullOrBlank() or dbConnStr.isNullOrEmpty()) {
- printLnErr("\nError: DB connection string undefined or invalid in the env variable $varName.")
+ printLnErr("\nError: DB connection string undefined in the env variable $varName.")
printLnErr("\nThe following two examples are valid connection strings:")
- printLnErr("\njdbc:sqlite:/tmp/libeufindb.sqlite3")
- printLnErr("jdbc:postgresql://localhost:5432/libeufindb?user=Foo&password=secret\n")
+ printLnErr("\npostgres:///libeufindb")
+ printLnErr("postgresql://localhost:5432/libeufindb?user=Foo&password=secret\n")
exitProcess(1)
}
return dbConnStr