Implemented parsing retrieve account transactions in MT940 format job parameters

This commit is contained in:
dankito 2020-09-18 18:50:37 +02:00
parent a64e0b9427
commit 4ed3d44b9e
4 changed files with 72 additions and 1 deletions

View File

@ -37,6 +37,8 @@ enum class InstituteSegmentId(override val id: String) : ISegmentId {
Balance("HISAL"),
AccountTransactionsMt940("HIKAZ")
AccountTransactionsMt940("HIKAZ"),
AccountTransactionsMt940Parameters(AccountTransactionsMt940.id + "S")
}

View File

@ -112,7 +112,9 @@ open class ResponseParser(
InstituteSegmentId.ChangeTanMediaParameters.id -> parseChangeTanMediaParameters(segment, segmentId, dataElementGroups)
InstituteSegmentId.Balance.id -> parseBalanceSegment(segment, dataElementGroups)
InstituteSegmentId.AccountTransactionsMt940.id -> parseMt940AccountTransactions(segment, dataElementGroups)
InstituteSegmentId.AccountTransactionsMt940Parameters.id -> parseMt940AccountTransactionsParameters(segment, segmentId, dataElementGroups)
else -> {
if (JobParametersSegmentRegex.matches(segmentId)) {
@ -657,6 +659,19 @@ open class ResponseParser(
return ReceivedAccountTransactions(bookedTransactionsString, unbookedTransactionsString, segment)
}
protected open fun parseMt940AccountTransactionsParameters(segment: String, segmentId: String, dataElementGroups: List<String>): RetrieveAccountTransactionsInMt940Parameters {
val jobParameters = parseJobParameters(segment, segmentId, dataElementGroups)
val transactionsParameterIndex = if (jobParameters.segmentVersion >= 6) 4 else 3
val dataElements = getDataElements(dataElementGroups[transactionsParameterIndex])
val countDaysForWhichTransactionsAreKept = parseInt(dataElements[0])
val settingCountEntriesAllowed = parseBoolean(dataElements[1])
val settingAllAccountAllowed = if (dataElements.size > 2) parseBoolean(dataElements[2]) else false
return RetrieveAccountTransactionsInMt940Parameters(jobParameters, countDaysForWhichTransactionsAreKept, settingCountEntriesAllowed, settingAllAccountAllowed)
}
protected open fun parseBankDetails(dataElementsGroup: String): Kreditinstitutskennung {
val detailsStrings = getDataElements(dataElementsGroup)

View File

@ -0,0 +1,13 @@
package net.dankito.banking.fints.response.segments
open class RetrieveAccountTransactionsInMt940Parameters(
parameters: JobParameters,
open val countDaysForWhichTransactionsAreKept: Int,
open val settingCountEntriesAllowed: Boolean,
open val settingAllAccountAllowed: Boolean
) : JobParameters(parameters) {
internal constructor() : this(JobParameters(), -1, false, false) // for object deserializers
}

View File

@ -1043,6 +1043,47 @@ class ResponseParserTest : FinTsTestBase() {
}
@Test
fun parseAccountTransactionsMt940Parameters_Version4() {
// given
val countDaysForWhichTransactionsAreKept = 90
// when
val result = underTest.parse("HIKAZS:21:4:4+20+1+$countDaysForWhichTransactionsAreKept:N'")
// then
assertSuccessfullyParsedSegment(result, InstituteSegmentId.AccountTransactionsMt940Parameters, 21, 4, 4)
result.getFirstSegmentById<RetrieveAccountTransactionsInMt940Parameters>(InstituteSegmentId.AccountTransactionsMt940Parameters)?.let { segment ->
expect(segment.countDaysForWhichTransactionsAreKept).toBe(countDaysForWhichTransactionsAreKept)
expect(segment.settingCountEntriesAllowed).isFalse()
expect(segment.settingAllAccountAllowed).isFalse()
}
?: run { fail("No segment of type AccountTransactionsMt940Parameters found in ${result.receivedSegments}") }
}
@Test
fun parseAccountTransactionsMt940Parameters_Version6() {
// given
val countDaysForWhichTransactionsAreKept = 90
// when
val result = underTest.parse("HIKAZS:23:6:4+20+1+1+$countDaysForWhichTransactionsAreKept:N:N'")
// then
assertSuccessfullyParsedSegment(result, InstituteSegmentId.AccountTransactionsMt940Parameters, 23, 6, 4)
result.getFirstSegmentById<RetrieveAccountTransactionsInMt940Parameters>(InstituteSegmentId.AccountTransactionsMt940Parameters)?.let { segment ->
expect(segment.countDaysForWhichTransactionsAreKept).toBe(countDaysForWhichTransactionsAreKept)
expect(segment.settingCountEntriesAllowed).isFalse()
expect(segment.settingAllAccountAllowed).isFalse()
}
?: run { fail("No segment of type AccountTransactionsMt940Parameters found in ${result.receivedSegments}") }
}
private fun assertSuccessfullyParsedSegment(result: Response, segmentId: ISegmentId, segmentNumber: Int,
segmentVersion: Int, referenceSegmentNumber: Int? = null) {