gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/03: address warnings


From: gnunet
Subject: [libeufin] 01/03: address warnings
Date: Fri, 22 Jan 2021 17:41:45 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

commit 401c7ce24a0b1589bfbc05c5fa6e6951ddba6826
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Jan 22 17:36:15 2021 +0100

    address warnings
---
 build-system/taler-build-scripts                   |  2 +-
 .../kotlin/tech/libeufin/nexus/JsonLiterals.kt     | 42 ++++++++++++++++++++++
 .../tech/libeufin/nexus/bankaccount/BankAccount.kt |  8 +++--
 .../kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt |  2 +-
 .../tech/libeufin/nexus/server/NexusServer.kt      | 40 +++++++--------------
 parsing-tests/samples                              |  2 +-
 6 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/build-system/taler-build-scripts b/build-system/taler-build-scripts
index e08ea37..47f14fc 160000
--- a/build-system/taler-build-scripts
+++ b/build-system/taler-build-scripts
@@ -1 +1 @@
-Subproject commit e08ea37979dcc17ac8e0987251771d771503cb56
+Subproject commit 47f14fcf1d03d9dad1bae59987488ea05ecd307b
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 0000000..cd89e01
--- /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 3d86449..8222355 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 2f2791b..50e13fe 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 7d4e368..9e2fab7 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,
diff --git a/parsing-tests/samples b/parsing-tests/samples
index 63f075c..4e36caa 160000
--- a/parsing-tests/samples
+++ b/parsing-tests/samples
@@ -1 +1 @@
-Subproject commit 63f075c6f61173f4ee68c39b30d860fd20a299dc
+Subproject commit 4e36caa0b9557d7446488d7eec7c80e6f1e554ac

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]