commit c4e54a7a4fd7cbea1a0524a505df5169c5fd1103
parent 520a29af74788aadd34dd878c9b2a2347e166a8a
Author: Marcello Stanisci <ms@taler.net>
Date: Mon, 27 Apr 2020 17:48:41 +0200
DB table names.
Rename table that stores triples
<iban,bic,account-holder-name> to a more generic name.
Diffstat:
7 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
- <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK" />
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -42,9 +42,8 @@ class TalerRequestedPaymentEntity(id: EntityID<Long>) : LongEntity(id) {
}
/**
- * This table "augments" the information given in the raw payments table, with Taler-related
- * ones. It tells if a payment is valid and/or it was refunded already. And moreover, it is
- * the table whose ("clean") IDs the exchange will base its history requests on.
+ * This is the table of the incoming payments. Entries are merely "pointers" to the
+ * entries from the raw payments table. Fixme: name should end with "-table".
*/
object TalerIncomingPayments: LongIdTable() {
val payment = reference("payment", RawBankTransactionsTable)
@@ -162,20 +161,20 @@ class Pain001Entity(id: EntityID<Int>) : IntEntity(id) {
var invalid by Pain001Table.invalid
}
-object EbicsAccountsInfoTable : IdTable<String>() {
+object BankAccountsTable : IdTable<String>() {
override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey()
val subscriber = reference("subscriber", EbicsSubscribersTable)
val accountHolder = text("accountHolder").nullable()
val iban = text("iban")
- val bankCode = text("bankCode")
+ val bankCode = text("bankCode")
}
-class EbicsAccountInfoEntity(id: EntityID<String>) : Entity<String>(id) {
- companion object : EntityClass<String, EbicsAccountInfoEntity>(EbicsAccountsInfoTable)
- var subscriber by EbicsSubscriberEntity referencedOn EbicsAccountsInfoTable.subscriber
- var accountHolder by EbicsAccountsInfoTable.accountHolder
- var iban by EbicsAccountsInfoTable.iban
- var bankCode by EbicsAccountsInfoTable.bankCode
+class BankAccountEntity(id: EntityID<String>) : Entity<String>(id) {
+ companion object : EntityClass<String, BankAccountEntity>(BankAccountsTable)
+ var subscriber by EbicsSubscriberEntity referencedOn BankAccountsTable.subscriber
+ var accountHolder by BankAccountsTable.accountHolder
+ var iban by BankAccountsTable.iban
+ var bankCode by BankAccountsTable.bankCode
}
object EbicsSubscribersTable : IdTable<String>() {
@@ -216,7 +215,7 @@ fun dbCreateTables() {
SchemaUtils.create(
Pain001Table,
EbicsSubscribersTable,
- EbicsAccountsInfoTable,
+ BankAccountsTable,
RawBankTransactionsTable,
TalerIncomingPayments,
TalerRequestedPayments
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -73,11 +73,11 @@ fun expectLong(param: String?): Long? {
}
/* Needs a transaction{} block to be called */
-fun expectAcctidTransaction(param: String?): EbicsAccountInfoEntity {
+fun expectAcctidTransaction(param: String?): BankAccountEntity {
if (param == null) {
throw NexusError(HttpStatusCode.BadRequest, "Null Acctid given")
}
- return EbicsAccountInfoEntity.findById(param) ?: throw NexusError(HttpStatusCode.NotFound, "Account: $param not found")
+ return BankAccountEntity.findById(param) ?: throw NexusError(HttpStatusCode.NotFound, "Account: $param not found")
}
/**
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -120,15 +120,15 @@ data class EbicsErrorJson(
val error: EbicsErrorDetailJson
)
-data class EbicsAccountInfoElement(
+data class BankAccountInfoElement(
var accountHolderName: String? = null,
var iban: String,
var bankCode: String,
var accountId: String
)
-data class EbicsAccountsInfoResponse(
- var accounts: MutableList<EbicsAccountInfoElement> = mutableListOf()
+data class BankAccountsInfoResponse(
+ var accounts: MutableList<BankAccountInfoElement> = mutableListOf()
)
data class PaymentInfoElement(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -142,7 +142,7 @@ fun extractFirstBic(bankCodes: List<EbicsTypes.AbstractBankCode>?): String? {
fun getSubscriberDetailsFromBankAccount(bankAccountId: String): EbicsClientSubscriberDetails {
return transaction {
- val accountInfo = EbicsAccountInfoEntity.findById(bankAccountId) ?: throw NexusError(HttpStatusCode.NotFound, "Bank account ($bankAccountId) not managed by Nexus")
+ val accountInfo = BankAccountEntity.findById(bankAccountId) ?: throw NexusError(HttpStatusCode.NotFound, "Bank account ($bankAccountId) not managed by Nexus")
logger.debug("Mapping bank account: ${bankAccountId}, to customer: ${accountInfo.subscriber.id.value}")
getSubscriberDetailsFromId(accountInfo.subscriber.id.value)
}
@@ -154,11 +154,11 @@ fun getSubscriberDetailsFromBankAccount(bankAccountId: String): EbicsClientSubsc
* @return the query set containing the subscriber's bank accounts. The result
* is guaranteed not to be empty.
*/
-fun getBankAccountsInfoFromId(id: String): SizedIterable<EbicsAccountInfoEntity> {
+fun getBankAccountsInfoFromId(id: String): SizedIterable<BankAccountEntity> {
logger.debug("Looking up bank account of user '$id'")
val list = transaction {
- EbicsAccountInfoEntity.find {
- EbicsAccountsInfoTable.subscriber eq id
+ BankAccountEntity.find {
+ BankAccountsTable.subscriber eq id
}
}
if (list.empty()) {
@@ -281,13 +281,13 @@ fun createPain001document(pain001Entity: Pain001Entity): String {
}
element("DbtrAcct/Id/IBAN") {
text(transaction {
- EbicsAccountInfoEntity.findById(pain001Entity.debtorAccount)?.iban ?: throw NexusError(HttpStatusCode.NotFound,"Debtor IBAN not found in database")
+ BankAccountEntity.findById(pain001Entity.debtorAccount)?.iban ?: throw NexusError(HttpStatusCode.NotFound,"Debtor IBAN not found in database")
})
}
element("DbtrAgt/FinInstnId/BIC") {
text(transaction {
- EbicsAccountInfoEntity.findById(pain001Entity.debtorAccount)?.bankCode ?: throw NexusError(HttpStatusCode.NotFound,"Debtor BIC not found in database")
+ BankAccountEntity.findById(pain001Entity.debtorAccount)?.bankCode ?: throw NexusError(HttpStatusCode.NotFound,"Debtor BIC not found in database")
})
}
element("ChrgBr") {
@@ -478,13 +478,13 @@ fun main() {
get("/ebics/subscribers/{id}/accounts") {
// this information is only avaiable *after* HTD or HKD has been called
val id = expectId(call.parameters["id"])
- val ret = EbicsAccountsInfoResponse()
+ val ret = BankAccountsInfoResponse()
transaction {
- EbicsAccountInfoEntity.find {
- EbicsAccountsInfoTable.subscriber eq id
+ BankAccountEntity.find {
+ BankAccountsTable.subscriber eq id
}.forEach {
ret.accounts.add(
- EbicsAccountInfoElement(
+ BankAccountInfoElement(
accountHolderName = it.accountHolder,
iban = it.iban,
bankCode = it.bankCode,
@@ -530,8 +530,8 @@ fun main() {
val id = expectId(call.parameters["id"])
val ret = PaymentsInfo()
transaction {
- EbicsAccountInfoEntity.find {
- EbicsAccountsInfoTable.subscriber eq id
+ BankAccountEntity.find {
+ BankAccountsTable.subscriber eq id
}.forEach {
Pain001Entity.find {
Pain001Table.debtorAccount eq it.id.value
@@ -1340,7 +1340,7 @@ fun main() {
val payload = XMLUtil.convertStringToJaxb<HTDResponseOrderData>(response.orderData.toString(Charsets.UTF_8))
transaction {
payload.value.partnerInfo.accountInfoList?.forEach {
- EbicsAccountInfoEntity.new(id = it.id) {
+ BankAccountEntity.new(id = it.id) {
this.subscriber = getSubscriberEntityFromId(customerIdAtNexus)
accountHolder = it.accountHolder
iban = extractFirstIban(it.accountNumberList) ?: throw NexusError(HttpStatusCode.NotFound, reason = "bank gave no IBAN")
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -538,8 +538,8 @@ class Taler(app: Route) {
*/
if (! isProduction()) {
val EXCHANGE_BANKACCOUNT_ID = "exchange-bankaccount-id"
- if (EbicsAccountInfoEntity.findById(EXCHANGE_BANKACCOUNT_ID) == null) {
- EbicsAccountInfoEntity.new(id = EXCHANGE_BANKACCOUNT_ID) {
+ if (BankAccountEntity.findById(EXCHANGE_BANKACCOUNT_ID) == null) {
+ BankAccountEntity.new(id = EXCHANGE_BANKACCOUNT_ID) {
subscriber = getSubscriberEntityFromId(exchangeId)
accountHolder = "Test Exchange"
iban = "42"
diff --git a/nexus/src/test/kotlin/PainGeneration.kt b/nexus/src/test/kotlin/PainGeneration.kt
@@ -20,7 +20,7 @@ class PainTest {
Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver")
transaction {
SchemaUtils.create(EbicsSubscribersTable)
- SchemaUtils.create(EbicsAccountsInfoTable)
+ SchemaUtils.create(BankAccountsTable)
SchemaUtils.create(Pain001Table)
val subscriberEntity = EbicsSubscriberEntity.new(id = "123asdf-0") {
@@ -33,7 +33,7 @@ class PainTest {
authenticationPrivateKey = SerialBlob("authenticationPrivateKey".toByteArray())
encryptionPrivateKey = SerialBlob("encryptionPrivateKey".toByteArray())
}
- EbicsAccountInfoEntity.new(id = "acctid") {
+ BankAccountEntity.new(id = "acctid") {
subscriber = subscriberEntity
accountHolder = "Account Holder"
iban = "IBAN"