From 6aa03bcad2c8012d0e542d4e1c36c07952a6f385 Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 13 Nov 2021 00:47:39 +0100 Subject: [PATCH] Implemented setting current message type on DialogContext; logging job and message type --- .../dankito/banking/fints/FinTsJobExecutor.kt | 2 - .../banking/fints/log/MessageContext.kt | 4 ++ .../banking/fints/log/MessageLogCollector.kt | 7 ++-- .../banking/fints/messages/MessageBuilder.kt | 42 +++++++++---------- .../banking/fints/model/DialogContext.kt | 9 +++- .../dankito/banking/fints/model/JobContext.kt | 2 +- .../banking/fints/model/MessageType.kt | 30 +++++++++++++ 7 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageType.kt 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 9996fb5d..af05bdd5 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt @@ -17,8 +17,6 @@ import net.dankito.banking.fints.response.client.GetUserTanMethodsResponse import net.dankito.banking.fints.response.segments.* import net.dankito.banking.fints.tan.FlickerCodeDecoder import net.dankito.banking.fints.tan.TanImageDecoder -import net.dankito.banking.fints.transactions.IAccountTransactionsParser -import net.dankito.banking.fints.transactions.Mt940AccountTransactionsParser import net.dankito.banking.fints.util.TanMethodSelector import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.Date diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageContext.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageContext.kt index 8177783e..fbe67de8 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageContext.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageContext.kt @@ -2,9 +2,13 @@ package net.dankito.banking.fints.log import net.dankito.banking.fints.model.AccountData import net.dankito.banking.fints.model.BankData +import net.dankito.banking.fints.model.MessageType +import net.dankito.banking.fints.model.JobContextType class MessageContext( + val jobType: JobContextType, + val dialogType: MessageType, val jobNumber: Int, val dialogNumber: Int, val messageNumber: Int, 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 24d27e49..7363d55b 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 @@ -64,15 +64,16 @@ open class MessageLogCollector { protected open fun createMessageTraceString(type: MessageLogEntryType, context: MessageContext): String { return "${twoDigits(context.jobNumber)}_${twoDigits(context.dialogNumber)}_${twoDigits(context.messageNumber)}_" + "${context.bank.bankCode}_${context.bank.customerId}" + - "${ context.account?.let { "_${it.accountIdentifier}" } ?: "" } " + - "${getTypeString(type)}:" + "${ context.account?.let { "_${it.accountIdentifier}" } ?: "" }_" + + "${context.jobType.name}_${context.dialogType.name} " + + "${getMessageTypeString(type)}:" } protected open fun twoDigits(number: Int): String { return StringHelper.format("%02d", number) } - protected open fun getTypeString(type: MessageLogEntryType): String { + protected open fun getMessageTypeString(type: MessageLogEntryType): String { return when (type) { MessageLogEntryType.Sent -> "Sending message" MessageLogEntryType.Received -> "Received message" diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt index 11487353..1016e3ed 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt @@ -60,7 +60,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg */ open fun createAnonymousDialogInitMessage(context: JobContext): MessageBuilderResult { - return createUnsignedMessageBuilderResult(context, listOf( + return createUnsignedMessageBuilderResult(context, MessageType.AnonymousDialogInit, listOf( IdentifikationsSegment(generator.resetSegmentNumber(1), context), Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), context) )) @@ -68,7 +68,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg open fun createAnonymousDialogEndMessage(context: JobContext): MessageBuilderResult { - return createUnsignedMessageBuilderResult(context, listOf( + return createUnsignedMessageBuilderResult(context, MessageType.DialogEnd, listOf( Dialogende(generator.resetSegmentNumber(1), context.dialog) )) } @@ -134,12 +134,12 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg segments.add(Synchronisierung(generator.getNextSegmentNumber(), Synchronisierungsmodus.NeueKundensystemIdZurueckmelden)) } - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.DialogInit, segments) } open fun createSynchronizeCustomerSystemIdMessage(context: JobContext): MessageBuilderResult { - return createSignedMessageBuilderResult(context, listOf( + return createSignedMessageBuilderResult(context, MessageType.SynchronizeCustomerSystemId, listOf( IdentifikationsSegment(generator.resetSegmentNumber(2), context), Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), context), createTwoStepTanSegment(context, CustomerSegmentId.Identification), @@ -149,7 +149,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg open fun createDialogEndMessage(context: JobContext): MessageBuilderResult { - return createSignedMessageBuilderResult(context, listOf( + return createSignedMessageBuilderResult(context, MessageType.DialogEnd, listOf( Dialogende(generator.resetSegmentNumber(2), context.dialog) )) } @@ -187,7 +187,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg addTanSegmentIfRequired(context, CustomerSegmentId.AccountTransactionsMt940, segments) - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.GetTransactions, segments) } protected open fun determineIsSettingMaxCountEntriesAllowed(bank: BankData, segmentId: ISegmentId, supportedJobVersions: List): Boolean { @@ -203,7 +203,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg addTanSegmentIfRequired(context, CustomerSegmentId.CreditCardTransactions, segments) - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.GetCreditCardTransactions, segments) } open fun supportsGetTransactions(account: AccountData): Boolean { @@ -232,7 +232,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg addTanSegmentIfRequired(context, CustomerSegmentId.Balance, segments) - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.GetBalance, segments) } return result @@ -259,7 +259,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg generator.resetSegmentNumber(2), tanMediaKind, tanMediumClass) ) - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.GetTanMedia, segments) } return result @@ -277,7 +277,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg context.bank, newActiveTanMedium, tan, atc) ) - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.ChangeTanMedium, segments) } return result @@ -292,7 +292,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg tanResponse.jobHashValue, tanResponse.jobReference, false, null, tanResponse.tanMediaIdentifier) ) - return createSignedMessageBuilderResult(context, createSignedMessage(context, enteredTan, segments), segments) + return createSignedMessageBuilderResult(context, MessageType.Tan, createSignedMessage(context, enteredTan, segments), segments) } @@ -308,7 +308,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg addTanSegmentIfRequired(context, segmentId, segments) - return createSignedMessageBuilderResult(context, segments) + return createSignedMessageBuilderResult(context, MessageType.TransferMoney, segments) } return result @@ -359,25 +359,25 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg open fun rebuildMessage(context: JobContext, message: MessageBuilderResult): MessageBuilderResult { - return createSignedMessageBuilderResult(context, message.messageBodySegments) + return createSignedMessageBuilderResult(context, context.dialog.messageType, message.messageBodySegments) } - protected open fun createSignedMessageBuilderResult(context: JobContext, segments: List): MessageBuilderResult { - return createSignedMessageBuilderResult(context, createSignedMessage(context, segments), segments) + protected open fun createSignedMessageBuilderResult(context: JobContext, type: MessageType, segments: List): MessageBuilderResult { + return createSignedMessageBuilderResult(context, type, createSignedMessage(context, segments), segments) } - protected open fun createSignedMessageBuilderResult(context: JobContext, createdMessage: String, segments: List): MessageBuilderResult { - return createMessageBuilderResult(context, createdMessage, segments) + protected open fun createSignedMessageBuilderResult(context: JobContext, type: MessageType, createdMessage: String, segments: List): MessageBuilderResult { + return createMessageBuilderResult(context, type, createdMessage, segments) } - protected open fun createUnsignedMessageBuilderResult(context: JobContext, segments: List): MessageBuilderResult { - return createMessageBuilderResult(context, createMessage(context, segments), segments) + protected open fun createUnsignedMessageBuilderResult(context: JobContext, type: MessageType, segments: List): MessageBuilderResult { + return createMessageBuilderResult(context, type, createMessage(context, segments), segments) } - protected open fun createMessageBuilderResult(context: JobContext, createdMessage: String, segments: List): MessageBuilderResult { + protected open fun createMessageBuilderResult(context: JobContext, type: MessageType, createdMessage: String, segments: List): MessageBuilderResult { val message = MessageBuilderResult(createdMessage, segments) - context.dialog.setNextMessage(message) + context.dialog.setNextMessage(type, message) return message } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/DialogContext.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/DialogContext.kt index 55e1c50a..3cf42845 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/DialogContext.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/DialogContext.kt @@ -1,7 +1,6 @@ package net.dankito.banking.fints.model import net.dankito.banking.fints.messages.MessageBuilderResult -import net.dankito.banking.fints.messages.datenelemente.implementierte.signatur.VersionDesSicherheitsverfahrens import net.dankito.banking.fints.response.BankResponse @@ -17,6 +16,10 @@ open class DialogContext( const val InitialMessageNumber = 0 } + + open var messageType: MessageType = MessageType.AnonymousDialogInit + protected set + open var currentMessage: MessageBuilderResult? = null protected set @@ -37,7 +40,9 @@ open class DialogContext( messageNumber++ } - open fun setNextMessage(message: MessageBuilderResult) { + open fun setNextMessage(type: MessageType, message: MessageBuilderResult) { + this.messageType = type + this.previousMessageInDialog = this.currentMessage this.currentMessage = message 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 40e6e1f1..e9eeb495 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 @@ -79,7 +79,7 @@ open class JobContext( } protected open fun createMessageContext(): MessageContext { - return MessageContext(jobNumber, dialog.messageNumber, bank, account) + return MessageContext(type, dialog.messageType, jobNumber, dialogNumber, dialog.messageNumber, bank, account) } } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageType.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageType.kt new file mode 100644 index 00000000..11322bd1 --- /dev/null +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageType.kt @@ -0,0 +1,30 @@ +package net.dankito.banking.fints.model + + +enum class MessageType { + + AnonymousDialogInit, + + DialogInit, + + DialogEnd, + + GetTanMedia, + + ChangeTanMedium, + + SynchronizeCustomerSystemId, + + Tan, + + AddAccount, + + GetBalance, + + GetTransactions, + + GetCreditCardTransactions, + + TransferMoney + +} \ No newline at end of file