Added convenience constructors for when retrieving data was successful

This commit is contained in:
dankito 2020-09-19 03:23:21 +02:00
parent ec3cdb1c39
commit 79ebb35bc7
4 changed files with 9 additions and 5 deletions

View File

@ -13,6 +13,10 @@ open class GetTransactionsResponse(
constructor(account: TypedBankAccount, errorToShowToUser: String) : this(errorToShowToUser, listOf(RetrievedAccountData(account, false, null, listOf(), listOf()))) constructor(account: TypedBankAccount, errorToShowToUser: String) : this(errorToShowToUser, listOf(RetrievedAccountData(account, false, null, listOf(), listOf())))
constructor(retrievedData: RetrievedAccountData) : this(listOf(retrievedData))
constructor(retrievedData: List<RetrievedAccountData>) : this(null, retrievedData)
override val isSuccessful: Boolean override val isSuccessful: Boolean
get() = errorToShowToUser == null && retrievedData.isNotEmpty() && retrievedData.none { it.successfullyRetrievedData == false } get() = errorToShowToUser == null && retrievedData.isNotEmpty() && retrievedData.none { it.successfullyRetrievedData == false }

View File

@ -161,7 +161,7 @@ open class BankingPresenter(
persistAccountOffUiThread(account) persistAccountOffUiThread(account)
response.retrievedData.forEach { retrievedData -> response.retrievedData.forEach { retrievedData ->
retrievedAccountTransactions(GetTransactionsResponse(null, listOf(retrievedData)), startDate, false) retrievedAccountTransactions(GetTransactionsResponse(retrievedData), startDate, false)
} }
findIconForBankAsync(account) findIconForBankAsync(account)
@ -353,7 +353,7 @@ open class BankingPresenter(
asyncRunner.runAsync { // don't block retrieving next chunk by blocked saving to db / json asyncRunner.runAsync { // don't block retrieving next chunk by blocked saving to db / json
updateAccountTransactions(bankAccount, accountTransactionsChunk) updateAccountTransactions(bankAccount, accountTransactionsChunk)
callRetrievedAccountTransactionsResponseListener(GetTransactionsResponse(null, listOf(RetrievedAccountData(bankAccount, true, null, accountTransactionsChunk, listOf())))) callRetrievedAccountTransactionsResponseListener(GetTransactionsResponse(RetrievedAccountData(bankAccount, true, null, accountTransactionsChunk, listOf())))
} }
} }
} }

View File

@ -78,7 +78,7 @@ open class fints4kBankingClient(
override fun getTransactionsAsync(bankAccount: TypedBankAccount, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) { override fun getTransactionsAsync(bankAccount: TypedBankAccount, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) {
findAccountForBankAccount(bankAccount) { account, errorMessage -> findAccountForBankAccount(bankAccount) { account, errorMessage ->
if (account == null) { if (account == null) {
callback(GetTransactionsResponse(errorMessage)) callback(GetTransactionsResponse(bankAccount, errorMessage ?: ""))
} }
else { else {
val mappedParameter = GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate, val mappedParameter = GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate,

View File

@ -178,8 +178,8 @@ open class hbci4jBankingClient(
return GetTransactionsResponse(account,"Could not fetch account transactions of bank account $account: $result") return GetTransactionsResponse(account,"Could not fetch account transactions of bank account $account: $result")
} }
return GetTransactionsResponse(null, listOf(RetrievedAccountData(account, true, balance.toBigDecimal(), return GetTransactionsResponse(RetrievedAccountData(account, true, balance.toBigDecimal(),
accountTransactionMapper.mapAccountTransactions(account, result), listOf()))) accountTransactionMapper.mapAccountTransactions(account, result), listOf()))
} }
catch(e: Exception) { catch(e: Exception) {
log.error("Could not get accounting details for bank ${credentials.bankCode}", e) log.error("Could not get accounting details for bank ${credentials.bankCode}", e)