libeufin

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

commit e1e7997a52755917c2ce1e9a7250e6b3c0cd6196
parent 9632ba7c7d358fc714c1cc65af1a9b9fcf054f88
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 13 Feb 2020 13:41:11 +0100

avoid git status

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/Db.kt | 2+-
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 25++++++++++++++-----------
2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt @@ -58,7 +58,7 @@ const val ID_MAX_LENGTH = 50 object EbicsAccountsInfoTable : IntIdTable() { val accountId = text("accountId") - val subscriber = reference("subscriber", EbicsSubscribersTable) + val subscriber = reference("subscriberId", EbicsSubscribersTable) val accountHolder = text("accountHolder").nullable() val iban = text("iban") val bankCode = text("bankCode") diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -41,6 +41,7 @@ import io.ktor.server.netty.Netty import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import org.apache.commons.compress.archivers.zip.ZipFile import org.apache.commons.compress.utils.SeekableInMemoryByteChannel +import org.jetbrains.exposed.dao.EntityID import org.jetbrains.exposed.exceptions.ExposedSQLException import org.jetbrains.exposed.sql.StdOutSqlLogger import org.jetbrains.exposed.sql.addLogger @@ -98,6 +99,14 @@ data class BankInvalidResponse(val statusCode: HttpStatusCode) : Exception("Miss val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus") +fun getSubscriberEntityFromId(id: String): EbicsSubscriberEntity { + return transaction { + EbicsSubscriberEntity.findById(id) ?: throw SubscriberNotFoundError( + HttpStatusCode.NotFound + ) + } +} + fun getSubscriberDetailsFromId(id: String): EbicsClientSubscriberDetails { return transaction { val subscriber = EbicsSubscriberEntity.findById( @@ -297,7 +306,7 @@ fun main() { val ret = EbicsAccountsInfoResponse() transaction { EbicsAccountInfoEntity.find { - EbicsAccountsInfoTable.subscriber eq id + EbicsAccountsInfoTable.subscriberId eq id }.forEach { ret.accounts.add( EbicsAccountInfoElement( @@ -433,20 +442,14 @@ fun main() { when (response) { is EbicsDownloadSuccessResult -> { val payload = XMLUtil.convertStringToJaxb<HTDResponseOrderData>(response.orderData.toString(Charsets.UTF_8)) - if (null == payload.value.partnerInfo.accountInfoList) { - throw Exception( - "Inconsistent state: customers MUST have at least one bank account" - ) - } transaction { - val subscriber = EbicsSubscriberEntity.findById(customerIdAtNexus) - // FIXME: see if "!!" can be avoided - payload.value.partnerInfo.accountInfoList!!.forEach { + payload.value.partnerInfo.accountInfoList?.forEach { EbicsAccountInfoEntity.new { - this.subscriber = subscriber!! /* FIXME: Always true here, but to be avoided */ + this.subscriber = getSubscriberEntityFromId(customerIdAtNexus) accountId = it.id accountHolder = it.accountHolder - /* FIXME: how to figure out whether that's a general or national account number? */ + /* FIXME: how to figure out whether that's a general or national account number? + * This should affect the cast below */ iban = (it.accountNumberList?.get(0) as EbicsTypes.GeneralAccountNumber).value // FIXME: eventually get *all* of them bankCode = (it.bankCodeList?.get(0) as EbicsTypes.GeneralBankCode).value // FIXME: eventually get *all* of them }