From 8589a4efaa301e087fda663a74de166536967c2c Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 21 May 2020 18:37:49 +0200 Subject: [PATCH] Fixed that non formatted usage parts got joined without spaces making them a bit unreadable --- .../fints/transactions/mt940/Mt940Parser.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt index 42604d75..6065af91 100644 --- a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt @@ -298,7 +298,7 @@ open class Mt940Parser : IMt940Parser { // see Finanzdatenformate p. 209 - 215 val geschaeftsvorfallCode = informationToAccountOwnerString.substring(0, 2) // TODO: may map - val usage = StringBuilder() + val usageParts = mutableListOf() val otherPartyName = StringBuilder() var otherPartyBankCode: String? = null var otherPartyAccountId: String? = null @@ -314,24 +314,31 @@ open class Mt940Parser : IMt940Parser { when (fieldCode) { 0 -> bookingText = fieldValue 10 -> primaNotaNumber = fieldValue - in 20..29 -> usage.append(fieldValue) + in 20..29 -> usageParts.add(fieldValue) 30 -> otherPartyBankCode = fieldValue 31 -> otherPartyAccountId = fieldValue 32, 33 -> otherPartyName.append(fieldValue) 34 -> textKeySupplement = fieldValue - in 60..63 -> usage.append(fieldValue) + in 60..63 -> usageParts.add(fieldValue) } } } + val usage = if (isFormattedUsage(usageParts)) usageParts.joinToString("") + else usageParts.joinToString(" ") + val otherPartyNameString = if (otherPartyName.isEmpty()) null else otherPartyName.toString() return InformationToAccountOwner( - usage.toString(), otherPartyNameString, otherPartyBankCode, otherPartyAccountId, + usage, otherPartyNameString, otherPartyBankCode, otherPartyAccountId, bookingText, primaNotaNumber, textKeySupplement ) } + protected open fun isFormattedUsage(usageParts: List): Boolean { + return usageParts.any { UsageTypePattern.matcher(it).find() } + } + /** * Jeder Bezeichner [z.B. EREF+] muss am Anfang eines Subfeldes [z. B. ?21] stehen. * Bei Längenüberschreitung wird im nachfolgenden Subfeld ohne Wiederholung des Bezeichners fortgesetzt. Bei Wechsel des Bezeichners ist ein neues Subfeld zu beginnen.