From 9a094ed3fca4e6166dbe339053836cefc5e39164 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 13 Oct 2019 13:30:42 +0200 Subject: [PATCH] Implemented setting allowed jobs on account --- .../kotlin/net/dankito/fints/FinTsClient.kt | 30 ++++++++++++++++--- .../net/dankito/fints/model/AccountData.kt | 4 ++- .../net/dankito/fints/response/Response.kt | 10 +++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index e3ef71ad..8e58e415 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -7,10 +7,7 @@ import net.dankito.fints.model.* import net.dankito.fints.response.InstituteSegmentId import net.dankito.fints.response.Response import net.dankito.fints.response.ResponseParser -import net.dankito.fints.response.segments.AccountInfo -import net.dankito.fints.response.segments.BankParameters -import net.dankito.fints.response.segments.ReceivedSynchronization -import net.dankito.fints.response.segments.UserParameters +import net.dankito.fints.response.segments.* import net.dankito.fints.util.IBase64Service import net.dankito.utils.web.client.IWebClient import net.dankito.utils.web.client.OkHttpWebClient @@ -260,6 +257,31 @@ open class FinTsClient( // TODO: may also make use of other info } + + val allowedJobsForBank = response.allowedJobs + if (allowedJobsForBank.isNotEmpty()) { // if allowedJobsForBank is empty than bank didn't send any allowed job + for (account in customer.accounts) { + val allowedJobsForAccount = mutableListOf() + + for (job in allowedJobsForBank) { + if (isJobSupported(account, job)) { + allowedJobsForAccount.add(job) + } + } + + account.allowedJobs = allowedJobsForAccount + } + } + } + + protected open fun isJobSupported(account: AccountData, job: AllowedJob): Boolean { + for (allowedJobName in account.allowedJobNames) { + if (allowedJobName == job.jobName) { + return true + } + } + + return false } protected open fun findExistingAccount(customer: CustomerData, accountInfo: AccountInfo): AccountData? { diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt index 80f3efda..608264f9 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountData.kt @@ -1,6 +1,7 @@ package net.dankito.fints.model import net.dankito.fints.response.segments.AccountType +import net.dankito.fints.response.segments.AllowedJob open class AccountData( @@ -15,7 +16,8 @@ open class AccountData( val accountHolderName: String, val productName: String?, val accountLimit: String?, - val allowedJobNames: List + val allowedJobNames: List, + var allowedJobs: List = listOf() ) { override fun toString(): String { diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt index b2b803a0..5108f43c 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt @@ -55,6 +55,16 @@ open class Response constructor( } + /** + * Returns an empty list of response didn't contain any allowed jobs. + * + * Returns all jobs bank supports otherwise. This does not necessarily mean that they are also allowed for + * customer / account, see [net.dankito.fints.model.AccountData.allowedJobNames]. + */ + open val allowedJobs: List + get() = receivedSegments.mapNotNull { it as? AllowedJob } + + open fun getFirstSegmentById(id: ISegmentId): T? { return getFirstSegmentById(id.id) }