From def4e1f74ef2b007aefbe099291b1a5eb3eaecce Mon Sep 17 00:00:00 2001 From: dankl Date: Wed, 16 Oct 2019 16:47:00 +0200 Subject: [PATCH] Implemented parsing CommunicationInfo (HIKOM) --- .../kotlin/net/dankito/fints/FinTsClient.kt | 7 ++++- .../fints/response/InstituteSegmentId.kt | 2 ++ .../dankito/fints/response/ResponseParser.kt | 26 ++++++++++++++-- .../response/segments/CommunicationInfo.kt | 13 ++++++++ .../segments/CommunicationParameter.kt | 31 +++++++++++++++++++ .../response/segments/Kommunikationsdienst.kt | 22 +++++++++++++ .../kotlin/net/dankito/fints/FinTsTestBase.kt | 6 +++- .../fints/response/ResponseParserTest.kt | 26 ++++++++++++++++ 8 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationInfo.kt create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationParameter.kt create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/Kommunikationsdienst.kt diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index d3f14b67..ad107997 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -478,13 +478,18 @@ open class FinTsClient @JvmOverloads constructor( bank.supportedLanguages = bankParameters.supportedLanguages // bank.bic = bankParameters. // TODO: where's the BIC? -// bank.finTs3ServerAddress = // TODO: parse HIKOM } response.getFirstSegmentById(InstituteSegmentId.TanInfo)?.let { tanInfo -> bank.supportedTanProcedures = mapToTanProcedures(tanInfo) } + response.getFirstSegmentById(InstituteSegmentId.CommunicationInfo)?.let { communicationInfo -> + communicationInfo.parameters.firstOrNull { it.type == Kommunikationsdienst.Https }?.address?.let { address -> + bank.finTs3ServerAddress = if (address.startsWith("https://", true)) address else "https://$address" + } + } + if (response.supportedJobs.isNotEmpty()) { bank.supportedJobs = response.supportedJobs } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/InstituteSegmentId.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/InstituteSegmentId.kt index 968ed315..d25d049a 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/InstituteSegmentId.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/InstituteSegmentId.kt @@ -15,6 +15,8 @@ enum class InstituteSegmentId(override val id: String) : ISegmentId { SecurityMethods("HISHV"), + CommunicationInfo("HIKOM"), + UserParameters("HIUPA"), AccountInfo("HIUPD"), diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt index 6a4bbb05..ada92a90 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/ResponseParser.kt @@ -83,6 +83,7 @@ open class ResponseParser @JvmOverloads constructor( InstituteSegmentId.Synchronization.id -> parseSynchronization(segment, dataElementGroups) InstituteSegmentId.BankParameters.id -> parseBankParameters(segment, dataElementGroups) InstituteSegmentId.SecurityMethods.id -> parseSecurityMethods(segment, dataElementGroups) + InstituteSegmentId.CommunicationInfo.id -> parseCommunicationInfo(segment, dataElementGroups) InstituteSegmentId.UserParameters.id -> parseUserParameters(segment, dataElementGroups) InstituteSegmentId.AccountInfo.id -> parseAccountInfo(segment, dataElementGroups) @@ -176,6 +177,25 @@ open class ResponseParser @JvmOverloads constructor( return SecurityMethods(mixingAllowed, profiles, segment) } + protected open fun parseCommunicationInfo(segment: String, dataElementGroups: List): CommunicationInfo { + val bankDetails = parseBankDetails(dataElementGroups[1]) + val defaultLanguage = parseLanguage(dataElementGroups[2]) + val parameters = parseCommunicationParameters(dataElementGroups.subList(3, dataElementGroups.size)) + + return CommunicationInfo(bankDetails, defaultLanguage, parameters, segment) + } + + protected open fun parseCommunicationParameters(dataElementGroups: List): List { + return dataElementGroups.map { dataElementGroup -> + val dataElements = getDataElements(dataElementGroup) + + CommunicationParameter( + parseCodeEnum(dataElements[0], Kommunikationsdienst.values()), + dataElements[1] + ) + } + } + protected open fun parseUserParameters(segment: String, dataElementGroups: List): UserParameters { val customerId = parseString(dataElementGroups[1]) @@ -388,9 +408,11 @@ open class ResponseParser @JvmOverloads constructor( } protected open fun parseLanguages(dataElementsGroup: String): List { - val languageStrings = getDataElements(dataElementsGroup) + return getDataElements(dataElementsGroup).map { parseLanguage(it) } + } - return parseCodeEnum(languageStrings, Dialogsprache.values()) + protected open fun parseLanguage(dataElementsGroup: String): Dialogsprache { + return parseCodeEnum(dataElementsGroup, Dialogsprache.values()) } protected open fun parseHbciVersions(dataElementsGroup: String): List { diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationInfo.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationInfo.kt new file mode 100644 index 00000000..af9f05bd --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationInfo.kt @@ -0,0 +1,13 @@ +package net.dankito.fints.response.segments + +import net.dankito.fints.messages.datenelemente.implementierte.Dialogsprache +import net.dankito.fints.messages.datenelementgruppen.implementierte.Kreditinstitutskennung + + +open class CommunicationInfo( + val bankInfo: Kreditinstitutskennung, + val defaultLanguage: Dialogsprache, + val parameters: List, + segmentString: String +) + : ReceivedSegment(segmentString) \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationParameter.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationParameter.kt new file mode 100644 index 00000000..8d1415dd --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/CommunicationParameter.kt @@ -0,0 +1,31 @@ +package net.dankito.fints.response.segments + + +open class CommunicationParameter( + val type: Kommunikationsdienst, + val address: String +) { + + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is CommunicationParameter) return false + + if (type != other.type) return false + if (address != other.address) return false + + return true + } + + override fun hashCode(): Int { + var result = type.hashCode() + result = 31 * result + address.hashCode() + return result + } + + + override fun toString(): String { + return "$type $address" + } + +} \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/Kommunikationsdienst.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/Kommunikationsdienst.kt new file mode 100644 index 00000000..3b34e342 --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/segments/Kommunikationsdienst.kt @@ -0,0 +1,22 @@ +package net.dankito.fints.response.segments + +import net.dankito.fints.messages.datenelemente.implementierte.ICodeEnum + + +/** + * Unterstütztes Kommunikationsverfahren (Protokollstack). +Zur Zeit unterstützte Kommunikationsverfahren: +1: T-Online (mit FinTS V3.0 nicht mehr unterstützt) +2: TCP/IP (Protokollstack SLIP/PPP) +13: https (verwendet im Sicherheitsverfahren PIN/TAN) + + */ +enum class Kommunikationsdienst(override val code: String) : ICodeEnum { + + T_Online("1"), + + TCP_IP("2"), + + Https("3") + +} \ No newline at end of file diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsTestBase.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsTestBase.kt index dcfbc2fd..a9e0a906 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsTestBase.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsTestBase.kt @@ -14,7 +14,11 @@ abstract class FinTsTestBase { companion object { const val BankCode = "12345678" - val Bank = BankData(BankCode, Laenderkennzeichen.Germany, "") + val BankCountryCode = Laenderkennzeichen.Germany + + val BankFinTsServerAddress = "banking.supi-dupi-bank.de/fints30" + + val Bank = BankData(BankCode, BankCountryCode, "") const val CustomerId = "0987654321" diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt index 872b2b1b..e419c0bd 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/response/ResponseParserTest.kt @@ -322,6 +322,32 @@ class ResponseParserTest : FinTsTestBase() { ?: run { Assert.fail("No segment of type SecurityMethods found in ${result.receivedSegments}") } } + @Test + fun parseCommunicationInfo() { + + // given + val language = Dialogsprache.German + + // when + val result = underTest.parse("HIKOM:5:4:3+$BankCountryCode:$BankCode+1+3:$BankFinTsServerAddress+2:$BankFinTsServerAddress::MIM:1'") + + // then + assertSuccessfullyParsedSegment(result, InstituteSegmentId.CommunicationInfo, 5, 4, 3) + + result.getFirstSegmentById(InstituteSegmentId.CommunicationInfo)?.let { segment -> + assertThat(segment.bankInfo.bankCountryCode).isEqualTo(BankCountryCode) + assertThat(segment.bankInfo.bankCode).isEqualTo(BankCode) + + assertThat(segment.defaultLanguage).isEqualTo(language) + + assertThat(segment.parameters).containsExactlyInAnyOrder( + CommunicationParameter(Kommunikationsdienst.Https, BankFinTsServerAddress), + CommunicationParameter(Kommunikationsdienst.TCP_IP, BankFinTsServerAddress) + ) + } + ?: run { Assert.fail("No segment of type CommunicationInfo found in ${result.receivedSegments}") } + } + @Test fun parseUserParameters() {