Moved prettyPrintFinTsMessage() to FinTsUtils
This commit is contained in:
parent
5ce12fe382
commit
b7c0fec629
|
@ -9,11 +9,13 @@ import net.dankito.banking.fints.model.MessageLogEntryType
|
|||
import net.dankito.banking.fints.extensions.getInnerException
|
||||
import net.dankito.banking.fints.extensions.nthIndexOf
|
||||
import net.dankito.banking.fints.extensions.toStringWithMinDigits
|
||||
import net.dankito.banking.fints.util.FinTsUtils
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
open class MessageLogCollector(
|
||||
private val options: FinTsClientOptions = FinTsClientOptions()
|
||||
private val options: FinTsClientOptions = FinTsClientOptions(),
|
||||
private val finTsUtils: FinTsUtils = FinTsUtils()
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
@ -22,7 +24,7 @@ open class MessageLogCollector(
|
|||
|
||||
const val MaxCountStackTraceElements = 15
|
||||
|
||||
private const val NewLine = "\r\n"
|
||||
internal const val NewLine = "\r\n"
|
||||
|
||||
private val log by logger()
|
||||
}
|
||||
|
@ -39,7 +41,7 @@ open class MessageLogCollector(
|
|||
val message = if (logEntry.type == MessageLogEntryType.Error) {
|
||||
logEntry.messageTrace + logEntry.message + (if (logEntry.error != null) NewLine + getStackTrace(logEntry.error!!) else "")
|
||||
} else {
|
||||
logEntry.messageTrace + "\n" + prettyPrintHbciMessage(logEntry.message)
|
||||
logEntry.messageTrace + "\n" + prettyPrintFinTsMessage(logEntry.message)
|
||||
}
|
||||
|
||||
return if (options.removeSensitiveDataFromMessageLog) {
|
||||
|
@ -55,7 +57,7 @@ open class MessageLogCollector(
|
|||
|
||||
addMessageLogEntry(type, context, messageTrace, message)
|
||||
|
||||
log.debug { "$messageTrace\n${prettyPrintHbciMessage(message)}" }
|
||||
log.debug { "$messageTrace\n${prettyPrintFinTsMessage(message)}" }
|
||||
}
|
||||
|
||||
open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) {
|
||||
|
@ -92,9 +94,8 @@ open class MessageLogCollector(
|
|||
}
|
||||
}
|
||||
|
||||
protected open fun prettyPrintHbciMessage(message: String): String {
|
||||
return message.replace("'", "'$NewLine")
|
||||
}
|
||||
protected open fun prettyPrintFinTsMessage(message: String): String =
|
||||
finTsUtils.prettyPrintFinTsMessage(message)
|
||||
|
||||
|
||||
protected open fun safelyRemoveSensitiveDataFromMessage(message: String, bank: BankData?): String {
|
||||
|
|
|
@ -5,12 +5,19 @@ import kotlinx.datetime.LocalDateTime
|
|||
import kotlinx.datetime.LocalTime
|
||||
import net.dankito.banking.fints.extensions.nowAtEuropeBerlin
|
||||
import net.dankito.banking.fints.extensions.todayAtEuropeBerlin
|
||||
import net.dankito.banking.fints.log.MessageLogCollector
|
||||
import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Datum
|
||||
import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Uhrzeit
|
||||
|
||||
|
||||
open class FinTsUtils {
|
||||
|
||||
companion object {
|
||||
private val NewLine = MessageLogCollector.NewLine
|
||||
|
||||
private val BreakableSegmentSeparatorsRegex = Regex("""'([A-Z])""")
|
||||
}
|
||||
|
||||
|
||||
open fun formatDateToday(): String {
|
||||
return formatDate(LocalDate.todayAtEuropeBerlin())
|
||||
|
@ -46,6 +53,13 @@ open class FinTsUtils {
|
|||
}
|
||||
|
||||
|
||||
open fun prettyPrintFinTsMessage(finTsMessage: String): String {
|
||||
return finTsMessage
|
||||
.replace(BreakableSegmentSeparatorsRegex, "'$NewLine$1")
|
||||
.replace("@HNSHK:", "@${NewLine}HNSHK:")
|
||||
}
|
||||
|
||||
|
||||
protected open fun convertToInt(string: String): Int {
|
||||
return string.toInt()
|
||||
}
|
||||
|
|
|
@ -89,4 +89,23 @@ class FinTsUtilsTest {
|
|||
assertEquals(182251, result)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun prettyPrint() {
|
||||
val result = underTest.prettyPrintFinTsMessage("""HNHBK:1:3+000000000392+300+0+1'HNVSK:998:3+PIN:1+998+1+1::0+1:20240821:022352+2:2:13:@8@ :5:1+280:10010010:UserName:V:0:0+0'HNVSD:999:1+@230@HNSHK:2:4+PIN:1+999+1265303553+1+1+1::0+1+1:20240821:022352+1:999:1+6:10:16+280:10010010:UserName:S:0:0'HKIDN:3:2+280:10010010+UserName+0+0'HKVVB:4:3+0+0+0+15E53C26816138699C7B6A3E8+1.0.0'HKSYN:5:3+0'HNSHA:6:2+1265303553++MyPassword''HNHBS:7:1+1'""")
|
||||
|
||||
assertEquals(result.replace("\r\n", "\n"), """
|
||||
HNHBK:1:3+000000000392+300+0+1'
|
||||
HNVSK:998:3+PIN:1+998+1+1::0+1:20240821:022352+2:2:13:@8@ :5:1+280:10010010:UserName:V:0:0+0'
|
||||
HNVSD:999:1+@230@
|
||||
HNSHK:2:4+PIN:1+999+1265303553+1+1+1::0+1+1:20240821:022352+1:999:1+6:10:16+280:10010010:UserName:S:0:0'
|
||||
HKIDN:3:2+280:10010010+UserName+0+0'
|
||||
HKVVB:4:3+0+0+0+15E53C26816138699C7B6A3E8+1.0.0'
|
||||
HKSYN:5:3+0'
|
||||
HNSHA:6:2+1265303553++MyPassword''
|
||||
HNHBS:7:1+1'
|
||||
""".trimIndent().replace("\r\n", "\n")
|
||||
)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue