Moved messageLog to Response
This commit is contained in:
parent
67ea188182
commit
3940b1e77f
|
@ -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<MessageLogEntry>
|
||||
val bank: BankAccess
|
||||
) {
|
||||
|
||||
@get:JsonIgnore
|
||||
|
|
|
@ -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<T> protected constructor(
|
|||
val type: ResponseType,
|
||||
val data: T? = null,
|
||||
val error: Error? = null,
|
||||
val tanRequired: TanRequired? = null
|
||||
val tanRequired: TanRequired? = null,
|
||||
val messageLog: List<MessageLogEntry> = emptyList()
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun <T> success(data: T): Response<T> =
|
||||
Response(ResponseType.Success, data)
|
||||
fun <T> success(data: T, messageLog: List<MessageLogEntry> = emptyList()): Response<T> =
|
||||
Response(ResponseType.Success, data, messageLog = messageLog)
|
||||
|
||||
fun <T> error(errorType: ErrorType, internalError: String? = null, errorMessagesFromBank: List<String> = emptyList()): Response<T> =
|
||||
Response(ResponseType.Error, null, Error(errorType, internalError, errorMessagesFromBank))
|
||||
fun <T> error(errorType: ErrorType, internalError: String? = null, errorMessagesFromBank: List<String> = emptyList(), messageLog: List<MessageLogEntry> = emptyList()): Response<T> =
|
||||
Response(ResponseType.Error, null, Error(errorType, internalError, errorMessagesFromBank), messageLog = messageLog)
|
||||
|
||||
fun <T> tanRequired(tanRequired: TanRequired): Response<T> =
|
||||
Response(ResponseType.TanRequired, null, null, tanRequired)
|
||||
fun <T> tanRequired(tanRequired: TanRequired, messageLog: List<MessageLogEntry> = emptyList()): Response<T> =
|
||||
Response(ResponseType.TanRequired, null, null, tanRequired, messageLog)
|
||||
|
||||
fun <T> bankReturnedError(errorMessagesFromBank: List<String>): Response<T> =
|
||||
Response.error(ErrorType.BankReturnedError, null, errorMessagesFromBank)
|
||||
fun <T> bankReturnedError(errorMessagesFromBank: List<String>, messageLog: List<MessageLogEntry> = emptyList()): Response<T> =
|
||||
Response.error(ErrorType.BankReturnedError, null, errorMessagesFromBank, messageLog)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<MessageLogEntry>
|
||||
)
|
||||
open class TransferMoneyResponse
|
|
@ -97,9 +97,9 @@ open class FinTs4kMapper {
|
|||
open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse, bank: BankInfo? = null): Response<GetAccountDataResponse> =
|
||||
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<Triple<BankAccount, GetAccountDataParameter, net.dankito.banking.client.model.response.GetAccountDataResponse>>): Response<List<GetTransactionsResponse>> {
|
||||
|
@ -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<List<GetTransactionsResponse>>(type, data, mappedResponses.firstNotNullOfOrNull { it.error }) { })
|
||||
return (object : Response<List<GetTransactionsResponse>>(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<TransferMoneyResponse> =
|
||||
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,13 +435,12 @@ open class FinTs4kMapper {
|
|||
}
|
||||
|
||||
|
||||
protected open fun <T> mapError(response: net.dankito.banking.client.model.response.FinTsClientResponse): Response<T> {
|
||||
return if (response.error != null) {
|
||||
protected open fun <T> mapError(response: net.dankito.banking.client.model.response.FinTsClientResponse, messageLog: List<MessageLogEntry>): Response<T> =
|
||||
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? =
|
||||
|
|
Loading…
Reference in New Issue