Storing now FinTsClientForCustomer instead of Pair<CustomerData, BankData>

This commit is contained in:
dankl 2019-11-03 23:58:22 +01:00 committed by dankito
parent 7d5583370c
commit 579f542bc7
1 changed files with 20 additions and 17 deletions

View File

@ -6,12 +6,16 @@ import net.dankito.banking.ui.model.AccountTransaction
import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.BankAccount
import net.dankito.banking.ui.model.responses.AddAccountResponse import net.dankito.banking.ui.model.responses.AddAccountResponse
import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.model.responses.GetTransactionsResponse
import net.dankito.fints.FinTsClient
import net.dankito.fints.FinTsClientCallback import net.dankito.fints.FinTsClientCallback
import net.dankito.fints.FinTsClientForCustomer
import net.dankito.fints.banks.BankFinder import net.dankito.fints.banks.BankFinder
import net.dankito.fints.model.* import net.dankito.fints.model.BankInfo
import net.dankito.fints.model.BankTransferData
import net.dankito.fints.model.CustomerData
import net.dankito.fints.model.GetTransactionsParameter
import net.dankito.fints.model.mapper.BankDataMapper import net.dankito.fints.model.mapper.BankDataMapper
import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.FinTsClientResponse
import net.dankito.fints.util.IBase64Service
import net.dankito.utils.IThreadPool import net.dankito.utils.IThreadPool
import net.dankito.utils.ThreadPool import net.dankito.utils.ThreadPool
import java.math.BigDecimal import java.math.BigDecimal
@ -19,9 +23,9 @@ import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
open class MainWindowPresenter(callback: FinTsClientCallback) { open class MainWindowPresenter(protected val callback: FinTsClientCallback) {
protected val finTsClient = FinTsClient(callback, Base64ServiceAndroid()) protected val base64Service: IBase64Service = Base64ServiceAndroid()
protected val bankFinder: BankFinder = BankFinder() protected val bankFinder: BankFinder = BankFinder()
@ -32,7 +36,7 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
protected val fints4javaModelMapper = net.dankito.banking.fints4java.android.mapper.fints4javaModelMapper() protected val fints4javaModelMapper = net.dankito.banking.fints4java.android.mapper.fints4javaModelMapper()
protected val accounts = mutableMapOf<Account, Any>() protected val accounts = mutableMapOf<Account, FinTsClientForCustomer>()
protected val accountAddedListeners = mutableListOf<(Account) -> Unit>() protected val accountAddedListeners = mutableListOf<(Account) -> Unit>()
@ -44,13 +48,14 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
val bank = bankDataMapper.mapFromBankInfo(bankInfo) val bank = bankDataMapper.mapFromBankInfo(bankInfo)
val customer = CustomerData(customerId, pin) val customer = CustomerData(customerId, pin)
val newClient = FinTsClientForCustomer(bank, customer, this.callback, base64Service)
finTsClient.addAccountAsync(bank, customer) { response -> newClient.addAccountAsync { response ->
val account = fints4javaModelMapper.mapAccount(customer, bank) val account = fints4javaModelMapper.mapAccount(customer, bank)
val mappedResponse = fints4javaModelMapper.mapResponse(account, response) val mappedResponse = fints4javaModelMapper.mapResponse(account, response)
if (response.isSuccessful) { if (response.isSuccessful) {
accounts.put(account, Pair(customer, bank)) accounts.put(account, newClient)
callAccountAddedListeners(account) callAccountAddedListeners(account)
@ -83,9 +88,8 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
open fun getAccountTransactionsAsync(bankAccount: BankAccount, fromDate: Date?, open fun getAccountTransactionsAsync(bankAccount: BankAccount, fromDate: Date?,
callback: (GetTransactionsResponse) -> Unit) { callback: (GetTransactionsResponse) -> Unit) {
getCustomerAndBankForAccount(bankAccount.account)?.let { customerBankPair -> getClientForAccount(bankAccount.account)?.let { client ->
finTsClient.getTransactionsAsync(GetTransactionsParameter(true, fromDate), client.getTransactionsAsync(GetTransactionsParameter(true, fromDate)) { response ->
customerBankPair.second, customerBankPair.first) { response ->
val mappedResponse = fints4javaModelMapper.mapResponse(bankAccount.account, response) val mappedResponse = fints4javaModelMapper.mapResponse(bankAccount.account, response)
@ -133,9 +137,8 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
open fun transferMoneyAsync(bankAccount: BankAccount, bankTransferData: BankTransferData, callback: (FinTsClientResponse) -> Unit) { open fun transferMoneyAsync(bankAccount: BankAccount, bankTransferData: BankTransferData, callback: (FinTsClientResponse) -> Unit) {
getCustomerAndBankForAccount(bankAccount.account)?.let { customerBankPair -> getClientForAccount(bankAccount.account)?.let { client ->
finTsClient.doBankTransferAsync( client.doBankTransferAsync(bankTransferData, callback)
bankTransferData, customerBankPair.second, customerBankPair.first, callback)
} }
} }
@ -166,13 +169,13 @@ open class MainWindowPresenter(callback: FinTsClientCallback) {
} }
protected open fun getCustomerAndBankForAccount(account: Account): Pair<CustomerData, BankData>? { protected open fun getClientForAccount(account: Account): FinTsClientForCustomer? {
(accounts.get(account) as? Pair<CustomerData, BankData>)?.let { customerBankPair -> accounts.get(account)?.let { client ->
account.selectedTanProcedure?.let { selectedTanProcedure -> account.selectedTanProcedure?.let { selectedTanProcedure ->
customerBankPair.first.selectedTanProcedure = fints4javaModelMapper.mapTanProcedureBack(selectedTanProcedure) client.customer.selectedTanProcedure = fints4javaModelMapper.mapTanProcedureBack(selectedTanProcedure)
} }
return customerBankPair // TODO: return IBankingClient return client // TODO: return IBankingClient
} }
return null return null