Implemented calculating isSuccessful in AddAccountResponse and GetTransactionsResponse

This commit is contained in:
dankito 2020-09-19 03:04:46 +02:00
parent f444a45730
commit 2d4499514a
9 changed files with 36 additions and 21 deletions

View File

@ -318,7 +318,6 @@ open class FinTsClient(
areWeThatGentleToCloseDialogs = originalAreWeThatGentleToCloseDialogs areWeThatGentleToCloseDialogs = originalAreWeThatGentleToCloseDialogs
// TODO: to evaluate if adding account has been successful also check if count accounts > 0
callback(AddAccountResponse(newUserInfoResponse.toResponse(), bank, retrievedAccountData)) callback(AddAccountResponse(newUserInfoResponse.toResponse(), bank, retrievedAccountData))
} }

View File

@ -8,4 +8,9 @@ open class AddAccountResponse(
response: Response, response: Response,
open val bank: BankData, open val bank: BankData,
retrievedData: List<RetrievedAccountData> = listOf() retrievedData: List<RetrievedAccountData> = listOf()
) : GetTransactionsResponse(response, retrievedData) ) : GetTransactionsResponse(response, retrievedData) {
override val isSuccessful: Boolean
get() = super.isSuccessful && bank.accounts.isNotEmpty()
}

View File

@ -11,4 +11,9 @@ open class GetTransactionsResponse(
* This value is only set if [GetTransactionsParameter.maxCountEntries] was set to tell caller if maxCountEntries parameter has been evaluated or not * This value is only set if [GetTransactionsParameter.maxCountEntries] was set to tell caller if maxCountEntries parameter has been evaluated or not
*/ */
open var isSettingMaxCountEntriesAllowedByBank: Boolean? = null open var isSettingMaxCountEntriesAllowedByBank: Boolean? = null
) : FinTsClientResponse(response) ) : FinTsClientResponse(response) {
override val isSuccessful: Boolean
get() = super.isSuccessful && retrievedData.isNotEmpty() && retrievedData.none { it.successfullyRetrievedData == false }
}

View File

