From 3940b1e77fb9ee3243a431b6f96c8417d9fc911c Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 15 Oct 2024 10:56:56 +0200 Subject: [PATCH] Moved messageLog to Response --- .../model/response/GetAccountDataResponse.kt | 3 +-- .../banking/client/model/response/Response.kt | 20 +++++++------- .../model/response/TransferMoneyResponse.kt | 4 +-- .../banking/client/fints4k/FinTs4kMapper.kt | 26 ++++++++++--------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetAccountDataResponse.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetAccountDataResponse.kt index fe7e0392..6ecbe14f 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetAccountDataResponse.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetAccountDataResponse.kt @@ -9,8 +9,7 @@ import net.codinux.banking.client.model.config.NoArgConstructor @Suppress("RUNTIME_ANNOTATION_NOT_SUPPORTED") @NoArgConstructor open class GetAccountDataResponse( - val bank: BankAccess, - val messageLog: List + val bank: BankAccess ) { @get:JsonIgnore diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt index fb305f3f..5a105b1d 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/Response.kt @@ -1,5 +1,6 @@ package net.codinux.banking.client.model.response +import net.codinux.banking.client.model.MessageLogEntry import net.codinux.banking.client.model.config.NoArgConstructor // TODO: may differentiate between ClientResponse, which is either Success or Error, and RestResponse, which can be Success, Error and TanRequired @@ -8,21 +9,22 @@ open class Response protected constructor( val type: ResponseType, val data: T? = null, val error: Error? = null, - val tanRequired: TanRequired? = null + val tanRequired: TanRequired? = null, + val messageLog: List = emptyList() ) { companion object { - fun success(data: T): Response = - Response(ResponseType.Success, data) + fun success(data: T, messageLog: List = emptyList()): Response = + Response(ResponseType.Success, data, messageLog = messageLog) - fun error(errorType: ErrorType, internalError: String? = null, errorMessagesFromBank: List = emptyList()): Response = - Response(ResponseType.Error, null, Error(errorType, internalError, errorMessagesFromBank)) + fun error(errorType: ErrorType, internalError: String? = null, errorMessagesFromBank: List = emptyList(), messageLog: List = emptyList()): Response = + Response(ResponseType.Error, null, Error(errorType, internalError, errorMessagesFromBank), messageLog = messageLog) - fun tanRequired(tanRequired: TanRequired): Response = - Response(ResponseType.TanRequired, null, null, tanRequired) + fun tanRequired(tanRequired: TanRequired, messageLog: List = emptyList()): Response = + Response(ResponseType.TanRequired, null, null, tanRequired, messageLog) - fun bankReturnedError(errorMessagesFromBank: List): Response = - Response.error(ErrorType.BankReturnedError, null, errorMessagesFromBank) + fun bankReturnedError(errorMessagesFromBank: List, messageLog: List = emptyList()): Response = + Response.error(ErrorType.BankReturnedError, null, errorMessagesFromBank, messageLog) } diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TransferMoneyResponse.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TransferMoneyResponse.kt index 99eec9a4..4b8f3d9f 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TransferMoneyResponse.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/TransferMoneyResponse.kt @@ -7,6 +7,4 @@ import net.codinux.banking.client.model.config.NoArgConstructor * Transfer money process does not return any data, only if successful or not (and in latter case an error message). */ @NoArgConstructor -open class TransferMoneyResponse( - val messageLog: List -) \ No newline at end of file +open class TransferMoneyResponse \ No newline at end of file diff --git a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt index d32f0203..78dac98e 100644 --- a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt +++ b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt @@ -97,9 +97,9 @@ open class FinTs4kMapper { open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse, bank: BankInfo? = null): Response = if (response.successful && response.customerAccount != null) { val bank = mapBank(response.customerAccount!!, bank, response.serializedFinTsModel) - Response.success(GetAccountDataResponse(bank, mapMessageLog(response, bank))) + Response.success(GetAccountDataResponse(bank), mapMessageLog(response, bank)) } else { - mapError(response) + mapError(response, mapMessageLog(response)) } open fun map(responses: List>): Response> { @@ -110,6 +110,8 @@ open class FinTs4kMapper { val bank = getAccountDataResponse.customerAccount val finTsBankAccount = bank?.accounts?.firstOrNull { it.identifier == account.identifier && it.subAccountNumber == account.subAccountNumber } + val messageLog = mapMessageLog(getAccountDataResponse) + if (getAccountDataResponse.successful && bank != null && finTsBankAccount != null) { if (finTsBankAccount.lastAccountUpdateTime != null) { account.lastAccountUpdateTime = finTsBankAccount.lastAccountUpdateTime @@ -124,15 +126,16 @@ open class FinTs4kMapper { Response.success(GetTransactionsResponse(account, balance, mapBookedTransactions(finTsBankAccount), emptyList(), mapHoldings(finTsBankAccount.statementOfHoldings, finTsBankAccount.currency, finTsBankAccount.lastAccountUpdateTime), - finTsBankAccount.lastAccountUpdateTime ?: Clock.System.now(), param.retrieveTransactionsFrom, param.retrieveTransactionsTo)) + finTsBankAccount.lastAccountUpdateTime ?: Clock.System.now(), param.retrieveTransactionsFrom, param.retrieveTransactionsTo), + messageLog) } else { - mapError(getAccountDataResponse) + mapError(getAccountDataResponse, messageLog) } } val data = mappedResponses.filter { it.type == ResponseType.Success }.mapNotNull { it.data } - return (object : Response>(type, data, mappedResponses.firstNotNullOfOrNull { it.error }) { }) + return (object : Response>(type, data, mappedResponses.firstNotNullOfOrNull { it.error }, messageLog = mappedResponses.flatMap { it.messageLog }) { }) } @@ -402,9 +405,9 @@ open class FinTs4kMapper { open fun mapTransferMoneyResponse(response: net.dankito.banking.client.model.response.TransferMoneyResponse, bank: BankAccess? = null, account: BankAccount? = null): Response = if (response.successful) { - Response.success(TransferMoneyResponse(mapMessageLog(response, bank, account))) + Response.success(TransferMoneyResponse(), mapMessageLog(response, bank, account)) } else { - mapError(response) + mapError(response, mapMessageLog(response, bank, account)) } open fun mapToMoney(amount: Amount, currency: String): Money = Money(amount.toString(), currency) @@ -432,14 +435,13 @@ open class FinTs4kMapper { } - protected open fun mapError(response: net.dankito.banking.client.model.response.FinTsClientResponse): Response { - return if (response.error != null) { + protected open fun mapError(response: net.dankito.banking.client.model.response.FinTsClientResponse, messageLog: List): Response = + if (response.error != null) { Response.error(ErrorType.valueOf(response.error!!.name), if (response.error == ErrorCode.BankReturnedError) null else response.errorMessage, - if (response.error == ErrorCode.BankReturnedError && response.errorMessage !== null) listOf(response.errorMessage!!) else emptyList()) + if (response.error == ErrorCode.BankReturnedError && response.errorMessage !== null) listOf(response.errorMessage!!) else emptyList(), messageLog) } else { - Response.error(ErrorType.UnknownError, response.errorMessage) + Response.error(ErrorType.UnknownError, response.errorMessage, messageLog = messageLog) } - } protected open fun mapException(exception: Exception?): String? = exception?.stackTraceToString()