Implemented setting current message type on DialogContext; logging job and message type

This commit is contained in:
dankito 2021-11-13 00:47:39 +01:00
parent fba6c2a0d5
commit 6aa03bcad2
7 changed files with 67 additions and 29 deletions

View File

@ -17,8 +17,6 @@ import net.dankito.banking.fints.response.client.GetUserTanMethodsResponse
import net.dankito.banking.fints.response.segments.* import net.dankito.banking.fints.response.segments.*
import net.dankito.banking.fints.tan.FlickerCodeDecoder import net.dankito.banking.fints.tan.FlickerCodeDecoder
import net.dankito.banking.fints.tan.TanImageDecoder 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.banking.fints.util.TanMethodSelector
import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.log.LoggerFactory
import net.dankito.utils.multiplatform.Date import net.dankito.utils.multiplatform.Date

View File

@ -2,9 +2,13 @@ package net.dankito.banking.fints.log
import net.dankito.banking.fints.model.AccountData import net.dankito.banking.fints.model.AccountData
import net.dankito.banking.fints.model.BankData import net.dankito.banking.fints.model.BankData
import net.dankito.banking.fints.model.MessageType
import net.dankito.banking.fints.model.JobContextType
class MessageContext( class MessageContext(
val jobType: JobContextType,
val dialogType: MessageType,
val jobNumber: Int, val jobNumber: Int,
val dialogNumber: Int, val dialogNumber: Int,
val messageNumber: Int, val messageNumber: Int,

View File

@ -64,15 +64,16 @@ open class MessageLogCollector {
protected open fun createMessageTraceString(type: MessageLogEntryType, context: MessageContext): String { protected open fun createMessageTraceString(type: MessageLogEntryType, context: MessageContext): String {
return "${twoDigits(context.jobNumber)}_${twoDigits(context.dialogNumber)}_${twoDigits(context.messageNumber)}_" + return "${twoDigits(context.jobNumber)}_${twoDigits(context.dialogNumber)}_${twoDigits(context.messageNumber)}_" +
"${context.bank.bankCode}_${context.bank.customerId}" + "${context.bank.bankCode}_${context.bank.customerId}" +
"${ context.account?.let { "_${it.accountIdentifier}" } ?: "" } " + "${ context.account?.let { "_${it.accountIdentifier}" } ?: "" }_" +
"${getTypeString(type)}:" "${context.jobType.name}_${context.dialogType.name} " +
"${getMessageTypeString(type)}:"
} }
protected open fun twoDigits(number: Int): String { protected open fun twoDigits(number: Int): String {
return StringHelper.format("%02d", number) return StringHelper.format("%02d", number)
} }
protected open fun getTypeString(type: MessageLogEntryType): String { protected open fun getMessageTypeString(type: MessageLogEntryType): String {
return when (type) { return when (type) {
MessageLogEntryType.Sent -> "Sending message" MessageLogEntryType.Sent -> "Sending message"
MessageLogEntryType.Received -> "Received message" MessageLogEntryType.Received -> "Received message"

View File

@ -60,7 +60,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
*/ */
open fun createAnonymousDialogInitMessage(context: JobContext): MessageBuilderResult { open fun createAnonymousDialogInitMessage(context: JobContext): MessageBuilderResult {
return createUnsignedMessageBuilderResult(context, listOf( return createUnsignedMessageBuilderResult(context, MessageType.AnonymousDialogInit, listOf(
IdentifikationsSegment(generator.resetSegmentNumber(1), context), IdentifikationsSegment(generator.resetSegmentNumber(1), context),
Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), context) Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), context)
)) ))
@ -68,7 +68,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
open fun createAnonymousDialogEndMessage(context: JobContext): MessageBuilderResult { open fun createAnonymousDialogEndMessage(context: JobContext): MessageBuilderResult {
return createUnsignedMessageBuilderResult(context, listOf( return createUnsignedMessageBuilderResult(context, MessageType.DialogEnd, listOf(
Dialogende(generator.resetSegmentNumber(1), context.dialog) 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)) segments.add(Synchronisierung(generator.getNextSegmentNumber(), Synchronisierungsmodus.NeueKundensystemIdZurueckmelden))
} }
return createSignedMessageBuilderResult(context, segments) return createSignedMessageBuilderResult(context, MessageType.DialogInit, segments)
} }
open fun createSynchronizeCustomerSystemIdMessage(context: JobContext): MessageBuilderResult { open fun createSynchronizeCustomerSystemIdMessage(context: JobContext): MessageBuilderResult {
return createSignedMessageBuilderResult(context, listOf( return createSignedMessageBuilderResult(context, MessageType.SynchronizeCustomerSystemId, listOf(
IdentifikationsSegment(generator.resetSegmentNumber(2), context), IdentifikationsSegment(generator.resetSegmentNumber(2), context),
Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), context), Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), context),
createTwoStepTanSegment(context, CustomerSegmentId.Identification), createTwoStepTanSegment(context, CustomerSegmentId.Identification),
@ -149,7 +149,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
open fun createDialogEndMessage(context: JobContext): MessageBuilderResult { open fun createDialogEndMessage(context: JobContext): MessageBuilderResult {
return createSignedMessageBuilderResult(context, listOf( return createSignedMessageBuilderResult(context, MessageType.DialogEnd, listOf(
Dialogende(generator.resetSegmentNumber(2), context.dialog) Dialogende(generator.resetSegmentNumber(2), context.dialog)
)) ))
} }
@ -187,7 +187,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
addTanSegmentIfRequired(context, CustomerSegmentId.AccountTransactionsMt940, segments) 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<Int>): Boolean { protected open fun determineIsSettingMaxCountEntriesAllowed(bank: BankData, segmentId: ISegmentId, supportedJobVersions: List<Int>): Boolean {
@ -203,7 +203,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
addTanSegmentIfRequired(context, CustomerSegmentId.CreditCardTransactions, segments) addTanSegmentIfRequired(context, CustomerSegmentId.CreditCardTransactions, segments)
return createSignedMessageBuilderResult(context, segments) return createSignedMessageBuilderResult(context, MessageType.GetCreditCardTransactions, segments)
} }
open fun supportsGetTransactions(account: AccountData): Boolean { open fun supportsGetTransactions(account: AccountData): Boolean {
@ -232,7 +232,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
addTanSegmentIfRequired(context, CustomerSegmentId.Balance, segments) addTanSegmentIfRequired(context, CustomerSegmentId.Balance, segments)
return createSignedMessageBuilderResult(context, segments) return createSignedMessageBuilderResult(context, MessageType.GetBalance, segments)
} }
return result return result
@ -259,7 +259,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
generator.resetSegmentNumber(2), tanMediaKind, tanMediumClass) generator.resetSegmentNumber(2), tanMediaKind, tanMediumClass)
) )
return createSignedMessageBuilderResult(context, segments) return createSignedMessageBuilderResult(context, MessageType.GetTanMedia, segments)
} }
return result return result
@ -277,7 +277,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
context.bank, newActiveTanMedium, tan, atc) context.bank, newActiveTanMedium, tan, atc)
) )
return createSignedMessageBuilderResult(context, segments) return createSignedMessageBuilderResult(context, MessageType.ChangeTanMedium, segments)
} }
return result return result
@ -292,7 +292,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
tanResponse.jobHashValue, tanResponse.jobReference, false, null, tanResponse.tanMediaIdentifier) 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) addTanSegmentIfRequired(context, segmentId, segments)
return createSignedMessageBuilderResult(context, segments) return createSignedMessageBuilderResult(context, MessageType.TransferMoney, segments)
} }
return result return result
@ -359,25 +359,25 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
open fun rebuildMessage(context: JobContext, message: MessageBuilderResult): MessageBuilderResult { 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<Segment>): MessageBuilderResult { protected open fun createSignedMessageBuilderResult(context: JobContext, type: MessageType, segments: List<Segment>): MessageBuilderResult {
return createSignedMessageBuilderResult(context, createSignedMessage(context, segments), segments) return createSignedMessageBuilderResult(context, type, createSignedMessage(context, segments), segments)
} }
protected open fun createSignedMessageBuilderResult(context: JobContext, createdMessage: String, segments: List<Segment>): MessageBuilderResult { protected open fun createSignedMessageBuilderResult(context: JobContext, type: MessageType, createdMessage: String, segments: List<Segment>): MessageBuilderResult {
return createMessageBuilderResult(context, createdMessage, segments) return createMessageBuilderResult(context, type, createdMessage, segments)
} }
protected open fun createUnsignedMessageBuilderResult(context: JobContext, segments: List<Segment>): MessageBuilderResult { protected open fun createUnsignedMessageBuilderResult(context: JobContext, type: MessageType, segments: List<Segment>): MessageBuilderResult {
return createMessageBuilderResult(context, createMessage(context, segments), segments) return createMessageBuilderResult(context, type, createMessage(context, segments), segments)
} }
protected open fun createMessageBuilderResult(context: JobContext, createdMessage: String, segments: List<Segment>): MessageBuilderResult { protected open fun createMessageBuilderResult(context: JobContext, type: MessageType, createdMessage: String, segments: List<Segment>): MessageBuilderResult {
val message = MessageBuilderResult(createdMessage, segments) val message = MessageBuilderResult(createdMessage, segments)
context.dialog.setNextMessage(message) context.dialog.setNextMessage(type, message)
return message return message
} }