@ -5,12 +5,14 @@ import net.dankito.utils.multiplatform.BigDecimal
open class AddAccountResponse( open class AddAccountResponse(
isSuccessful: Boolean,
errorToShowToUser: String?, errorToShowToUser: String?,
open val customer: TypedCustomer, open val customer: TypedCustomer,
retrievedData: List<RetrievedAccountData> = listOf(), retrievedData: List<RetrievedAccountData> = listOf(),
userCancelledAction: Boolean = false userCancelledAction: Boolean = false
) : GetTransactionsResponse(isSuccessful, errorToShowToUser, retrievedData, userCancelledAction) { ) : GetTransactionsResponse(errorToShowToUser, retrievedData, userCancelledAction) {
override val isSuccessful: Boolean
get() = super.isSuccessful && customer.accounts.isNotEmpty()
open val supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean open val supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean
get() = retrievedData.isNotEmpty() && retrievedData.any { it.successfullyRetrievedData } get() = retrievedData.isNotEmpty() && retrievedData.any { it.successfullyRetrievedData }

View File

@ -4,9 +4,13 @@ import net.dankito.banking.ui.model.RetrievedAccountData
open class GetTransactionsResponse( open class GetTransactionsResponse(
isSuccessful: Boolean,
errorToShowToUser: String?, errorToShowToUser: String?,
open val retrievedData: List<RetrievedAccountData> = listOf(), open val retrievedData: List<RetrievedAccountData> = listOf(),
userCancelledAction: Boolean = false, userCancelledAction: Boolean = false,
open val tanRequiredButWeWereToldToAbortIfSo: Boolean = false open val tanRequiredButWeWereToldToAbortIfSo: Boolean = false
) : BankingClientResponse(isSuccessful, errorToShowToUser, userCancelledAction) ) : BankingClientResponse(true /* any value */, errorToShowToUser, userCancelledAction) {
override val isSuccessful: Boolean
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(true, null, listOf(retrievedData)), startDate, false) retrievedAccountTransactions(GetTransactionsResponse(null, listOf(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(true, null, listOf(RetrievedAccountData(bankAccount, true, null, accountTransactionsChunk, listOf())))) callRetrievedAccountTransactionsResponseListener(GetTransactionsResponse(null, listOf(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(false, errorMessage)) callback(GetTransactionsResponse(errorMessage))
} }
else { else {
val mappedParameter = GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate, val mappedParameter = GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate,

View File

@ -31,13 +31,13 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) {
open fun mapResponse(customer: TypedCustomer, response: net.dankito.banking.fints.response.client.AddAccountResponse): AddAccountResponse { open fun mapResponse(customer: TypedCustomer, response: net.dankito.banking.fints.response.client.AddAccountResponse): AddAccountResponse {
return AddAccountResponse(response.isSuccessful, mapErrorToShowToUser(response), return AddAccountResponse(mapErrorToShowToUser(response),
customer, map(customer, response.retrievedData), response.userCancelledAction) customer, map(customer, response.retrievedData), response.userCancelledAction)
} }
open fun mapResponse(bankAccount: TypedBankAccount, response: net.dankito.banking.fints.response.client.GetTransactionsResponse): GetTransactionsResponse { open fun mapResponse(bankAccount: TypedBankAccount, response: net.dankito.banking.fints.response.client.GetTransactionsResponse): GetTransactionsResponse {
return GetTransactionsResponse(response.isSuccessful, mapErrorToShowToUser(response), return GetTransactionsResponse(mapErrorToShowToUser(response),
map(bankAccount.customer as TypedCustomer, response.retrievedData), map(bankAccount.customer as TypedCustomer, response.retrievedData),
response.userCancelledAction, response.tanRequiredButWeWereToldToAbortIfSo) response.userCancelledAction, response.tanRequiredButWeWereToldToAbortIfSo)
} }

View File

@ -76,7 +76,7 @@ open class hbci4jBankingClient(
val accounts = passport.accounts val accounts = passport.accounts
if (accounts == null || accounts.size == 0) { if (accounts == null || accounts.size == 0) {
log.error("Keine Konten ermittelbar") log.error("Keine Konten ermittelbar")
return AddAccountResponse(false, "Keine Konten ermittelbar", customer) // TODO: translate return AddAccountResponse("Keine Konten ermittelbar", customer) // TODO: translate
} }
this.customer.accounts = mapper.mapBankAccounts(customer, accounts, passport) this.customer.accounts = mapper.mapBankAccounts(customer, accounts, passport)
@ -85,7 +85,7 @@ open class hbci4jBankingClient(
} }
} }
return AddAccountResponse(false, connection.error.getInnerExceptionMessage(), customer) return AddAccountResponse(connection.error.getInnerExceptionMessage(), customer)
} }
protected open fun tryToRetrieveAccountTransactionsForAddedAccounts(customer: TypedCustomer): AddAccountResponse { protected open fun tryToRetrieveAccountTransactionsForAddedAccounts(customer: TypedCustomer): AddAccountResponse {
@ -106,7 +106,7 @@ open class hbci4jBankingClient(
} }
} }
return AddAccountResponse(true, null, customer, retrievedData, userCancelledAction) return AddAccountResponse(null, customer, retrievedData, userCancelledAction)
} }
@ -153,7 +153,7 @@ open class hbci4jBankingClient(
// Pruefen, ob die Kommunikation mit der Bank grundsaetzlich geklappt hat // Pruefen, ob die Kommunikation mit der Bank grundsaetzlich geklappt hat
if (!status.isOK) { if (!status.isOK) {
log.error("Could not connect to bank ${credentials.bankCode} $status: ${status.errorString}") log.error("Could not connect to bank ${credentials.bankCode} $status: ${status.errorString}")
return GetTransactionsResponse(false, "Could not connect to bank ${credentials.bankCode}: $status", retrievingDataFailed) return GetTransactionsResponse("Could not connect to bank ${credentials.bankCode}: $status", retrievingDataFailed)
} }
// Auswertung des Saldo-Abrufs. // Auswertung des Saldo-Abrufs.
@ -162,7 +162,7 @@ open class hbci4jBankingClient(
val balanceResult = nullableBalanceJob.jobResult as GVRSaldoReq val balanceResult = nullableBalanceJob.jobResult as GVRSaldoReq
if(balanceResult.isOK == false) { if(balanceResult.isOK == false) {
log.error("Could not fetch balance of bank account $bankAccount: $balanceResult", balanceResult.getJobStatus().exceptions) log.error("Could not fetch balance of bank account $bankAccount: $balanceResult", balanceResult.getJobStatus().exceptions)
return GetTransactionsResponse(false, "Could not fetch balance of bank account $bankAccount: $balanceResult", retrievingDataFailed) return GetTransactionsResponse("Could not fetch balance of bank account $bankAccount: $balanceResult", retrievingDataFailed)
} }
balance = balanceResult.entries[0].ready.value.bigDecimalValue.toBigDecimal() balance = balanceResult.entries[0].ready.value.bigDecimalValue.toBigDecimal()
@ -176,15 +176,15 @@ open class hbci4jBankingClient(
// Pruefen, ob der Abruf der Umsaetze geklappt hat // Pruefen, ob der Abruf der Umsaetze geklappt hat
if (result.isOK == false) { if (result.isOK == false) {
log.error("Could not get fetch account transactions of bank account $bankAccount: $result", result.getJobStatus().exceptions) log.error("Could not get fetch account transactions of bank account $bankAccount: $result", result.getJobStatus().exceptions)
return GetTransactionsResponse(false, "Could not fetch account transactions of bank account $bankAccount: $result", retrievingDataFailed) return GetTransactionsResponse("Could not fetch account transactions of bank account $bankAccount: $result", retrievingDataFailed)
} }
return GetTransactionsResponse(true, null, listOf(RetrievedAccountData(bankAccount, true, balance.toBigDecimal(), return GetTransactionsResponse(null, listOf(RetrievedAccountData(bankAccount, true, balance.toBigDecimal(),
accountTransactionMapper.mapAccountTransactions(bankAccount, result), listOf()))) accountTransactionMapper.mapAccountTransactions(bankAccount, 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)
return GetTransactionsResponse(false, e.getInnerExceptionMessage(), retrievingDataFailed) return GetTransactionsResponse(e.getInnerExceptionMessage(), retrievingDataFailed)
} }
finally { finally {
closeConnection(connection) closeConnection(connection)
@ -193,7 +193,7 @@ open class hbci4jBankingClient(
closeConnection(connection) closeConnection(connection)
return GetTransactionsResponse(false, connection.error.getInnerExceptionMessage(), retrievingDataFailed) return GetTransactionsResponse(connection.error.getInnerExceptionMessage(), retrievingDataFailed)
} }
protected open fun executeJobsForGetAccountingEntries(handle: HBCIHandler, bankAccount: TypedBankAccount, parameter: GetTransactionsParameter): Triple<HBCIJob?, HBCIJob, HBCIExecStatus> { protected open fun executeJobsForGetAccountingEntries(handle: HBCIHandler, bankAccount: TypedBankAccount, parameter: GetTransactionsParameter): Triple<HBCIJob?, HBCIJob, HBCIExecStatus> {