From 57911d835eded8fa82a0c2e348726dd7d3adcba1 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 12 May 2020 19:10:27 +0200 Subject: [PATCH] Moved DialogContext.increaseMessageNumber() to a central place --- .../main/kotlin/net/dankito/fints/FinTsClient.kt | 13 ------------- .../net/dankito/fints/messages/MessageBuilder.kt | 2 ++ .../kotlin/net/dankito/fints/model/DialogContext.kt | 7 ++++--- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 5d236c3a..6cc4649b 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -91,7 +91,6 @@ open class FinTsClient @JvmOverloads constructor( } protected open fun closeAnonymousDialog(dialogContext: DialogContext, response: Response) { - dialogContext.increaseMessageNumber() // TODO: move to MessageBuilder val dialogEndRequestBody = messageBuilder.createAnonymousDialogEndMessage(dialogContext) @@ -273,10 +272,6 @@ open class FinTsClient @JvmOverloads constructor( balanceResponse.getFirstSegmentById(InstituteSegmentId.Balance)?.let { balance = it.balance } - - if (balanceResponse.didReceiveResponse) { - dialogContext.increaseMessageNumber() // TODO: move to MessageBuilder - } } @@ -335,8 +330,6 @@ open class FinTsClient @JvmOverloads constructor( protected open fun getBalanceAfterDialogInit(account: AccountData, dialogContext: DialogContext): Response { - dialogContext.increaseMessageNumber() // TODO: move to MessageBuilder - val message = messageBuilder.createGetBalanceMessage(account, dialogContext) return getAndHandleResponseForMessage(message, dialogContext) @@ -426,8 +419,6 @@ open class FinTsClient @JvmOverloads constructor( } - dialogContext.increaseMessageNumber() // TODO: move to MessageBuilder - val message = createMessage(dialogContext) val response = if (messageMayRequiresTan) getAndHandleResponseForMessageThatMayRequiresTan(message, dialogContext) @@ -474,7 +465,6 @@ open class FinTsClient @JvmOverloads constructor( } protected open fun closeDialog(dialogContext: DialogContext) { - dialogContext.increaseMessageNumber() // TODO: move to MessageBuilder val dialogEndRequestBody = messageBuilder.createDialogEndMessage(dialogContext) @@ -674,9 +664,6 @@ open class FinTsClient @JvmOverloads constructor( protected open fun sendTanToBank(enteredTan: String, tanResponse: TanResponse, dialogContext: DialogContext): Response { - - dialogContext.increaseMessageNumber() // TODO: move to MessageBuilder - val message = messageBuilder.createSendEnteredTanMessage(enteredTan, tanResponse, dialogContext) // TODO: shouldn't we use MessageBuilderResult here as well? diff --git a/fints4k/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt b/fints4k/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt index 43426a3e..0b87aa01 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt @@ -304,6 +304,8 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg open fun createMessage(dialogContext: DialogContext, payloadSegments: List): String { + dialogContext.increaseMessageNumber() + val formattedPayload = formatPayload(payloadSegments) val messageSize = formattedPayload.length + MessageHeaderLength + MessageEndingLength + AddedSeparatorsLength diff --git a/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt b/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt index 95e7654f..1c73989b 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt @@ -10,7 +10,6 @@ open class DialogContext( product: ProductData, var currentMessage: MessageBuilderResult? = null, var dialogId: String = InitialDialogId, - var messageNumber: Int = InitialMessageNumber, var response: Response? = null, var previousMessageInDialog: MessageBuilderResult? = null ) : MessageBaseData(bank, customer, product) { @@ -18,11 +17,13 @@ open class DialogContext( companion object { const val InitialDialogId = "0" - const val InitialMessageNumber = 1 + const val InitialMessageNumber = 0 } + open var messageNumber: Int = InitialMessageNumber + protected set - fun increaseMessageNumber() { + open fun increaseMessageNumber() { messageNumber++ }