Added enum AccountFeature to be better extensible of upcoming implemented features

This commit is contained in:
dankito 2020-05-13 00:38:26 +02:00
parent 68dc62d02c
commit 8c6c65c7b0
6 changed files with 46 additions and 18 deletions

View File

@ -193,7 +193,7 @@ open class FinTsClient @JvmOverloads constructor(
val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>() val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>()
val balances = mutableMapOf<AccountData, BigDecimal>() val balances = mutableMapOf<AccountData, BigDecimal>()
customer.accounts.forEach { account -> customer.accounts.forEach { account ->
if (account.supportsRetrievingAccountTransactions) { if (account.supportsFeature(AccountFeature.RetrieveAccountTransactions)) {
val response = tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, account, false) val response = tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, account, false)
transactionsOfLast90DaysResponses.add(response) transactionsOfLast90DaysResponses.add(response)
response.balance?.let { balances.put(account, it) } response.balance?.let { balances.put(account, it) }
@ -225,7 +225,7 @@ open class FinTsClient @JvmOverloads constructor(
val now = Date() val now = Date()
val ninetyDaysAgo = Date(now.time - NinetyDaysAgoMilliseconds - now.timezoneOffset * 60 * 1000) // map to UTC val ninetyDaysAgo = Date(now.time - NinetyDaysAgoMilliseconds - now.timezoneOffset * 60 * 1000) // map to UTC
val response = getTransactions(GetTransactionsParameter(account.supportsRetrievingBalance, ninetyDaysAgo), bank, customer, account) val response = getTransactions(GetTransactionsParameter(account.supportsFeature(AccountFeature.RetrieveBalance), ninetyDaysAgo), bank, customer, account)
account.triedToRetrieveTransactionsOfLast90DaysWithoutTan = true account.triedToRetrieveTransactionsOfLast90DaysWithoutTan = true
@ -261,7 +261,7 @@ open class FinTsClient @JvmOverloads constructor(
var balance: BigDecimal? = null var balance: BigDecimal? = null
if (parameter.alsoRetrieveBalance && account.supportsRetrievingBalance) { if (parameter.alsoRetrieveBalance && account.supportsFeature(AccountFeature.RetrieveBalance)) {
val balanceResponse = getBalanceAfterDialogInit(account, dialogContext) val balanceResponse = getBalanceAfterDialogInit(account, dialogContext)
if (balanceResponse.successful == false && balanceResponse.couldCreateMessage == true) { // don't break here if required HKSAL message is not implemented if (balanceResponse.successful == false && balanceResponse.couldCreateMessage == true) { // don't break here if required HKSAL message is not implemented
@ -864,9 +864,9 @@ open class FinTsClient @JvmOverloads constructor(
account.allowedJobs = allowedJobsForAccount account.allowedJobs = allowedJobsForAccount
account.supportsRetrievingAccountTransactions = messageBuilder.supportsGetTransactions(account) account.setSupportsFeature(AccountFeature.RetrieveAccountTransactions, messageBuilder.supportsGetTransactions(account))
account.supportsRetrievingBalance = messageBuilder.supportsGetBalance(account) account.setSupportsFeature(AccountFeature.RetrieveBalance, messageBuilder.supportsGetBalance(account))
account.supportsTransferringMoney = messageBuilder.supportsBankTransfer(account) account.setSupportsFeature(AccountFeature.TransferMoney, messageBuilder.supportsBankTransfer(account))
} }
protected open fun mapToTanProcedures(tanInfo: TanInfo): List<TanProcedure> { protected open fun mapToTanProcedures(tanInfo: TanInfo): List<TanProcedure> {

View File

@ -19,15 +19,30 @@ open class AccountData(
val accountLimit: String?, val accountLimit: String?,
val allowedJobNames: List<String>, val allowedJobNames: List<String>,
var allowedJobs: List<JobParameters> = listOf(), var allowedJobs: List<JobParameters> = listOf(),
var supportsRetrievingAccountTransactions: Boolean = false,
var supportsRetrievingBalance: Boolean = false,
var supportsTransferringMoney: Boolean = false,
var supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean? = null, var supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean? = null,
var triedToRetrieveTransactionsOfLast90DaysWithoutTan: Boolean = false var triedToRetrieveTransactionsOfLast90DaysWithoutTan: Boolean = false
) { ) {
internal constructor() : this("", null, Laenderkennzeichen.Germany, "", null, "", null, null, "", null, null, listOf()) // for object deserializers internal constructor() : this("", null, Laenderkennzeichen.Germany, "", null, "", null, null, "", null, null, listOf()) // for object deserializers
protected val supportedFeatures = mutableSetOf<AccountFeature>()
open fun supportsFeature(feature: AccountFeature): Boolean {
return supportedFeatures.contains(feature)
}
open fun setSupportsFeature(feature: AccountFeature, isSupported: Boolean) {
if (isSupported) {
supportedFeatures.add(feature)
}
else {
supportedFeatures.remove(feature)
}
}
override fun toString(): String { override fun toString(): String {
return "$productName $accountIdentifier $accountHolderName" return "$productName $accountIdentifier $accountHolderName"
} }

View File

@ -0,0 +1,12 @@
package net.dankito.fints.model
enum class AccountFeature {
RetrieveAccountTransactions,
RetrieveBalance,
TransferMoney
}

View File

@ -66,7 +66,7 @@ public class JavaShowcase {
/* Other stuff you can do with the lib */ /* Other stuff you can do with the lib */
for (AccountData account : customer.getAccounts()) { // accounts are now retrieved for (AccountData account : customer.getAccounts()) { // accounts are now retrieved
if (account.getSupportsRetrievingAccountTransactions()) { if (account.supportsFeature(AccountFeature.RetrieveAccountTransactions)) {
// retrieves all account transactions, but requires entering a TAN (FinTsClientCallback.enterTan() will be called) // retrieves all account transactions, but requires entering a TAN (FinTsClientCallback.enterTan() will be called)
// GetTransactionsResponse response = finTsClient.getTransactions( // GetTransactionsResponse response = finTsClient.getTransactions(
// new GetTransactionsParameter(true), bank, customer, account); // new GetTransactionsParameter(true), bank, customer, account);
@ -74,7 +74,7 @@ public class JavaShowcase {
// showGetTransactionsResponse(response); // showGetTransactionsResponse(response);
} }
if (account.getSupportsTransferringMoney()) { if (account.supportsFeature(AccountFeature.TransferMoney)) {
// transfer 0.01 to yourself // transfer 0.01 to yourself
// BankTransferData data = new BankTransferData(customer.getName(), account.getIban(), bank.getBic(), new BigDecimal("0.01"), "Hey I can transfer money to myself") // BankTransferData data = new BankTransferData(customer.getName(), account.getIban(), bank.getBic(), new BigDecimal("0.01"), "Hey I can transfer money to myself")
// FinTsClientResponse transferMoneyResponse = finTsClient.doBankTransfer(data, bank, customer, account); // FinTsClientResponse transferMoneyResponse = finTsClient.doBankTransfer(data, bank, customer, account);

View File

@ -139,7 +139,7 @@ class FinTsClientTest {
// given // given
underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts
val account = Customer.accounts.firstOrNull { it.allowedJobNames.contains(CustomerSegmentId.AccountTransactionsMt940.id) } val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }
assertThat(account).describedAs("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").isNotNull() assertThat(account).describedAs("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").isNotNull()
// when // when
@ -194,7 +194,7 @@ class FinTsClientTest {
underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts
// we need at least one account that supports cash transfer // we need at least one account that supports cash transfer
val account = Customer.accounts.firstOrNull { it.allowedJobNames.contains(CustomerSegmentId.SepaBankTransfer.id) } val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) }
assertThat(account).describedAs("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").isNotNull() assertThat(account).describedAs("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").isNotNull()
// IBAN should be set // IBAN should be set

View File

@ -7,6 +7,7 @@ import net.dankito.banking.ui.model.responses.GetTransactionsResponse
import net.dankito.banking.ui.model.tan.* import net.dankito.banking.ui.model.tan.*
import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion
import net.dankito.fints.model.AccountData import net.dankito.fints.model.AccountData
import net.dankito.fints.model.AccountFeature
import net.dankito.fints.model.BankData import net.dankito.fints.model.BankData
import net.dankito.fints.model.CustomerData import net.dankito.fints.model.CustomerData
import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.FinTsClientResponse
@ -103,8 +104,8 @@ open class fints4javaModelMapper {
open fun mapBankAccount(account: Account, accountData: AccountData): BankAccount { open fun mapBankAccount(account: Account, accountData: AccountData): BankAccount {
return BankAccount(account, accountData.accountIdentifier, accountData.accountHolderName, accountData.iban, return BankAccount(account, accountData.accountIdentifier, accountData.accountHolderName, accountData.iban,
accountData.subAccountAttribute, BigDecimal.ZERO, accountData.currency ?: "EUR", accountData.subAccountAttribute, BigDecimal.ZERO, accountData.currency ?: "EUR",
mapBankAccountType(accountData.accountType), accountData.supportsRetrievingAccountTransactions, mapBankAccountType(accountData.accountType), accountData.supportsFeature(AccountFeature.RetrieveAccountTransactions),
accountData.supportsRetrievingBalance, accountData.supportsTransferringMoney) accountData.supportsFeature(AccountFeature.RetrieveBalance), accountData.supportsFeature(AccountFeature.TransferMoney))
} }
open fun mapBankAccountType(type: AccountType?): BankAccountType { open fun mapBankAccountType(type: AccountType?): BankAccountType {
@ -149,9 +150,9 @@ open class fints4javaModelMapper {
open fun updateBankAccount(account: AccountData, updatedAccount: AccountData) { open fun updateBankAccount(account: AccountData, updatedAccount: AccountData) {
account.allowedJobs = updatedAccount.allowedJobs account.allowedJobs = updatedAccount.allowedJobs
account.supportsRetrievingAccountTransactions = updatedAccount.supportsRetrievingAccountTransactions AccountFeature.values().forEach { feature ->
account.supportsRetrievingBalance = updatedAccount.supportsRetrievingBalance account.setSupportsFeature(feature, updatedAccount.supportsFeature(feature))
account.supportsTransferringMoney = updatedAccount.supportsTransferringMoney }
} }
open fun findAccountForBankAccount(customer: CustomerData, bankAccount: BankAccount): AccountData? { open fun findAccountForBankAccount(customer: CustomerData, bankAccount: BankAccount): AccountData? {