From 41a343421db230b2786389ffccedb07362d10375 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 13 Oct 2019 13:12:18 +0200 Subject: [PATCH] Added AccountData to CustomerData --- .../kotlin/net/dankito/fints/FinTsClient.kt | 34 +++++++++++++++++-- .../net/dankito/fints/model/AccountData.kt | 25 ++++++++++++++ .../net/dankito/fints/model/CustomerData.kt | 1 + .../fints/response/segments/AccountInfo.kt | 2 +- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index f2f79c50..aead256e 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -224,11 +224,26 @@ open class FinTsClient( } response.getFirstSegmentById(InstituteSegmentId.AccountInfo)?.let { accountInfo -> - customer.iban = accountInfo.iban + customer.iban = accountInfo.iban // TODO: remove and use that one from AccountData - customer.name = accountInfo.accountHolderName1 + var accountHolderName = accountInfo.accountHolderName1 accountInfo.accountHolderName2?.let { - customer.name = customer.name + it // TODO: add a whitespace in between? + accountHolderName += it // TODO: add a whitespace in between? + } + customer.name = accountHolderName + + findExistingAccount(customer, accountInfo)?.let { account -> + // TODO: update AccountData. But can this ever happen that an account changes? + } + ?: run { + val newAccount = AccountData(accountInfo.accountIdentifier, accountInfo.subAccountAttribute, + accountInfo.bankCountryCode, accountInfo.bankCode, accountInfo.iban, accountInfo.customerId, + accountInfo.accountType, accountInfo.currency, accountHolderName, accountInfo.productName, + accountInfo.accountLimit, accountInfo.allowedJobNames) + + val accounts = customer.accounts.toMutableList() + accounts.add(newAccount) + customer.accounts = accounts } // TODO: may also make use of other info @@ -247,4 +262,17 @@ open class FinTsClient( } } + protected open fun findExistingAccount(customer: CustomerData, accountInfo: AccountInfo): AccountData? { + customer.accounts.forEach { account -> + if (account.accountIdentifier == accountInfo.accountIdentifier + && account.productName == accountInfo.productName + && account.accountType == accountInfo.accountType) { + + return account + } + } + + return null + } + } \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt new file mode 100644 index 00000000..80f3efda --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt @@ -0,0 +1,25 @@ +package net.dankito.fints.model + +import net.dankito.fints.response.segments.AccountType + + +open class AccountData( + val accountIdentifier: String, + val subAccountAttribute: String?, + val bankCountryCode: Int, + val bankCode: String, + val iban: String?, + val customerId: String, + val accountType: AccountType?, + val currency: String?, // TODO: may parse to a value object + val accountHolderName: String, + val productName: String?, + val accountLimit: String?, + val allowedJobNames: List +) { + + override fun toString(): String { + return "$productName $accountIdentifier $accountHolderName" + } + +} \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/CustomerData.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/CustomerData.kt index ac271f8e..d5162207 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/CustomerData.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/CustomerData.kt @@ -11,6 +11,7 @@ open class CustomerData( val userId: String = customerId, var name: String = "", var iban: String? = null, + var accounts: List = listOf(), var updVersion: Int = UPDVersion.VersionNotReceivedYet, var availableTanProcedures: List = listOf(), var selectedTanProcedure: TanProcedure? = null, diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt index 80d9bb1f..ad1c2536 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/AccountInfo.kt @@ -2,7 +2,7 @@ package net.dankito.fints.response.segments open class AccountInfo( - val accountNumber: String, + val accountIdentifier: String, val subAccountAttribute: String?, val bankCountryCode: Int, val bankCode: String,