Implemented restoring data directly when creating fints4kBankingClient. This also fixes that restored BankData has data that mapped BankData didn't have (like allowedJobs, pinInfo, ...)
This commit is contained in:
parent
63259ff404
commit
0ea9fad7a0
|
@ -24,6 +24,4 @@ interface IBankingClient {
|
|||
|
||||
fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit)
|
||||
|
||||
fun restoreData()
|
||||
|
||||
}
|
|
@ -120,13 +120,6 @@ open class BankingPresenter(
|
|||
deserializedAccounts.forEach { customer ->
|
||||
val newClient = bankingClientCreator.createClient(customer, dataFolder, asyncRunner, callback)
|
||||
|
||||
try {
|
||||
newClient.restoreData()
|
||||
} catch (e: Exception) {
|
||||
log.error(e) { "Could not deserialize customer data of $customer" }
|
||||
// TODO: show error message to user
|
||||
}
|
||||
|
||||
addClientForAccount(customer, newClient)
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ open class fints4kBankingClient(
|
|||
protected var didTryToGetAccountDataFromBank = false
|
||||
|
||||
|
||||
protected val bank = BankData(customer.bankCode, customer.customerId, customer.password, customer.finTsServerAddress, customer.bic, customer.bankName)
|
||||
protected val bank = restoreDataOrMapFromUiModel(customer)
|
||||
|
||||
|
||||
protected open val client = FinTsClientForCustomer(bank, createFinTsClientCallback(callback), webClient, base64Service)
|
||||
|
@ -152,19 +152,24 @@ open class fints4kBankingClient(
|
|||
}
|
||||
|
||||
|
||||
override fun restoreData() {
|
||||
val deserializedBank = serializer.deserializeObject(getFints4kClientDataFile(), BankData::class)
|
||||
|
||||
deserializedBank?.let {
|
||||
mapper.updateCustomer(bank, deserializedBank)
|
||||
|
||||
mapper.mapCustomer(customer, bank) // TODO: necessary?
|
||||
protected open fun restoreDataOrMapFromUiModel(customer: Customer): BankData {
|
||||
return restoreData(customer) ?:
|
||||
BankData(customer.bankCode, customer.customerId, customer.password, customer.finTsServerAddress, customer.bic, customer.bankName)
|
||||
}
|
||||
|
||||
protected open fun restoreData(customer: Customer): BankData? {
|
||||
try {
|
||||
return serializer.deserializeObject(getFints4kClientDataFile(customer.bankCode, customer.customerId), 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)" }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
protected open fun saveData() {
|
||||
try {
|
||||
val clientDataFile = getFints4kClientDataFile()
|
||||
val clientDataFile = getFints4kClientDataFile(bank.bankCode, bank.customerId)
|
||||
|
||||
serializer.serializeObject(bank, clientDataFile)
|
||||
} catch (e: Exception) {
|
||||
|
@ -172,12 +177,12 @@ open class fints4kBankingClient(
|
|||
}
|
||||
}
|
||||
|
||||
protected open fun getFints4kClientDataFile(): File {
|
||||
protected open fun getFints4kClientDataFile(bankCode: String, customerId: String): File {
|
||||
val folder = File(dataFolder, "fints4k-client")
|
||||
|
||||
folder.mkdirs()
|
||||
|
||||
return File(folder, "${bank.bankCode}_${bank.customerId}_$fints4kClientDataFilename")
|
||||
return File(folder, "${bankCode}_${customerId}_$fints4kClientDataFilename")
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -271,11 +271,6 @@ open class hbci4jBankingClient(
|
|||
}
|
||||
|
||||
|
||||
override fun restoreData() {
|
||||
// nothing to do for hbci4j
|
||||
}
|
||||
|
||||
|
||||
protected open fun connect(): ConnectResult {
|
||||
return connect(credentials, HBCIVersion.HBCI_300)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue