Renamed Mt940AccountTransactionsParser to Mt940Parser and parseTransactions() to parseMt940String()
This commit is contained in:
parent
149097fe33
commit
f54c082af0
|
@ -1,10 +0,0 @@
|
||||||
package net.dankito.fints.transactions.mt940
|
|
||||||
|
|
||||||
import net.dankito.fints.transactions.mt940.model.AccountStatement
|
|
||||||
|
|
||||||
|
|
||||||
interface IAccountTransactionsParser {
|
|
||||||
|
|
||||||
fun parseTransactions(transactionsString: String): List<AccountStatement>
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package net.dankito.fints.transactions.mt940
|
||||||
|
|
||||||
|
import net.dankito.fints.transactions.mt940.model.AccountStatement
|
||||||
|
|
||||||
|
|
||||||
|
interface IMt940Parser {
|
||||||
|
|
||||||
|
fun parseMt940String(mt940String: String): List<AccountStatement>
|
||||||
|
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ user‐to‐user messages.
|
||||||
Character ”‐” is not permitted as the first character of the line.
|
Character ”‐” is not permitted as the first character of the line.
|
||||||
None of lines include only Space.
|
None of lines include only Space.
|
||||||
*/
|
*/
|
||||||
open class Mt940AccountTransactionsParser : IAccountTransactionsParser {
|
open class Mt940Parser : IMt940Parser {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val AccountStatementsSeparatorPattern = Pattern.compile("^\\s*-\\s*\$") // a line only with '-' and may other white space characters
|
val AccountStatementsSeparatorPattern = Pattern.compile("^\\s*-\\s*\$") // a line only with '-' and may other white space characters
|
||||||
|
@ -55,27 +55,27 @@ open class Mt940AccountTransactionsParser : IAccountTransactionsParser {
|
||||||
val UsageTypePattern = Pattern.compile("\\w{4}\\+")
|
val UsageTypePattern = Pattern.compile("\\w{4}\\+")
|
||||||
|
|
||||||
|
|
||||||
private val log = LoggerFactory.getLogger(Mt940AccountTransactionsParser::class.java)
|
private val log = LoggerFactory.getLogger(Mt940Parser::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun parseTransactions(transactionsString: String): List<AccountStatement> {
|
override fun parseMt940String(mt940String: String): List<AccountStatement> {
|
||||||
try {
|
try {
|
||||||
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(transactionsString)
|
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940String)
|
||||||
|
|
||||||
return singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) }
|
return singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) }
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.error("Could not parse account transactions from string:\n$transactionsString", e)
|
log.error("Could not parse account statements from MT940 string:\n$mt940String", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return listOf()
|
return listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected open fun splitIntoSingleAccountStatements(transactionsString: String): List<String> {
|
protected open fun splitIntoSingleAccountStatements(mt940String: String): List<String> {
|
||||||
val accountStatements = mutableListOf<String>()
|
val accountStatements = mutableListOf<String>()
|
||||||
|
|
||||||
val lines = transactionsString.split("\n")
|
val lines = mt940String.split("\n")
|
||||||
var lastMatchedLine = 0
|
var lastMatchedLine = 0
|
||||||
lines.forEachIndexed { index, line ->
|
lines.forEachIndexed { index, line ->
|
||||||
if (line == "-") {
|
if (line == "-") {
|
|
@ -1,6 +1,6 @@
|
||||||
package net.dankito.fints.transactions
|
package net.dankito.fints.transactions
|
||||||
|
|
||||||
import net.dankito.fints.transactions.mt940.Mt940AccountTransactionsParser
|
import net.dankito.fints.transactions.mt940.Mt940Parser
|
||||||
import net.dankito.fints.transactions.mt940.model.Balance
|
import net.dankito.fints.transactions.mt940.model.Balance
|
||||||
import net.dankito.fints.transactions.mt940.model.TransactionDetails
|
import net.dankito.fints.transactions.mt940.model.TransactionDetails
|
||||||
import net.dankito.fints.transactions.mt940.model.Turnover
|
import net.dankito.fints.transactions.mt940.model.Turnover
|
||||||
|
@ -11,7 +11,7 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class Mt940AccountTransactionsParserTest {
|
class Mt940ParserTest {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TestFilesFolderName = "test_files/"
|
const val TestFilesFolderName = "test_files/"
|
||||||
|
@ -43,14 +43,14 @@ class Mt940AccountTransactionsParserTest {
|
||||||
val AccountStatement1With2TransactionsClosingBalanceAmount = AccountStatement1OpeningBalanceAmount + AccountStatement1Transaction1Amount - AccountStatement1Transaction2Amount
|
val AccountStatement1With2TransactionsClosingBalanceAmount = AccountStatement1OpeningBalanceAmount + AccountStatement1Transaction1Amount - AccountStatement1Transaction2Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
private val underTest = Mt940AccountTransactionsParser()
|
private val underTest = Mt940Parser()
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun accountStatementWithSingleTransaction() {
|
fun accountStatementWithSingleTransaction() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.parseTransactions(AccountStatementWithSingleTransaction)
|
val result = underTest.parseMt940String(AccountStatementWithSingleTransaction)
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
@ -75,7 +75,7 @@ class Mt940AccountTransactionsParserTest {
|
||||||
fun accountStatementWithTwoTransactions() {
|
fun accountStatementWithTwoTransactions() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.parseTransactions(AccountStatementWithTwoTransactions)
|
val result = underTest.parseMt940String(AccountStatementWithTwoTransactions)
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
@ -105,12 +105,12 @@ class Mt940AccountTransactionsParserTest {
|
||||||
fun parseTransactions() {
|
fun parseTransactions() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
val fileStream = Mt940AccountTransactionsParserTest::class.java.classLoader.getResourceAsStream(TransactionsMt940FileRelativePath)
|
val fileStream = Mt940ParserTest::class.java.classLoader.getResourceAsStream(TransactionsMt940FileRelativePath)
|
||||||
val transactionsString = fileStream.reader().readText()
|
val transactionsString = fileStream.reader().readText()
|
||||||
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = underTest.parseTransactions(transactionsString)
|
val result = underTest.parseMt940String(transactionsString)
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
@ -182,7 +182,7 @@ class Mt940AccountTransactionsParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertDate(date: Date): String {
|
private fun convertDate(date: Date): String {
|
||||||
return Mt940AccountTransactionsParser.DateFormat.format(date)
|
return Mt940Parser.DateFormat.format(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertToShortBookingDate(date: Date): String {
|
private fun convertToShortBookingDate(date: Date): String {
|
Loading…
Reference in New Issue