libeufin

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

commit 785140724e8305d1e962d6140d10b2684bc464d3
parent da5bdc694047484fc4c60fa9afe27b43409e51f5
Author: MS <ms@taler.net>
Date:   Mon,  7 Dec 2020 16:38:54 +0100

continuing with the scheduling API

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt | 14++++++++++++++
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 53+++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt @@ -32,6 +32,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.deser.std.StdDeserializer import com.fasterxml.jackson.databind.ser.std.StdSerializer +import tech.libeufin.nexus.NexusScheduledTasksTable +import tech.libeufin.nexus.NexusScheduledTasksTable.nullable import tech.libeufin.nexus.iso20022.CamtBankAccountEntry import tech.libeufin.nexus.iso20022.CreditDebitIndicator import tech.libeufin.nexus.iso20022.EntryStatus @@ -339,6 +341,18 @@ data class Pain001Data( val subject: String ) +data class AccountTask( + val resourceType: String, + val resourceId: String, + val taskName: String, + val taskType: String, + val taskCronspec: String, + val taskParams: String, + val nextScheduledExecutionSec: Long?, // human-readable time (= Epoch when this value doesn't exist in DB) + val prevScheduledExecutionSec: Long? // human-readable time (= Epoch when this value doesn't exist in DB) +) + + data class CreateAccountTaskRequest( val name: String, val cronspec: String, diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -78,7 +78,14 @@ fun ensureNonNull(param: String?): String { fun ensureLong(param: String?): Long { val asString = ensureNonNull(param) return asString.toLongOrNull() ?: throw NexusError( - HttpStatusCode.BadRequest, "Parameter is not a number: ${param}" + HttpStatusCode.BadRequest, "Parameter is not Long: ${param}" + ) +} + +fun ensureInt(param: String?): Int { + val asString = ensureNonNull(param) + return asString.toIntOrNull() ?: throw NexusError( + HttpStatusCode.BadRequest, "Parameter is not Int: ${param}" ) } @@ -412,6 +419,29 @@ fun serverMain(dbName: String, host: String) { call.respond(resp) } + // Get all the scheduled jobs to the requester. + get("/bank-accounts/{accountid}/schedule") { + val ret = mutableListOf<AccountTask>() + transaction { + NexusScheduledTaskEntity.all().forEach { + ret.add( + AccountTask( + resourceType = it.resourceType, + resourceId = it.resourceId, + taskName = it.taskName, + taskType = it.taskType, + taskCronspec = it.taskCronspec, + taskParams = it.taskParams, + nextScheduledExecutionSec = it.nextScheduledExecutionSec, + prevScheduledExecutionSec = it.prevScheduledExecutionSec + ) + ) + } + } + call.respond(ret) + return@get + } + post("/bank-accounts/{accountid}/schedule") { val schedSpec = call.receive<CreateAccountTaskRequest>() val accountId = ensureNonNull(call.parameters["accountid"]) @@ -459,7 +489,26 @@ fun serverMain(dbName: String, host: String) { } get("/bank-accounts/{accountId}/schedule/{taskId}") { - call.respond(object { }) + val task = transaction { + NexusScheduledTaskEntity.findById(ensureInt(call.parameters["taskId"])) + } + call.respond( + if (task != null) { + AccountTask( + resourceId = task.resourceId, + resourceType = task.resourceType, + taskName = task.taskName, + taskCronspec = task.taskCronspec, + taskType = task.taskType, + taskParams = task.taskParams, + nextScheduledExecutionSec = task.nextScheduledExecutionSec, + prevScheduledExecutionSec = task.prevScheduledExecutionSec + ) + } else { + object {} + } + ) + return@get } delete("/bank-accounts/{accountId}/schedule/{taskId}") {