Fixed that changes make in UI settings haven't been reflected in clients

This commit is contained in:
dankito 2020-09-08 16:25:28 +02:00
parent b7d94e8a17
commit 744af2880c
6 changed files with 62 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package net.dankito.banking.ui package net.dankito.banking.ui
import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.BankAccount
import net.dankito.banking.ui.model.Customer
import net.dankito.banking.ui.model.MessageLogEntry import net.dankito.banking.ui.model.MessageLogEntry
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
import net.dankito.banking.ui.model.parameters.TransferMoneyData import net.dankito.banking.ui.model.parameters.TransferMoneyData
@ -24,4 +25,7 @@ interface IBankingClient {
fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit)
fun dataChanged(customer: Customer)
} }

View File

@ -394,6 +394,8 @@ open class BankingPresenter(
open fun accountUpdated(bank: Customer) { open fun accountUpdated(bank: Customer) {
persistAccount(bank) persistAccount(bank)
getBankingClientForAccount(bank)?.dataChanged(bank)
} }
open fun accountUpdated(account: BankAccount) { open fun accountUpdated(account: BankAccount) {

View File

@ -65,7 +65,7 @@ open class fints4kBankingClient(
protected open fun handleAddAccountResponse(response: net.dankito.banking.fints.response.client.AddAccountResponse, protected open fun handleAddAccountResponse(response: net.dankito.banking.fints.response.client.AddAccountResponse,
callback: (AddAccountResponse) -> Unit) { callback: (AddAccountResponse) -> Unit) {
mapper.mapCustomer(customer, bank) mapper.mapBank(customer, bank)
val mappedResponse = mapper.mapResponse(customer, response) val mappedResponse = mapper.mapResponse(customer, response)
saveData() saveData()
@ -132,6 +132,11 @@ open class fints4kBankingClient(
} }
override fun dataChanged(customer: Customer) {
mapper.mapChangesFromUiToClientModel(customer, bank)
}
protected open fun findAccountForBankAccount(bankAccount: BankAccount, findAccountResult: (AccountData?, error: String?) -> Unit) { protected open fun findAccountForBankAccount(bankAccount: BankAccount, findAccountResult: (AccountData?, error: String?) -> Unit) {
val mappedAccount = mapper.findAccountForBankAccount(bank, bankAccount) val mappedAccount = mapper.findAccountForBankAccount(bank, bankAccount)

View File

@ -60,7 +60,7 @@ open class fints4kModelMapper {
} }
open fun mapCustomer(customer: Customer, bank: BankData) { open fun mapBank(customer: Customer, bank: BankData) {
customer.bankCode = bank.bankCode customer.bankCode = bank.bankCode
customer.customerId = bank.customerId customer.customerId = bank.customerId
customer.password = bank.pin customer.password = bank.pin
@ -75,6 +75,18 @@ open class fints4kModelMapper {
updateTanMediaAndProcedures(customer, bank) updateTanMediaAndProcedures(customer, bank)
} }
/**
* In UI only customerId, password, (bankCode,) and selected TAN procedure can be set
*/
open fun mapChangesFromUiToClientModel(customer: Customer, bank: BankData) {
bank.customerId = customer.customerId
bank.pin = customer.password
bank.bankCode = customer.bankCode
bank.selectedTanProcedure = findTanProcedure(bank, customer.selectedTanProcedure) ?: bank.selectedTanProcedure
}
// TODO: move to a fints4k internal mapper // TODO: move to a fints4k internal mapper
open fun updateCustomer(bank: BankData, updatedBank: BankData) { open fun updateCustomer(bank: BankData, updatedBank: BankData) {
bank.pin = updatedBank.pin bank.pin = updatedBank.pin
@ -284,6 +296,14 @@ open class fints4kModelMapper {
return customer.supportedTanProcedures.firstOrNull { it.bankInternalProcedureCode == tanProcedure.securityFunction.code } return customer.supportedTanProcedures.firstOrNull { it.bankInternalProcedureCode == tanProcedure.securityFunction.code }
} }
protected open fun findTanProcedure(bank: BankData, tanProcedure: TanProcedure?): net.dankito.banking.fints.model.TanProcedure? {
if (tanProcedure == null) {
return null
}
return bank.tanProceduresAvailableForUser.firstOrNull { it.securityFunction.code == tanProcedure.bankInternalProcedureCode }
}
open fun mapTanMediums(tanMediums: List<net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMedium>): List<TanMedium> { open fun mapTanMediums(tanMediums: List<net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMedium>): List<TanMedium> {
return tanMediums.map { mapTanMedium(it) } return tanMediums.map { mapTanMedium(it) }

View File

@ -48,7 +48,7 @@ open class hbci4jBankingClient(
} }
protected val credentials = AccountCredentials(customer.bankCode, customer.customerId, customer.password) protected val credentials = AccountCredentials(customer)
protected val mapper = hbci4jModelMapper() protected val mapper = hbci4jModelMapper()
@ -271,6 +271,17 @@ open class hbci4jBankingClient(
} }
override fun dataChanged(customer: Customer) {
if (customer.bankCode != credentials.bankCode || customer.customerId != credentials.customerId || customer.password != credentials.password) {
getPassportFile(credentials).delete()
}
credentials.bankCode = customer.bankCode
credentials.customerId = customer.customerId
credentials.password = customer.password
}
protected open fun connect(): ConnectResult { protected open fun connect(): ConnectResult {
return connect(credentials, HBCIVersion.HBCI_300) return connect(credentials, HBCIVersion.HBCI_300)
} }
@ -286,10 +297,7 @@ open class hbci4jBankingClient(
// Die Datei kann problemlos geloescht werden. Sie wird beim naechsten mal automatisch neu erzeugt, // Die Datei kann problemlos geloescht werden. Sie wird beim naechsten mal automatisch neu erzeugt,
// wenn der Parameter "client.passport.PinTan.init" den Wert "1" hat (siehe unten). // wenn der Parameter "client.passport.PinTan.init" den Wert "1" hat (siehe unten).
// Wir speichern die Datei der Einfachheit halber im aktuellen Verzeichnis. // Wir speichern die Datei der Einfachheit halber im aktuellen Verzeichnis.
val hbciClientFolder = File(dataFolder, "hbci4j-client") val passportFile = getPassportFile(credentials)
hbciClientFolder.mkdirs()
val passportFile = File(hbciClientFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat")
// Wir setzen die Kernel-Parameter zur Laufzeit. Wir koennten sie alternativ // Wir setzen die Kernel-Parameter zur Laufzeit. Wir koennten sie alternativ
// auch oben in "props" setzen. // auch oben in "props" setzen.
@ -336,6 +344,13 @@ open class hbci4jBankingClient(
return ConnectResult(true, null, handle, passport) return ConnectResult(true, null, handle, passport)
} }
protected open fun getPassportFile(credentials: AccountCredentials): File {
val hbciClientFolder = File(dataFolder, "hbci4j-client")
hbciClientFolder.mkdirs()
return File(hbciClientFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat")
}
protected open fun closeConnection(connection: ConnectResult) { protected open fun closeConnection(connection: ConnectResult) {
closeConnection(connection.handle, connection.passport) closeConnection(connection.handle, connection.passport)
} }

View File

@ -1,8 +1,14 @@
package net.dankito.banking.model package net.dankito.banking.model
import net.dankito.banking.ui.model.Customer
open class AccountCredentials( open class AccountCredentials(
val bankCode: String, var bankCode: String,
val customerId: String, var customerId: String,
var password: String var password: String
) ) {
constructor(bank: Customer) : this(bank.bankCode, bank.customerId, bank.password)
}