commit a9b19b40109ff361498439025780f105ccecaaf5
parent c3b1631fecedb5c72cb4688dde731603dde13d10
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 13 Feb 2020 18:28:22 +0100
Not allowing multiple bank account with same id.
Diffstat:
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
@@ -56,17 +56,16 @@ const val ID_MAX_LENGTH = 50
//
//}
-object EbicsAccountsInfoTable : IntIdTable() {
- val accountId = text("accountId")
+object EbicsAccountsInfoTable : 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")
}
-class EbicsAccountInfoEntity(id: EntityID<Int>) : IntEntity(id) {
- companion object : IntEntityClass<EbicsAccountInfoEntity>(EbicsAccountsInfoTable)
- var accountId by EbicsAccountsInfoTable.accountId
+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
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -112,7 +112,7 @@ fun getSubscriberEntityFromId(id: String): EbicsSubscriberEntity {
fun getBankAccountDetailsFromAcctid(id: String): EbicsAccountInfoElement {
return transaction {
val bankAccount = EbicsAccountInfoEntity.find {
- EbicsAccountsInfoTable.accountId eq id
+ EbicsAccountsInfoTable.id eq id
}.firstOrNull() ?: throw BankAccountNotFoundError(HttpStatusCode.NotFound)
EbicsAccountInfoElement(
accountId = id,
@@ -329,7 +329,7 @@ fun main() {
accountHolderName = it.accountHolder,
iban = it.iban,
bankCode = it.bankCode,
- accountId = it.accountId
+ accountId = it.id.value
)
)
}
@@ -964,9 +964,8 @@ fun main() {
val payload = XMLUtil.convertStringToJaxb<HTDResponseOrderData>(response.orderData.toString(Charsets.UTF_8))
transaction {
payload.value.partnerInfo.accountInfoList?.forEach {
- EbicsAccountInfoEntity.new {
+ EbicsAccountInfoEntity.new(id = it.id) {
this.subscriber = getSubscriberEntityFromId(customerIdAtNexus)
- accountId = it.id
accountHolder = it.accountHolder
iban = when (it.accountNumberList?.get(0)) {
is EbicsTypes.GeneralAccountNumber -> {