diff options
author | Florian Dold <florian@dold.me> | 2021-01-22 17:36:15 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-01-22 17:36:15 +0100 |
commit | 401c7ce24a0b1589bfbc05c5fa6e6951ddba6826 (patch) | |
tree | 32778a9a4efc387c9aacfbcdd0edffcdda53785b /nexus | |
parent | d6f9f6c931522fe57e7a7e0029235c8f1b4d454e (diff) | |
download | libeufin-401c7ce24a0b1589bfbc05c5fa6e6951ddba6826.tar.gz libeufin-401c7ce24a0b1589bfbc05c5fa6e6951ddba6826.tar.bz2 libeufin-401c7ce24a0b1589bfbc05c5fa6e6951ddba6826.zip |
address warnings
Diffstat (limited to 'nexus')
4 files changed, 62 insertions, 30 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JsonLiterals.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JsonLiterals.kt new file mode 100644 index 00000000..cd89e011 --- /dev/null +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JsonLiterals.kt @@ -0,0 +1,42 @@ +/* + * This file is part of LibEuFin. + * Copyright (C) 2021 Taler Systems S.A. + + * LibEuFin is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3, or + * (at your option) any later version. + + * LibEuFin is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + + * You should have received a copy of the GNU Affero General Public + * License along with LibEuFin; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/> + */ + +package tech.libeufin.nexus + +import com.fasterxml.jackson.databind.node.ObjectNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper + +class JsonObjectMaker(val obj: ObjectNode) { + fun prop(key: String, value: String?) { + obj.put(key, value) + } + fun prop(key: String, value: Long?) { + obj.put(key, value) + } + fun prop(key: String, value: Int?) { + obj.put(key, value) + } +} + +fun makeJsonObject(f: JsonObjectMaker.() -> Unit): ObjectNode { + val mapper = jacksonObjectMapper() + val obj = mapper.createObjectNode() + f(JsonObjectMaker(obj)) + return obj +}
\ No newline at end of file diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt index 3d864493..82223554 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -83,9 +83,13 @@ suspend fun submitAllPaymentInitiations(httpClient: HttpClient, accountid: Strin logger.debug("auto-submitter started") val workQueue = mutableListOf<Submission>() transaction { - val account = NexusBankAccountEntity.findByName(accountid) + val account = NexusBankAccountEntity.findByName(accountid) ?: throw NexusError( + HttpStatusCode.NotFound, + "account not found" + ) PaymentInitiationEntity.find { - PaymentInitiationsTable.submitted eq false + (PaymentInitiationsTable.submitted eq false) and ( + PaymentInitiationsTable.bankAccount eq account.id) }.forEach { val defaultBankConnectionId = it.bankAccount.defaultBankConnection?.id ?: throw NexusError( HttpStatusCode.BadRequest, diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt index 2f2791b8..50e13fe2 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -97,7 +97,7 @@ suspend fun fetchEbicsBySpec( val specs = mutableListOf<EbicsFetchSpec>() fun addForLevel(l: FetchLevel, p: EbicsOrderParams) { - when (fetchSpec.level) { + when (l) { FetchLevel.ALL -> { specs.add(EbicsFetchSpec("C52", p)) specs.add(EbicsFetchSpec("C53", p)) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt index 7d4e368e..9e2fab70 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -42,15 +42,9 @@ import io.ktor.util.* import io.ktor.util.pipeline.* import io.ktor.utils.io.* import org.jetbrains.exposed.sql.and -import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction import org.slf4j.event.Level import tech.libeufin.nexus.* -import tech.libeufin.nexus.OfferedBankAccountsTable.accountHolder -import tech.libeufin.nexus.OfferedBankAccountsTable.bankCode -import tech.libeufin.nexus.OfferedBankAccountsTable.iban -import tech.libeufin.nexus.OfferedBankAccountsTable.imported -import tech.libeufin.nexus.OfferedBankAccountsTable.offeredAccountId import tech.libeufin.nexus.bankaccount.* import tech.libeufin.nexus.ebics.* import tech.libeufin.nexus.iso20022.CamtBankAccountEntry @@ -139,7 +133,7 @@ fun requireValidResourceName(name: String): String { suspend inline fun <reified T : Any> ApplicationCall.receiveJson(): T { try { - return this.receive<T>() + return this.receive() } catch (e: MissingKotlinParameterException) { throw NexusError(HttpStatusCode.BadRequest, "Missing value for ${e.pathReference}") } catch (e: MismatchedInputException) { @@ -256,8 +250,8 @@ fun serverMain(dbName: String, host: String, port: Int) { routing { get("/config") { call.respond( - object { - val version = getVersion() + makeJsonObject { + prop("version", getVersion()) } ) return@get @@ -304,7 +298,7 @@ fun serverMain(dbName: String, host: String, port: Int) { when (req.action) { PermissionChangeAction.GRANT -> { if (existingPerm == null) { - NexusPermissionEntity.new() { + NexusPermissionEntity.new { subjectType = req.permission.subjectType subjectId = req.permission.subjectId resourceType = req.permission.resourceType @@ -422,7 +416,6 @@ fun serverMain(dbName: String, host: String, port: Int) { t.put("type", it.taskType) t.set<JsonNode>("params", jacksonObjectMapper().readTree(it.taskParams)) } - Unit } call.respond(resp) return@get @@ -434,7 +427,7 @@ fun serverMain(dbName: String, host: String, port: Int) { val accountId = ensureNonNull(call.parameters["accountid"]) transaction { authenticateRequest(call.request) - val bankAccount = NexusBankAccountEntity.findByName(accountId) + NexusBankAccountEntity.findByName(accountId) ?: throw NexusError(HttpStatusCode.NotFound, "unknown bank account") try { NexusCron.parser.parse(schedSpec.cronspec) @@ -444,9 +437,8 @@ fun serverMain(dbName: String, host: String, port: Int) { // sanity checks. when (schedSpec.type) { "fetch" -> { - val fetchSpec = - jacksonObjectMapper().treeToValue(schedSpec.params, FetchSpecJson::class.java) - ?: throw NexusError(HttpStatusCode.BadRequest, "bad fetch spec") + jacksonObjectMapper().treeToValue(schedSpec.params, FetchSpecJson::class.java) + ?: throw NexusError(HttpStatusCode.BadRequest, "bad fetch spec") } "submit" -> { } @@ -526,15 +518,14 @@ fun serverMain(dbName: String, host: String, port: Int) { requireSuperuser(call.request) val accountId = ensureNonNull(call.parameters["accountid"]) val res = transaction { - val user = authenticateRequest(call.request) val bankAccount = NexusBankAccountEntity.findByName(accountId) if (bankAccount == null) { throw NexusError(HttpStatusCode.NotFound, "unknown bank account") } val holderEnc = URLEncoder.encode(bankAccount.accountHolder, "UTF-8") - return@transaction object { - val defaultBankConnection = bankAccount.defaultBankConnection?.id?.value - val accountPaytoUri = "payto://iban/${bankAccount.iban}?receiver-name=$holderEnc" + return@transaction makeJsonObject { + prop("defaultBankConnection", bankAccount.defaultBankConnection?.id?.value) + prop("accountPaytoUri", "payto://iban/${bankAccount.iban}?receiver-name=$holderEnc") } } call.respond(res) @@ -598,7 +589,6 @@ fun serverMain(dbName: String, host: String, port: Int) { get("/bank-accounts/{accountid}/payment-initiations/{uuid}") { requireSuperuser(call.request) val res = transaction { - val user = authenticateRequest(call.request) val paymentInitiation = getPaymentInitiation(ensureLong(call.parameters["uuid"])) return@transaction object { val paymentInitiation = paymentInitiation @@ -669,7 +659,6 @@ fun serverMain(dbName: String, host: String, port: Int) { "Account id missing" ) } - val user = transaction { authenticateRequest(call.request) } val fetchSpec = if (call.request.hasBody()) { call.receive<FetchSpecJson>() } else { @@ -679,8 +668,8 @@ fun serverMain(dbName: String, host: String, port: Int) { ) } val newTransactions = fetchBankAccountTransactions(client, fetchSpec, accountid) - call.respond(object { - val newTransactions = newTransactions + call.respond(makeJsonObject { + prop("newTransactions", newTransactions) }) return@post } @@ -689,8 +678,6 @@ fun serverMain(dbName: String, host: String, port: Int) { get("/bank-accounts/{accountid}/transactions") { requireSuperuser(call.request) val bankAccountId = expectNonNull(call.parameters["accountid"]) - val start = call.request.queryParameters["start"] - val end = call.request.queryParameters["end"] val ret = Transactions() transaction { authenticateRequest(call.request) @@ -794,7 +781,6 @@ fun serverMain(dbName: String, host: String, port: Int) { get("/bank-connections/{connectionName}") { requireSuperuser(call.request) val resp = transaction { - val user = authenticateRequest(call.request) val conn = requireBankConnection(call, "connectionName") when (conn.type) { "ebics" -> { @@ -905,7 +891,7 @@ fun serverMain(dbName: String, host: String, port: Int) { val fcid = ensureNonNull(call.parameters["fcid"]) val ret = transaction { val f = FacadeEntity.findByName(fcid) ?: throw NexusError( - HttpStatusCode.NotFound, "Facade ${fcid} does not exist" + HttpStatusCode.NotFound, "Facade $fcid does not exist" ) FacadeShowInfo( name = f.facadeName, |