diff --git a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt index b1830d2e..a3a50700 100644 --- a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt +++ b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/Mt940AccountTransactionsParser.kt @@ -28,7 +28,7 @@ open class Mt940AccountTransactionsParser @JvmOverloads constructor( } override fun parseTransactionsChunk(transactionsChunk: String, account: AccountData): Pair, String> { - val (accountStatements, remainder) = mt940Parser.parseTransactionsChunk(transactionsChunk) + val (accountStatements, remainder) = mt940Parser.parseMt940Chunk(transactionsChunk) return Pair(accountStatements.flatMap { mapToAccountTransactions(it, account) }, remainder) } diff --git a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/IMt940Parser.kt b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/IMt940Parser.kt index c5aaad4b..7b5d8a20 100644 --- a/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/IMt940Parser.kt +++ b/fints4k/src/main/kotlin/net/dankito/banking/fints/transactions/mt940/IMt940Parser.kt @@ -5,8 +5,22 @@ import net.dankito.banking.fints.transactions.mt940.model.AccountStatement interface IMt940Parser { + /** + * Parses a whole MT 940 statements string, that is one that ends with a "-" line. + */ fun parseMt940String(mt940String: String): List - fun parseTransactionsChunk(mt940Chunk: String): Pair, String> + /** + * Parses incomplete MT 940 statements string, that is ones that not end with a "-" line, + * as the they are returned e.g. if a HKKAZ response is dispersed over multiple messages. + * + * Tries to parse all statements in the string except an incomplete last one and returns an + * incomplete last MT 940 statement (if any) as remainder. + * + * So each single HKKAZ partial response can be parsed immediately, its statements/transactions + * be displayed immediately to user and the remainder then be passed together with next partial + * HKKAZ response to this method till this whole MT 940 statement is parsed. + */ + fun parseMt940Chunk(mt940Chunk: String): Pair, String> } \ No newline at end of file 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 c4f3f241..d348d25e 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 @@ -61,19 +61,25 @@ open class Mt940Parser : IMt940Parser { } + /** + * Parses a whole MT 940 statements string, that is one that ends with a "-" line. + */ override fun parseMt940String(mt940String: String): List { - try { - val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940String) - - return singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) } - } catch (e: Exception) { - log.error("Could not parse account statements from MT940 string:\n$mt940String", e) - } - - return listOf() + return parseMt940Chunk(mt940String).first } - override fun parseTransactionsChunk(mt940Chunk: String): Pair, String> { + /** + * Parses incomplete MT 940 statements string, that is ones that not end with a "-" line, + * as the they are returned e.g. if a HKKAZ response is dispersed over multiple messages. + * + * Tries to parse all statements in the string except an incomplete last one and returns an + * incomplete last MT 940 statement (if any) as remainder. + * + * So each single HKKAZ partial response can be parsed immediately, its statements/transactions + * be displayed immediately to user and the remainder then be passed together with next partial + * HKKAZ response to this method till this whole MT 940 statement is parsed. + */ + override fun parseMt940Chunk(mt940Chunk: String): Pair, String> { try { val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList()