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 transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit)
|
||||||
|
|
||||||
fun restoreData()
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -120,13 +120,6 @@ open class BankingPresenter(
|
||||||
deserializedAccounts.forEach { customer ->
|
deserializedAccounts.forEach { customer ->
|
||||||
val newClient = bankingClientCreator.createClient(customer, dataFolder, asyncRunner, callback)
|
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)
|
addClientForAccount(customer, newClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ open class fints4kBankingClient(
|
||||||
protected var didTryToGetAccountDataFromBank = false
|
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)
|
protected open val client = FinTsClientForCustomer(bank, createFinTsClientCallback(callback), webClient, base64Service)
|
||||||
|
@ -152,19 +152,24 @@ open class fints4kBankingClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun restoreData() {
|
protected open fun restoreDataOrMapFromUiModel(customer: Customer): BankData {
|
||||||
val deserializedBank = serializer.deserializeObject(getFints4kClientDataFile(), BankData::class)
|
return restoreData(customer) ?:
|
||||||
|
BankData(customer.bankCode, customer.customerId, customer.password, customer.finTsServerAddress, customer.bic, customer.bankName)
|
||||||
|
}
|
||||||
|
|
||||||
deserializedBank?.let {
|
protected open fun restoreData(customer: Customer): BankData? {
|
||||||
mapper.updateCustomer(bank, deserializedBank)
|
try {
|
||||||
|
return serializer.deserializeObject(getFints4kClientDataFile(customer.bankCode, customer.customerId), BankData::class)
|
||||||
mapper.mapCustomer(customer, bank) // TODO: necessary?
|
} 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() {
|
protected open fun saveData() {
|
||||||
try {
|
try {
|
||||||
val clientDataFile = getFints4kClientDataFile()
|
val clientDataFile = getFints4kClientDataFile(bank.bankCode, bank.customerId)
|
||||||
|
|
||||||
serializer.serializeObject(bank, clientDataFile)
|
serializer.serializeObject(bank, clientDataFile)
|
||||||
} catch (e: Exception) {
|
} 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")
|
val folder = File(dataFolder, "fints4k-client")
|
||||||
|
|
||||||
folder.mkdirs()
|
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 {
|
protected open fun connect(): ConnectResult {
|
||||||
return connect(credentials, HBCIVersion.HBCI_300)
|
return connect(credentials, HBCIVersion.HBCI_300)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue