From 7d8d1eb6d0f109a27e28b3ccbaf682eb347a88b2 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 22 Sep 2020 18:39:32 +0200 Subject: [PATCH] Implemented returning default / unsuccessful RetrievedAccountData also for accounts that do not support retrieving transactions or balance --- .../net/dankito/banking/fints/FinTsClient.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index e7acb726..9cba6017 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -298,24 +298,24 @@ open class FinTsClient( protected open fun addAccountGetAccountBalancesAndTransactions(bank: BankData, newUserInfoResponse: BankResponse, didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, callback: (AddAccountResponse) -> Unit) { - // TODO: or add a default RetrievedAccountData instance for each account? - val retrievedAccountData = mutableListOf() - val accountSupportingRetrievingTransactions = bank.accounts.filter { it.supportsFeature(AccountFeature.RetrieveBalance) || it.supportsFeature(AccountFeature.RetrieveAccountTransactions) } - val countAccountSupportingRetrievingTransactions = accountSupportingRetrievingTransactions.size + val retrievedAccountData = bank.accounts.associateBy( { it }, { RetrievedAccountData.unsuccessful(it) } ).toMutableMap() + + val accountsSupportingRetrievingTransactions = bank.accounts.filter { it.supportsFeature(AccountFeature.RetrieveBalance) || it.supportsFeature(AccountFeature.RetrieveAccountTransactions) } + val countAccountsSupportingRetrievingTransactions = accountsSupportingRetrievingTransactions.size var countRetrievedAccounts = 0 - if (countAccountSupportingRetrievingTransactions == 0) { + if (countAccountsSupportingRetrievingTransactions == 0) { addAccountAfterRetrievingTransactions(bank, newUserInfoResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback) } - accountSupportingRetrievingTransactions.forEach { account -> + accountsSupportingRetrievingTransactions.forEach { account -> tryGetTransactionsOfLast90DaysWithoutTan(bank, account) { response -> - retrievedAccountData.addAll(response.retrievedData) + retrievedAccountData.put(account, response.retrievedData.first()) countRetrievedAccounts++ - if (countRetrievedAccounts == countAccountSupportingRetrievingTransactions) { + if (countRetrievedAccounts == countAccountsSupportingRetrievingTransactions) { addAccountAfterRetrievingTransactions(bank, newUserInfoResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback) } @@ -325,7 +325,7 @@ open class FinTsClient( protected open fun addAccountAfterRetrievingTransactions(bank: BankData, newUserInfoResponse: BankResponse, didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, - retrievedAccountData: List, + retrievedAccountData: Map, callback: (AddAccountResponse) -> Unit) { if (didOverwriteUserUnselectedTanMethod) { bank.resetSelectedTanMethod() @@ -333,7 +333,7 @@ open class FinTsClient( areWeThatGentleToCloseDialogs = originalAreWeThatGentleToCloseDialogs - callback(AddAccountResponse(newUserInfoResponse, bank, retrievedAccountData)) + callback(AddAccountResponse(newUserInfoResponse, bank, retrievedAccountData.values.toList())) }