Renamed Mt940AccountTransactionsParser to Mt940Parser and parseTransactions() to parseMt940String()

This commit is contained in:
dankl 2019-10-12 12:37:08 +02:00 committed by dankito
parent 149097fe33
commit f54c082af0
4 changed files with 25 additions and 25 deletions

View File

@ -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>
}

View File

@ -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>
}

View File

@ -21,7 +21,7 @@ usertouser messages.
Character is not permitted as the first character of the line.
None of lines include only Space.
*/
open class Mt940AccountTransactionsParser : IAccountTransactionsParser {
open class Mt940Parser : IMt940Parser {
companion object {
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}\\+")
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 {
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(transactionsString)
val singleAccountStatementsStrings = splitIntoSingleAccountStatements(mt940String)
return singleAccountStatementsStrings.mapNotNull { parseAccountStatement(it) }
} 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()
}
protected open fun splitIntoSingleAccountStatements(transactionsString: String): List<String> {
protected open fun splitIntoSingleAccountStatements(mt940String: String): List<String> {
val accountStatements = mutableListOf<String>()
val lines = transactionsString.split("\n")
val lines = mt940String.split("\n")
var lastMatchedLine = 0
lines.forEachIndexed { index, line ->
if (line == "-") {

View File

@ -1,6 +1,6 @@
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.TransactionDetails
import net.dankito.fints.transactions.mt940.model.Turnover
@ -11,7 +11,7 @@ import java.text.SimpleDateFormat
import java.util.*
class Mt940AccountTransactionsParserTest {
class Mt940ParserTest {
companion object {
const val TestFilesFolderName = "test_files/"
@ -43,14 +43,14 @@ class Mt940AccountTransactionsParserTest {
val AccountStatement1With2TransactionsClosingBalanceAmount = AccountStatement1OpeningBalanceAmount + AccountStatement1Transaction1Amount - AccountStatement1Transaction2Amount
}
private val underTest = Mt940AccountTransactionsParser()
private val underTest = Mt940Parser()
@Test
fun accountStatementWithSingleTransaction() {
// when
val result = underTest.parseTransactions(AccountStatementWithSingleTransaction)
val result = underTest.parseMt940String(AccountStatementWithSingleTransaction)
// then
@ -75,7 +75,7 @@ class Mt940AccountTransactionsParserTest {
fun accountStatementWithTwoTransactions() {
// when
val result = underTest.parseTransactions(AccountStatementWithTwoTransactions)
val result = underTest.parseMt940String(AccountStatementWithTwoTransactions)
// then
@ -105,12 +105,12 @@ class Mt940AccountTransactionsParserTest {
fun parseTransactions() {
// given
val fileStream = Mt940AccountTransactionsParserTest::class.java.classLoader.getResourceAsStream(TransactionsMt940FileRelativePath)
val fileStream = Mt940ParserTest::class.java.classLoader.getResourceAsStream(TransactionsMt940FileRelativePath)
val transactionsString = fileStream.reader().readText()
// when
val result = underTest.parseTransactions(transactionsString)
val result = underTest.parseMt940String(transactionsString)
// then
@ -182,7 +182,7 @@ class Mt940AccountTransactionsParserTest {
}
private fun convertDate(date: Date): String {
return Mt940AccountTransactionsParser.DateFormat.format(date)
return Mt940Parser.DateFormat.format(date)
}
private fun convertToShortBookingDate(date: Date): String {