From f62f30dd8eb4e5d6591fee10c98ac00072cd4bb2 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 16 Sep 2020 15:03:03 +0200 Subject: [PATCH] Fixed that mapped TAN media und procedures got discarded and replaced by new instances and therefore inserted another time into database resulting in duplicates --- .../banking/mapper/fints4kModelMapper.kt | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt index d8017c59..80de5a7f 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt @@ -8,6 +8,7 @@ import net.dankito.banking.ui.model.responses.BankingClientResponse import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.model.tan.* import net.dankito.banking.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion +import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMediumKlasse import net.dankito.banking.fints.model.AccountData import net.dankito.banking.fints.model.AccountFeature import net.dankito.banking.fints.model.BankData @@ -244,7 +245,9 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { open fun updateTanMediaAndProcedures(account: TypedCustomer, bank: BankData) { - account.supportedTanProcedures = mapTanProcedures(bank.tanProceduresAvailableForUser) + account.supportedTanProcedures = bank.tanProceduresAvailableForUser.map { tanProcedure -> + findMappedTanProcedure(account, tanProcedure) ?: mapTanProcedure(tanProcedure) + } if (bank.isTanProcedureSelected) { account.selectedTanProcedure = findMappedTanProcedure(account, bank.selectedTanProcedure) @@ -253,7 +256,9 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { account.selectedTanProcedure = null } - account.tanMedia = mapTanMedia(bank.tanMedia) + account.tanMedia = bank.tanMedia.map { tanMedium -> + findMappedTanMedium(account, tanMedium) ?: mapTanMedium(tanMedium) + } } @@ -305,6 +310,19 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { return bank.tanProceduresAvailableForUser.firstOrNull { it.securityFunction.code == tanProcedure.bankInternalProcedureCode } } + protected open fun findMappedTanMedium(customer: TypedCustomer, tanMedium: net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMedium): TanMedium? { + return customer.tanMedia.firstOrNull { doesMatchTanMedium(tanMedium, it) } + } + + protected open fun doesMatchTanMedium(fintsTanMedium: net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMedium, tanMedium: TanMedium): Boolean { + return when (fintsTanMedium.mediumClass) { + TanMediumKlasse.TanGenerator -> tanMedium is TanGeneratorTanMedium && tanMedium.cardNumber == (fintsTanMedium as? net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium)?.cardNumber + TanMediumKlasse.MobiltelefonMitMobileTan -> tanMedium is MobilePhoneTanMedium && (tanMedium.phoneNumber == (fintsTanMedium as? net.dankito.banking.fints.messages.datenelemente.implementierte.tan.MobilePhoneTanMedium)?.phoneNumber || + tanMedium.phoneNumber == (fintsTanMedium as? net.dankito.banking.fints.messages.datenelemente.implementierte.tan.MobilePhoneTanMedium)?.concealedPhoneNumber) + else -> tanMedium.displayName == fintsTanMedium.mediumClass.name + } + } + open fun mapTanMedia(tanMediums: List): List { return tanMediums.map { mapTanMedium(it) }