libeufin

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

commit 1610d8ada82608f70b3e821d5519639bdc0f42c5
parent 508e2b3a25d167af3b6f751949a6e867bd4f4164
Author: MS <ms@taler.net>
Date:   Wed, 13 Jan 2021 10:44:28 +0100

Retrieving facade details from other table

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt | 4++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 39++++++++++++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 3 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 @@ -322,7 +322,8 @@ data class BankMessageInfo( data class FacadeShowInfo( val name: String, val type: String, - val baseUrl: String + val baseUrl: String, + val config: JsonNode ) data class FacadeInfo( @@ -364,7 +365,6 @@ data class AccountTask( 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 @@ -69,6 +69,25 @@ import java.net.URLEncoder import java.nio.file.Paths import java.util.zip.InflaterInputStream +// Return facade state depending on the type. +fun getFacadeState(type: String, facade: FacadeEntity): JsonNode { + return transaction { + when (type) { + "taler-wire-gateway" -> { + val state = TalerFacadeStateEntity.find { + TalerFacadeStateTable.facade eq facade.id + }.firstOrNull() + if (state == null) throw NexusError(HttpStatusCode.NotFound,"State of facade ${facade.id} not found") + val node = jacksonObjectMapper().createObjectNode() + node.put("bankConnection", state.bankConnection) + node.put("bankAccount", state.bankAccount) + node + } + else -> throw NexusError(HttpStatusCode.NotFound,"Facade type ${type} not supported") + } + } +} + fun ensureNonNull(param: String?): String { return param ?: throw NexusError( @@ -854,6 +873,23 @@ fun serverMain(dbName: String, host: String, port: Int) { call.respondBytes(ret.msgContent, ContentType("application", "xml")) } + get("/facades/{fcid}") { + val fcid = ensureNonNull(call.parameters["fcid"]) + val ret = transaction { + val f = FacadeEntity.findById(fcid) ?: throw NexusError( + HttpStatusCode.NotFound, "Facade ${fcid} does not exist" + ) + FacadeShowInfo( + name = f.id.value, + type = f.type, + baseUrl = "http://${host}/facades/${f.id.value}/${f.type}/", + config = getFacadeState(f.type, f) + ) + } + call.respond(ret) + return@get + } + get("/facades") { val ret = object { val facades = mutableListOf<FacadeShowInfo>() } transaction { @@ -865,7 +901,8 @@ fun serverMain(dbName: String, host: String, port: Int) { FacadeShowInfo( name = it.id.value, type = it.type, - baseUrl = "http://${host}/facades/${it.id.value}/${it.type}/" + baseUrl = "http://${host}/facades/${it.id.value}/${it.type}/", + config = getFacadeState(it.type, it) ) ) }