Implemented returning default / unsuccessful RetrievedAccountData also for accounts that do not support retrieving transactions or balance

This commit is contained in:
dankito 2020-09-22 18:39:32 +02:00
parent d420cfcfb2
commit 7d8d1eb6d0
1 changed files with 10 additions and 10 deletions

View File

@ -298,24 +298,24 @@ open class FinTsClient(
protected open fun addAccountGetAccountBalancesAndTransactions(bank: BankData, newUserInfoResponse: BankResponse, protected open fun addAccountGetAccountBalancesAndTransactions(bank: BankData, newUserInfoResponse: BankResponse,
didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
callback: (AddAccountResponse) -> Unit) { callback: (AddAccountResponse) -> Unit) {
// TODO: or add a default RetrievedAccountData instance for each account?
val retrievedAccountData = mutableListOf<RetrievedAccountData>()
val accountSupportingRetrievingTransactions = bank.accounts.filter { it.supportsFeature(AccountFeature.RetrieveBalance) || it.supportsFeature(AccountFeature.RetrieveAccountTransactions) } val retrievedAccountData = bank.accounts.associateBy( { it }, { RetrievedAccountData.unsuccessful(it) } ).toMutableMap()
val countAccountSupportingRetrievingTransactions = accountSupportingRetrievingTransactions.size
val accountsSupportingRetrievingTransactions = bank.accounts.filter { it.supportsFeature(AccountFeature.RetrieveBalance) || it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }
val countAccountsSupportingRetrievingTransactions = accountsSupportingRetrievingTransactions.size
var countRetrievedAccounts = 0 var countRetrievedAccounts = 0
if (countAccountSupportingRetrievingTransactions == 0) { if (countAccountsSupportingRetrievingTransactions == 0) {
addAccountAfterRetrievingTransactions(bank, newUserInfoResponse, didOverwriteUserUnselectedTanMethod, addAccountAfterRetrievingTransactions(bank, newUserInfoResponse, didOverwriteUserUnselectedTanMethod,
originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback) originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback)
} }
accountSupportingRetrievingTransactions.forEach { account -> accountsSupportingRetrievingTransactions.forEach { account ->
tryGetTransactionsOfLast90DaysWithoutTan(bank, account) { response -> tryGetTransactionsOfLast90DaysWithoutTan(bank, account) { response ->
retrievedAccountData.addAll(response.retrievedData) retrievedAccountData.put(account, response.retrievedData.first())
countRetrievedAccounts++ countRetrievedAccounts++
if (countRetrievedAccounts == countAccountSupportingRetrievingTransactions) { if (countRetrievedAccounts == countAccountsSupportingRetrievingTransactions) {
addAccountAfterRetrievingTransactions(bank, newUserInfoResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, addAccountAfterRetrievingTransactions(bank, newUserInfoResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs,
retrievedAccountData, callback) retrievedAccountData, callback)
} }
@ -325,7 +325,7 @@ open class FinTsClient(
protected open fun addAccountAfterRetrievingTransactions(bank: BankData, newUserInfoResponse: BankResponse, protected open fun addAccountAfterRetrievingTransactions(bank: BankData, newUserInfoResponse: BankResponse,
didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
retrievedAccountData: List<RetrievedAccountData>, retrievedAccountData: Map<AccountData, RetrievedAccountData>,
callback: (AddAccountResponse) -> Unit) { callback: (AddAccountResponse) -> Unit) {
if (didOverwriteUserUnselectedTanMethod) { if (didOverwriteUserUnselectedTanMethod) {
bank.resetSelectedTanMethod() bank.resetSelectedTanMethod()
@ -333,7 +333,7 @@ open class FinTsClient(
areWeThatGentleToCloseDialogs = originalAreWeThatGentleToCloseDialogs areWeThatGentleToCloseDialogs = originalAreWeThatGentleToCloseDialogs
callback(AddAccountResponse(newUserInfoResponse, bank, retrievedAccountData)) callback(AddAccountResponse(newUserInfoResponse, bank, retrievedAccountData.values.toList()))
} }