Renamed parseMt940Chunk() to parseTransactionsChunk(), parseMt940String() calls now parseMt940Chunk(), added comments
This commit is contained in:
parent
012f164414
commit
4cf2fc0973
|
@ -28,7 +28,7 @@ open class Mt940AccountTransactionsParser @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun parseTransactionsChunk(transactionsChunk: String, account: AccountData): Pair<List<AccountTransaction>, String> {
|
override fun parseTransactionsChunk(transactionsChunk: String, account: AccountData): Pair<List<AccountTransaction>, String> {
|
||||||
val (accountStatements, remainder) = mt940Parser.parseTransactionsChunk(transactionsChunk)
|
val (accountStatements, remainder) = mt940Parser.parseMt940Chunk(transactionsChunk)
|
||||||
|
|
||||||
return Pair(accountStatements.flatMap { mapToAccountTransactions(it, account) }, remainder)
|
return Pair(accountStatements.flatMap { mapToAccountTransactions(it, account) }, remainder)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,22 @@ import net.dankito.banking.fints.transactions.mt940.model.AccountStatement
|
||||||
|
|
||||||
interface IMt940Parser {
|
interface IMt940Parser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a whole MT 940 statements string, that is one that ends with a "-" line.
|
||||||
|
*/
|
||||||
fun parseMt940String(mt940String: String): List<AccountStatement>
|
fun parseMt940String(mt940String: String): List<AccountStatement>
|
||||||
|
|
||||||
fun parseTransactionsChunk(mt940Chunk: String): Pair<List<AccountStatement>, 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<List<AccountStatement>, String>
|
||||||
|
|
||||||
}
|
}
|
|
@ -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<AccountStatement> {
|
override fun parseMt940String(mt940String: String): List<AccountStatement> {
|
||||||
try {
|
return parseMt940Chunk(mt940String).first
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun parseTransactionsChunk(mt940Chunk: String): Pair<List<AccountStatement>, 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<List<AccountStatement>, String> {
|
||||||
try {
|
try {
|
||||||
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList()
|
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940Chunk).toMutableList()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue