Implemented setting allowed jobs on account

This commit is contained in:
dankl 2019-10-13 13:30:42 +02:00 committed by dankito
parent 031629e0c9
commit 9a094ed3fc
3 changed files with 39 additions and 5 deletions

View File

@ -7,10 +7,7 @@ import net.dankito.fints.model.*
import net.dankito.fints.response.InstituteSegmentId import net.dankito.fints.response.InstituteSegmentId
import net.dankito.fints.response.Response import net.dankito.fints.response.Response
import net.dankito.fints.response.ResponseParser import net.dankito.fints.response.ResponseParser
import net.dankito.fints.response.segments.AccountInfo import net.dankito.fints.response.segments.*
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.util.IBase64Service import net.dankito.fints.util.IBase64Service
import net.dankito.utils.web.client.IWebClient import net.dankito.utils.web.client.IWebClient
import net.dankito.utils.web.client.OkHttpWebClient import net.dankito.utils.web.client.OkHttpWebClient
@ -260,6 +257,31 @@ open class FinTsClient(
// TODO: may also make use of other info // 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<AllowedJob>()
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? { protected open fun findExistingAccount(customer: CustomerData, accountInfo: AccountInfo): AccountData? {

View File

@ -1,6 +1,7 @@
package net.dankito.fints.model package net.dankito.fints.model
import net.dankito.fints.response.segments.AccountType import net.dankito.fints.response.segments.AccountType
import net.dankito.fints.response.segments.AllowedJob
open class AccountData( open class AccountData(
@ -15,7 +16,8 @@ open class AccountData(
val accountHolderName: String, val accountHolderName: String,
val productName: String?, val productName: String?,
val accountLimit: String?, val accountLimit: String?,
val allowedJobNames: List<String> val allowedJobNames: List<String>,
var allowedJobs: List<AllowedJob> = listOf()
) { ) {
override fun toString(): String { override fun toString(): String {

View File

@ -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<AllowedJob>
get() = receivedSegments.mapNotNull { it as? AllowedJob }
open fun <T : ReceivedSegment> getFirstSegmentById(id: ISegmentId): T? { open fun <T : ReceivedSegment> getFirstSegmentById(id: ISegmentId): T? {
return getFirstSegmentById(id.id) return getFirstSegmentById(id.id)
} }