View File

@ -1,7 +1,6 @@
package net.dankito.banking.fints.model package net.dankito.banking.fints.model
import net.dankito.banking.fints.messages.MessageBuilderResult import net.dankito.banking.fints.messages.MessageBuilderResult
import net.dankito.banking.fints.messages.datenelemente.implementierte.signatur.VersionDesSicherheitsverfahrens
import net.dankito.banking.fints.response.BankResponse import net.dankito.banking.fints.response.BankResponse
@ -17,6 +16,10 @@ open class DialogContext(
const val InitialMessageNumber = 0 const val InitialMessageNumber = 0
} }
open var messageType: MessageType = MessageType.AnonymousDialogInit
protected set
open var currentMessage: MessageBuilderResult? = null open var currentMessage: MessageBuilderResult? = null
protected set protected set
@ -37,7 +40,9 @@ open class DialogContext(
messageNumber++ messageNumber++
} }
open fun setNextMessage(message: MessageBuilderResult) { open fun setNextMessage(type: MessageType, message: MessageBuilderResult) {
this.messageType = type
this.previousMessageInDialog = this.currentMessage this.previousMessageInDialog = this.currentMessage
this.currentMessage = message this.currentMessage = message

View File

@ -79,7 +79,7 @@ open class JobContext(
} }
protected open fun createMessageContext(): MessageContext { protected open fun createMessageContext(): MessageContext {
return MessageContext(jobNumber, dialog.messageNumber, bank, account) return MessageContext(type, dialog.messageType, jobNumber, dialogNumber, dialog.messageNumber, bank, account)
} }
} }

View File

@ -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
}