From 471fd0caf431247577df4b17f04f031ef2357368 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 12 Nov 2021 22:31:07 +0100 Subject: [PATCH] Collecting now message on JobContext (makes FinTsClient, FinTsJobExecutor and RequestExecutor state free); moved therefore Mt940AccountTransactionsParser to JobContext --- .../net/dankito/banking/fints/FinTsClient.kt | 20 ++++++------ .../banking/fints/FinTsClientForCustomer.kt | 8 ++--- .../dankito/banking/fints/FinTsJobExecutor.kt | 32 +++++++------------ .../dankito/banking/fints/RequestExecutor.kt | 22 ++----------- .../banking/fints/log/IMessageLogAppender.kt | 5 ++- .../banking/fints/log/MessageLogCollector.kt | 15 +++++---- .../dankito/banking/fints/model/JobContext.kt | 27 ++++++++++++++-- .../banking/fints/response/ResponseParser.kt | 2 +- .../response/client/AddAccountResponse.kt | 3 +- .../response/client/FinTsClientResponse.kt | 10 ++++-- .../client/GetTanMediaListResponse.kt | 4 ++- .../client/GetTransactionsResponse.kt | 4 ++- .../Mt940AccountTransactionsParser.kt | 8 ++--- .../fints/transactions/mt940/Mt940Parser.kt | 9 +++--- .../dankito/banking/fints4kBankingClient.kt | 31 ++++++++++-------- 15 files changed, 104 insertions(+), 96 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index 7f8a6bb2..232098b2 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -27,10 +27,6 @@ open class FinTsClient @JvmOverloads constructor( } - open val messageLogWithoutSensitiveData: List - get() = jobExecutor.messageLogWithoutSensitiveData - - /** * Retrieves information about bank (e.g. supported HBCI versions, FinTS server address, * supported jobs, ...). @@ -51,8 +47,10 @@ open class FinTsClient @JvmOverloads constructor( * On success [bank] parameter is updated afterwards. */ open fun getAnonymousBankInfo(bank: BankData, callback: (FinTsClientResponse) -> Unit) { - jobExecutor.getAnonymousBankInfo(JobContext(JobContextType.AnonymousBankInfo, this.callback, product, bank)) { response -> - callback(FinTsClientResponse(response)) + val context = JobContext(JobContextType.AnonymousBankInfo, this.callback, product, bank) + + jobExecutor.getAnonymousBankInfo(context) { response -> + callback(FinTsClientResponse(context, response)) } } @@ -66,7 +64,7 @@ open class FinTsClient @JvmOverloads constructor( jobExecutor.retrieveBasicDataLikeUsersTanMethods(context, parameter.preferredTanMethods, parameter.preferredTanMedium) { newUserInfoResponse -> if (newUserInfoResponse.successful == false) { // bank parameter (FinTS server address, ...) already seem to be wrong - callback(AddAccountResponse(newUserInfoResponse, bank)) + callback(AddAccountResponse(context, newUserInfoResponse, bank)) return@retrieveBasicDataLikeUsersTanMethods } @@ -84,7 +82,7 @@ open class FinTsClient @JvmOverloads constructor( jobExecutor.getAccounts(context) { getAccountsResponse -> if (getAccountsResponse.successful == false) { - callback(AddAccountResponse(getAccountsResponse, context.bank)) + callback(AddAccountResponse(context, getAccountsResponse, context.bank)) return@getAccounts } @@ -119,7 +117,7 @@ open class FinTsClient @JvmOverloads constructor( tryGetTransactionsOfLast90DaysWithoutTan(bank, account) { response -> retrievedAccountData.put(account, response.retrievedData.first()) - if (response.internalError != null) { + if (response.internalError != null) { // TODO: errors from response get lost! User then only sees "null" as error message //getAccountsResponse.errorMessage = response.errorMessage } @@ -135,7 +133,7 @@ open class FinTsClient @JvmOverloads constructor( retrievedAccountData: Map, callback: (AddAccountResponse) -> Unit) { - callback(AddAccountResponse(getAccountsResponse, context.bank, retrievedAccountData.values.toList())) + callback(AddAccountResponse(context, getAccountsResponse, context.bank, retrievedAccountData.values.toList())) } @@ -175,7 +173,7 @@ open class FinTsClient @JvmOverloads constructor( val context = JobContext(JobContextType.ChangeTanMedium, this.callback, product, bank) jobExecutor.changeTanMedium(context, newActiveTanMedium) { response -> - callback(FinTsClientResponse(response)) + callback(FinTsClientResponse(context, response)) } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt index 25647055..f82521ff 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt @@ -21,7 +21,6 @@ open class FinTsClientForCustomer( callback: FinTsClientCallback, requestExecutor: RequestExecutor = RequestExecutor(), messageBuilder: MessageBuilder = MessageBuilder(), - mt940Parser: IAccountTransactionsParser = Mt940AccountTransactionsParser(), modelMapper: ModelMapper = ModelMapper(messageBuilder), protected open val tanMethodSelector: TanMethodSelector = TanMethodSelector(), product: ProductData = ProductData("15E53C26816138699C7B6A3E8", "1.0.0") // TODO: get version dynamically) @@ -29,14 +28,13 @@ open class FinTsClientForCustomer( constructor(bank: BankData, callback: FinTsClientCallback, webClient: IWebClient = KtorWebClient(), base64Service: IBase64Service = PureKotlinBase64Service(), product: ProductData = ProductData("15E53C26816138699C7B6A3E8", "1.0.0")) // TODO: get version dynamically) - : this(bank, callback, RequestExecutor(MessageBuilder(), webClient, base64Service)) + : this(bank, callback, RequestExecutor(MessageBuilder(), webClient, base64Service), product = product) - protected val client = FinTsClient(callback, FinTsJobExecutor(requestExecutor, messageBuilder, mt940Parser, modelMapper, tanMethodSelector), product) + protected val client = FinTsClient(callback, FinTsJobExecutor(requestExecutor, messageBuilder, modelMapper, tanMethodSelector), product) - open val messageLogWithoutSensitiveData: List - get() = client.messageLogWithoutSensitiveData + open val messageLogWithoutSensitiveData: List = mutableListOf() open fun setCallback(callback: FinTsClientCallback) { client.callback = callback diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt index 57a8e259..9996fb5d 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt @@ -33,7 +33,6 @@ import net.dankito.utils.multiplatform.ObjectReference open class FinTsJobExecutor( protected open val requestExecutor: RequestExecutor = RequestExecutor(), protected open val messageBuilder: MessageBuilder = MessageBuilder(), - protected open val mt940Parser: IAccountTransactionsParser = Mt940AccountTransactionsParser(), protected open val modelMapper: ModelMapper = ModelMapper(messageBuilder), protected open val tanMethodSelector: TanMethodSelector = TanMethodSelector() ) { @@ -43,15 +42,6 @@ open class FinTsJobExecutor( } - open val messageLogWithoutSensitiveData: List - get() = requestExecutor.messageLogWithoutSensitiveData - - - init { - mt940Parser.logAppender = requestExecutor.messageLogAppender // TODO: find a better solution to append messages to MessageLog - } - - open fun getAnonymousBankInfo(context: JobContext, callback: (BankResponse) -> Unit) { context.startNewDialog() @@ -197,7 +187,7 @@ open class FinTsJobExecutor( initDialogWithStrongCustomerAuthentication(context) { initDialogResponse -> if (initDialogResponse.successful == false) { - callback(GetTransactionsResponse(initDialogResponse, RetrievedAccountData.unsuccessfulList(parameter.account))) + callback(GetTransactionsResponse(context, initDialogResponse, RetrievedAccountData.unsuccessfulList(parameter.account))) } else { // we now retrieved the fresh account information from FinTS server, use that one @@ -205,7 +195,7 @@ open class FinTsJobExecutor( mayGetBalance(context, parameter) { balanceResponse -> if (dialogContext.didBankCloseDialog) { - callback(GetTransactionsResponse(balanceResponse ?: initDialogResponse, RetrievedAccountData.unsuccessfulList(parameter.account))) + callback(GetTransactionsResponse(context, balanceResponse ?: initDialogResponse, RetrievedAccountData.unsuccessfulList(parameter.account))) } else { getTransactionsAfterInitAndGetBalance(context, parameter, balanceResponse, callback) @@ -235,7 +225,7 @@ open class FinTsJobExecutor( context.dialog.chunkedResponseHandler = { response -> response.getFirstSegmentById(InstituteSegmentId.AccountTransactionsMt940)?.let { transactionsSegment -> - val (chunkTransaction, remainder) = mt940Parser.parseTransactionsChunk(remainingMt940String + transactionsSegment.bookedTransactionsString, + val (chunkTransaction, remainder) = context.mt940Parser.parseTransactionsChunk(remainingMt940String + transactionsSegment.bookedTransactionsString, context.bank, parameter.account) bookedTransactions.addAll(chunkTransaction) @@ -261,7 +251,7 @@ open class FinTsJobExecutor( val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today, response.internalError) callback( - GetTransactionsResponse(response, listOf(retrievedData), + GetTransactionsResponse(context, response, listOf(retrievedData), if (parameter.maxCountEntries != null) parameter.isSettingMaxCountEntriesAllowedByBank else null ) ) @@ -302,7 +292,7 @@ open class FinTsJobExecutor( closeDialog(context) } - callback(FinTsClientResponse(response)) + callback(FinTsClientResponse(context, response)) } } @@ -318,11 +308,13 @@ open class FinTsJobExecutor( sendMessageAndHandleResponse(context, CustomerSegmentId.TanMediaList, false, { messageBuilder.createGetTanMediaListMessage(context, tanMediaKind, tanMediumClass) }) { response -> - handleGetTanMediaListResponse(response, context.bank, preferredTanMedium, callback) + handleGetTanMediaListResponse(context, response, preferredTanMedium, callback) } } - protected open fun handleGetTanMediaListResponse(response: BankResponse, bank: BankData, preferredTanMedium: String? = null, callback: (GetTanMediaListResponse) -> Unit) { + protected open fun handleGetTanMediaListResponse(context: JobContext, response: BankResponse, preferredTanMedium: String? = null, callback: (GetTanMediaListResponse) -> Unit) { + val bank = context.bank + // TAN media list (= TAN generator list) is only returned for users with chipTAN TAN methods val tanMediaList = if (response.successful == false) null else response.getFirstSegmentById(InstituteSegmentId.TanMediaList) @@ -335,7 +327,7 @@ open class FinTsJobExecutor( ?: bank.tanMedia.firstOrNull { it.mediumName != null } } - callback(GetTanMediaListResponse(response, tanMediaList)) + callback(GetTanMediaListResponse(context, response, tanMediaList)) } @@ -373,7 +365,7 @@ open class FinTsJobExecutor( val updatedAccount = getUpdatedAccount(context, context.account!!) messageBuilder.createBankTransferMessage(context, bankTransferData, updatedAccount) }) { response -> - callback(FinTsClientResponse(response)) + callback(FinTsClientResponse(context, response)) } } @@ -499,7 +491,7 @@ open class FinTsJobExecutor( changeTanMedium(context, changeTanMediumTo) { changeTanMediumResponse -> - changeTanMediumResultCallback?.invoke(FinTsClientResponse(changeTanMediumResponse)) + changeTanMediumResultCallback?.invoke(FinTsClientResponse(context, changeTanMediumResponse)) if (changeTanMediumResponse.successful == false || lastCreatedMessage == null) { callback(changeTanMediumResponse) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt index 6fd9c400..6bd71bca 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/RequestExecutor.kt @@ -1,7 +1,5 @@ package net.dankito.banking.fints -import net.dankito.banking.fints.log.IMessageLogAppender -import net.dankito.banking.fints.log.MessageLogCollector import net.dankito.banking.fints.messages.MessageBuilder import net.dankito.banking.fints.messages.MessageBuilderResult import net.dankito.banking.fints.model.* @@ -14,7 +12,6 @@ import net.dankito.banking.fints.webclient.IWebClient import net.dankito.banking.fints.webclient.KtorWebClient import net.dankito.banking.fints.webclient.WebClientResponse import net.dankito.utils.multiplatform.getAllExceptionMessagesJoined -import net.dankito.utils.multiplatform.log.Logger import net.dankito.utils.multiplatform.log.LoggerFactory @@ -22,8 +19,7 @@ open class RequestExecutor( protected open val messageBuilder: MessageBuilder = MessageBuilder(), protected open val webClient: IWebClient = KtorWebClient(), protected open val base64Service: IBase64Service = PureKotlinBase64Service(), - protected open val responseParser: ResponseParser = ResponseParser(), - protected open val messageLogCollector: MessageLogCollector = MessageLogCollector() + protected open val responseParser: ResponseParser = ResponseParser() ) { companion object { @@ -31,18 +27,6 @@ open class RequestExecutor( } - open val messageLogWithoutSensitiveData: List - get() = messageLogCollector.messageLogWithoutSensitiveData - - internal open val messageLogAppender: IMessageLogAppender = object : IMessageLogAppender { - - override fun logError(message: String, e: Exception?, logger: Logger?, bank: BankData?) { - messageLogCollector.logError(message, e, logger, bank) - } - - } - - open fun getAndHandleResponseForMessage(message: MessageBuilderResult, context: JobContext, tanRequiredCallback: (TanResponse, BankResponse, callback: (BankResponse) -> Unit) -> Unit, callback: (BankResponse) -> Unit) { if (message.createdMessage == null) { @@ -190,11 +174,11 @@ open class RequestExecutor( protected open fun addMessageLog(context: JobContext, type: MessageLogEntryType, message: String) { - messageLogCollector.addMessageLog(message, type, context.bank) + context.addMessageLog(type, message) } protected open fun logError(context: JobContext, message: String, e: Exception?) { - messageLogAppender.logError(message, e, log, context.bank) + context.logError(RequestExecutor::class, message, e) } } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/IMessageLogAppender.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/IMessageLogAppender.kt index c30c28e0..6fb8968c 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/IMessageLogAppender.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/IMessageLogAppender.kt @@ -1,11 +1,10 @@ package net.dankito.banking.fints.log -import net.dankito.banking.fints.model.BankData -import net.dankito.utils.multiplatform.log.Logger +import kotlin.reflect.KClass interface IMessageLogAppender { - fun logError(message: String, e: Exception? = null, logger: Logger? = null, bank: BankData? = null) + fun logError(loggingClass: KClass<*>, message: String, e: Exception? = null) } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt index b22aeba3..8213ab49 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt @@ -8,6 +8,7 @@ import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.Date import net.dankito.utils.multiplatform.StackTraceHelper import net.dankito.utils.multiplatform.getInnerException +import kotlin.reflect.KClass open class MessageLogCollector { @@ -32,7 +33,7 @@ open class MessageLogCollector { protected open val stackTraceHelper = StackTraceHelper() - open fun addMessageLog(message: String, type: MessageLogEntryType, bank: BankData) { + open fun addMessageLog(bank: BankData, type: MessageLogEntryType, message: String) { val timeStamp = Date() val prettyPrintMessage = prettyPrintHbciMessage(message) @@ -46,13 +47,11 @@ open class MessageLogCollector { } - open fun logError(message: String, e: Exception? = null, logger: Logger? = null, bank: BankData?) { - val loggerToUse = logger ?: log - + open fun logError(loggingClass: KClass<*>, bank: BankData, message: String, e: Exception? = null) { if (e != null) { - loggerToUse.error(e) { message } + getLogger(loggingClass).error(e) { message } } else { - loggerToUse.error(message) + getLogger(loggingClass).error(message) } val errorStackTrace = if (e != null) "\r\n" + getStackTrace(e) else "" @@ -114,4 +113,8 @@ open class MessageLogCollector { return stackTraceHelper.getStackTrace(innerException, MaxCountStackTraceElements) } + protected open fun getLogger(loggingClass: KClass<*>): Logger { + return LoggerFactory.getLogger(loggingClass) + } + } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt index f4d1ae59..1a9055e2 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt @@ -1,8 +1,14 @@ package net.dankito.banking.fints.model import net.dankito.banking.fints.callback.FinTsClientCallback +import net.dankito.banking.fints.log.IMessageLogAppender +import net.dankito.banking.fints.log.MessageLogCollector import net.dankito.banking.fints.messages.datenelemente.implementierte.signatur.VersionDesSicherheitsverfahrens import net.dankito.banking.fints.response.BankResponse +import net.dankito.banking.fints.transactions.IAccountTransactionsParser +import net.dankito.banking.fints.transactions.Mt940AccountTransactionsParser +import net.dankito.banking.fints.transactions.mt940.Mt940Parser +import kotlin.reflect.KClass open class JobContext( @@ -13,12 +19,18 @@ open class JobContext( /** * Only set if the current context is for a specific account (like get account's transactions). */ - open val account: AccountData? = null -) : MessageBaseData(bank, product) { + open val account: AccountData? = null, + protected open val messageLogCollector: MessageLogCollector = MessageLogCollector() +) : MessageBaseData(bank, product), IMessageLogAppender { protected open val _dialogs = mutableListOf() + open val mt940Parser: IAccountTransactionsParser = Mt940AccountTransactionsParser(Mt940Parser(this), this) + + open val messageLogWithoutSensitiveData: List + get() = messageLogCollector.messageLogWithoutSensitiveData + open var dialog: DialogContext = DialogContext() // create null value so that variable is not null protected set @@ -27,7 +39,7 @@ open class JobContext( get() = ArrayList(_dialogs) // create a copy - fun startNewDialog(closeDialog: Boolean = true, dialogId: String = DialogContext.InitialDialogId, + open fun startNewDialog(closeDialog: Boolean = true, dialogId: String = DialogContext.InitialDialogId, versionOfSecurityProcedure: VersionDesSicherheitsverfahrens = VersionDesSicherheitsverfahrens.Version_2, chunkedResponseHandler: ((BankResponse) -> Unit)? = null) : DialogContext { val newDialogContext = DialogContext(closeDialog, dialogId = dialogId, chunkedResponseHandler = chunkedResponseHandler) @@ -41,4 +53,13 @@ open class JobContext( return newDialogContext } + + open fun addMessageLog(type: MessageLogEntryType, message: String) { + messageLogCollector.addMessageLog(bank, type, message) + } + + override fun logError(loggingClass: KClass<*>, message: String, e: Exception?) { + messageLogCollector.logError(loggingClass, bank, message, e) + } + } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt index ccb9fb68..73ea308a 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt @@ -1022,7 +1022,7 @@ open class ResponseParser( protected open fun logError(message: String, e: Exception?) { logAppender?.let { logAppender -> - logAppender.logError(message, e, log) + logAppender.logError(ResponseParser::class, message, e) } ?: run { log.error(e) { message } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/AddAccountResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/AddAccountResponse.kt index 99c2dd94..95b07c7e 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/AddAccountResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/AddAccountResponse.kt @@ -5,10 +5,11 @@ import net.dankito.banking.fints.response.BankResponse open class AddAccountResponse( + context: JobContext, response: BankResponse, open val bank: BankData, retrievedData: List = listOf() -) : GetTransactionsResponse(response, retrievedData) { +) : GetTransactionsResponse(context, response, retrievedData) { override val successful: Boolean get() = super.successful && bank.accounts.isNotEmpty() diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt index dc597b25..350c9bbc 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/FinTsClientResponse.kt @@ -1,5 +1,7 @@ package net.dankito.banking.fints.response.client +import net.dankito.banking.fints.model.JobContext +import net.dankito.banking.fints.model.MessageLogEntry import net.dankito.banking.fints.response.BankResponse import net.dankito.banking.fints.response.segments.TanResponse @@ -13,6 +15,8 @@ open class FinTsClientResponse( open val isStrongAuthenticationRequired: Boolean, open val tanRequired: TanResponse? = null, + open val messageLogWithoutSensitiveData: List, + /** * A fints4k internal error like an error occurred during web request or response parsing. */ @@ -34,9 +38,9 @@ open class FinTsClientResponse( ) { - constructor(response: BankResponse) : this(response.successful, response.noTanMethodSelected, - response.isStrongAuthenticationRequired, response.tanResponse, response.internalError, - response.errorsToShowToUser, response.wrongCredentialsEntered, + constructor(context: JobContext, response: BankResponse) : this(response.successful, response.noTanMethodSelected, + response.isStrongAuthenticationRequired, response.tanResponse, context.messageLogWithoutSensitiveData, + response.internalError, response.errorsToShowToUser, response.wrongCredentialsEntered, response.tanRequiredButUserDidNotEnterOne, response.tanRequiredButWeWereToldToAbortIfSo, response.messageThatCouldNotBeCreated?.isJobAllowed ?: true, response.messageThatCouldNotBeCreated?.isJobVersionSupported ?: true, diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTanMediaListResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTanMediaListResponse.kt index 682d3497..3a9acdbc 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTanMediaListResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTanMediaListResponse.kt @@ -1,11 +1,13 @@ package net.dankito.banking.fints.response.client +import net.dankito.banking.fints.model.JobContext import net.dankito.banking.fints.response.BankResponse import net.dankito.banking.fints.response.segments.TanMediaList open class GetTanMediaListResponse( + context: JobContext, response: BankResponse, val tanMediaList: TanMediaList? ) - : FinTsClientResponse(response) \ No newline at end of file + : FinTsClientResponse(context, response) \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt index 713339a0..bb1d782a 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/client/GetTransactionsResponse.kt @@ -1,17 +1,19 @@ package net.dankito.banking.fints.response.client +import net.dankito.banking.fints.model.JobContext import net.dankito.banking.fints.model.RetrievedAccountData import net.dankito.banking.fints.response.BankResponse open class GetTransactionsResponse( + context: JobContext, response: BankResponse, open val retrievedData: List = listOf(), /** * 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 -) : FinTsClientResponse(response) { +) : FinTsClientResponse(context, response) { override val successful: Boolean get() = super.successful diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt index 847795e5..3a28e1db 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt @@ -9,7 +9,7 @@ import net.dankito.banking.fints.transactions.mt940.model.Balance import net.dankito.banking.fints.transactions.mt940.model.Transaction import net.dankito.banking.fints.transactions.mt940.model.StatementLine import net.dankito.utils.multiplatform.log.LoggerFactory -import net.dankito.utils.multiplatform.log.Logger +import kotlin.reflect.KClass open class Mt940AccountTransactionsParser( @@ -121,8 +121,8 @@ open class Mt940AccountTransactionsParser( mt940Parser.logAppender = logAppender?.let { logAppender -> object : IMessageLogAppender { - override fun logError(message: String, e: Exception?, logger: Logger?, bank: BankData?) { - logAppender.logError(message, e, logger, bank ?: bankDataOfCall) + override fun logError(loggingClass: KClass<*>, message: String, e: Exception?) { + logAppender.logError(loggingClass, message, e) } } @@ -131,7 +131,7 @@ open class Mt940AccountTransactionsParser( protected open fun logError(message: String, e: Exception?, bank: BankData) { logAppender?.let { logAppender -> - logAppender.logError(message, e, log, bank) + logAppender.logError(Mt940AccountTransactionsParser::class, message, e) } ?: run { log.error(e) { message } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt index 835338d4..6d1582c6 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt @@ -23,7 +23,9 @@ user‐to‐user messages. Character ”‐” is not permitted as the first character of the line. None of lines include only Space. */ -open class Mt940Parser : IMt940Parser { +open class Mt940Parser( + override var logAppender: IMessageLogAppender? = null +) : IMt940Parser { companion object { val AccountStatementsSeparatorRegex = Regex("^\\s*-\\s*\$", RegexOption.MULTILINE) // a line only with '-' and may other white space characters @@ -78,9 +80,6 @@ open class Mt940Parser : IMt940Parser { } - override var logAppender: IMessageLogAppender? = null - - /** * Parses a whole MT 940 statements string, that is one that ends with a "-" line. */ @@ -496,7 +495,7 @@ open class Mt940Parser : IMt940Parser { protected open fun logError(message: String, e: Exception?) { logAppender?.let { logAppender -> - logAppender.logError(message, e, log) + logAppender.logError(Mt940Parser::class, message, e) } ?: run { log.error(e) { message } diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt index 80f6aefc..08d1e4f2 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt @@ -53,17 +53,11 @@ open class fints4kBankingClient( protected open val client = FinTsClientForCustomer(fintsBank, createFinTsClientCallback(callback), webClient, base64Service) + protected open val _messageLogWithoutSensitiveData: MutableList = mutableListOf() + override val messageLogWithoutSensitiveData: List - get() = client.messageLogWithoutSensitiveData.map { MessageLogEntry(it.message, map(it.type), it.time, bank) } - - protected open fun map(type: MessageLogEntryType): net.dankito.banking.ui.model.MessageLogEntryType { - return when (type) { - MessageLogEntryType.Sent -> net.dankito.banking.ui.model.MessageLogEntryType.Sent - MessageLogEntryType.Received -> net.dankito.banking.ui.model.MessageLogEntryType.Received - MessageLogEntryType.Error -> net.dankito.banking.ui.model.MessageLogEntryType.Error - } - } + get() = ArrayList(_messageLogWithoutSensitiveData) override fun addAccountAsync(callback: (AddAccountResponse) -> Unit) { @@ -84,7 +78,7 @@ open class fints4kBankingClient( val mappedResponse = mapper.mapResponse(bank, response) - saveData() + saveData(response) callback(mappedResponse) } @@ -124,7 +118,7 @@ open class fints4kBankingClient( callback: (GetTransactionsResponse) -> Unit) { val mappedResponse = mapper.mapResponse(account, response) - saveData() + saveData(response) callback(mappedResponse) } @@ -156,7 +150,7 @@ open class fints4kBankingClient( } protected open fun handleBankTransferResponse(callback: (BankingClientResponse) -> Unit, response: FinTsClientResponse) { - saveData() + saveData(response) callback(mapper.mapResponse(response)) } @@ -218,8 +212,11 @@ open class fints4kBankingClient( return null } - protected open fun saveData() { + protected open fun saveData(response: FinTsClientResponse) { try { + _messageLogWithoutSensitiveData.addAll(response.messageLogWithoutSensitiveData + .map { MessageLogEntry(it.message, map(it.type), it.time, bank) }) + // TODO: fix that real (child) class get serialized and re-enable again // val clientDataFile = getFints4kClientDataFile(fintsBank.bankCode, fintsBank.customerId) // @@ -229,6 +226,14 @@ open class fints4kBankingClient( } } + protected open fun map(type: MessageLogEntryType): net.dankito.banking.ui.model.MessageLogEntryType { + return when (type) { + MessageLogEntryType.Sent -> net.dankito.banking.ui.model.MessageLogEntryType.Sent + MessageLogEntryType.Received -> net.dankito.banking.ui.model.MessageLogEntryType.Received + MessageLogEntryType.Error -> net.dankito.banking.ui.model.MessageLogEntryType.Error + } + } + protected open fun getFints4kClientDataFile(bank: TypedBankData): File { return getFints4kClientDataFile(bank.bankCode, bank.userName) }