From 6f354724be0ecf525603fdc7ceb078f3b086bad2 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 14 Sep 2020 01:00:09 +0200 Subject: [PATCH] Fixed that when an account gets deleting its BankingClient data didn't get deleted --- .../kotlin/net/dankito/banking/ui/IBankingClient.kt | 2 ++ .../dankito/banking/ui/presenter/BankingPresenter.kt | 4 +++- .../net/dankito/banking/fints4kBankingClient.kt | 12 +++++++++++- .../net/dankito/banking/hbci4jBankingClient.kt | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt index 8dab3924..eb7adf65 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt @@ -26,4 +26,6 @@ interface IBankingClient { fun dataChanged(customer: TypedCustomer) + fun deletedAccount(customer: TypedCustomer, wasLastAccountWithThisCredentials: Boolean) + } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index f789f51e..b02c2ea4 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -246,7 +246,7 @@ open class BankingPresenter constructor( val wasSelected = isSingleSelectedAccount(customer) or // either account or one of its bank accounts is currently selected (customer.accounts.firstOrNull { isSingleSelectedBankAccount(it) } != null) - bankingClientsForAccounts.remove(customer) + val client = bankingClientsForAccounts.remove(customer) val displayIndex = customer.displayIndex @@ -259,6 +259,8 @@ open class BankingPresenter constructor( accountDisplayIndexUpdated(bank) } + client?.deletedAccount(customer, customers.firstOrNull { it.customerId == customer.customerId && it.bankCode == customer.bankCode} == null) + callAccountsChangedListeners() if (wasSelected || areAllAccountSelected) { // to update displayed account transactions as transactions of yet deleted accounts have to be removed diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt index 800b0784..c0b7236f 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt @@ -137,6 +137,12 @@ open class fints4kBankingClient( mapper.mapChangesFromUiToClientModel(customer, bank) } + override fun deletedAccount(customer: TypedCustomer, wasLastAccountWithThisCredentials: Boolean) { + if (wasLastAccountWithThisCredentials) { + getFints4kClientDataFile(customer).delete() + } + } + protected open fun findAccountForBankAccount(bankAccount: TypedBankAccount, findAccountResult: (AccountData?, error: String?) -> Unit) { val mappedAccount = mapper.findAccountForBankAccount(bank, bankAccount) @@ -176,7 +182,7 @@ open class fints4kBankingClient( protected open fun restoreData(customer: TypedCustomer): BankData? { try { - return serializer.deserializeObject(getFints4kClientDataFile(customer.bankCode, customer.customerId), BankData::class) + return serializer.deserializeObject(getFints4kClientDataFile(customer), BankData::class) } catch (e: Exception) { log.warn(e) { "Could not deserialize bank data of $customer (which is ok if bank is just about to be added)" } } @@ -194,6 +200,10 @@ open class fints4kBankingClient( } } + protected open fun getFints4kClientDataFile(customer: TypedCustomer): File { + return getFints4kClientDataFile(customer.bankCode, customer.customerId) + } + protected open fun getFints4kClientDataFile(bankCode: String, customerId: String): File { val folder = File(dataFolder, "fints4k-client") diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt index 419b4640..6575d113 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt @@ -283,6 +283,10 @@ open class hbci4jBankingClient( credentials.password = customer.password } + override fun deletedAccount(customer: TypedCustomer, wasLastAccountWithThisCredentials: Boolean) { + getPassportFile(credentials).delete() + } + protected open fun connect(): ConnectResult { return connect(credentials, HBCIVersion.HBCI_300)