Extracted

This commit is contained in:
dankito 2024-08-14 13:29:01 +02:00
parent 4e42a26396
commit e12ab5a5f8
2 changed files with 30 additions and 20 deletions

View File

@ -50,7 +50,7 @@ open class FinTsClient @JvmOverloads constructor(
open suspend fun getAccountDataAsync(param: GetAccountDataParameter): GetAccountDataResponse {
val finTsServerAddress = finTsServerAddressFinder.findFinTsServerAddress(param.bankCode)
if (finTsServerAddress.isNullOrBlank()) {
return GetAccountDataResponse(ErrorCode.BankDoesNotSupportFinTs3, "Either bank does not FinTS 3.0 or we don't know its FinTS server address", null, listOf())
return GetAccountDataResponse(ErrorCode.BankDoesNotSupportFinTs3, "Either bank does not support FinTS 3.0 or we don't know its FinTS server address", null, listOf())
}
val bank = mapper.mapToBankData(param, finTsServerAddress)
@ -94,25 +94,7 @@ open class FinTsClient @JvmOverloads constructor(
protected open suspend fun getAccountData(param: GetAccountDataParameter, bank: BankData, account: AccountData): GetAccountTransactionsResponse {
val context = JobContext(JobContextType.GetTransactions, this.callback, product, bank, account)
val retrieveTransactionsFrom = when (param.retrieveTransactions) {
RetrieveTransactions.No -> LocalDate.todayAtEuropeBerlin() // TODO: implement RetrieveTransactions.No
RetrieveTransactions.OfLast90Days -> calculate90DaysAgo()
RetrieveTransactions.AccordingToRetrieveFromAndTo -> param.retrieveTransactionsFrom
else -> null
}
val retrieveTransactionsTo = when (param.retrieveTransactions) {
RetrieveTransactions.AccordingToRetrieveFromAndTo -> param.retrieveTransactionsTo
else -> null
}
return jobExecutor.getTransactionsAsync(context, GetAccountTransactionsParameter(bank, account, param.retrieveBalance, retrieveTransactionsFrom,
retrieveTransactionsTo, abortIfTanIsRequired = param.abortIfTanIsRequired))
}
private fun calculate90DaysAgo(): LocalDate? {
// Europe/Berlin: we're communicating with German bank servers, so we have to use their time zone
return LocalDate.todayAtEuropeBerlin().minusDays(90)
return jobExecutor.getTransactionsAsync(context, mapper.toGetAccountTransactionsParameter(param, bank, account))
}

View File

@ -1,8 +1,11 @@
package net.dankito.banking.fints.mapper
import kotlinx.datetime.LocalDate
import net.dankito.banking.client.model.*
import net.dankito.banking.client.model.AccountTransaction
import net.dankito.banking.client.model.parameter.FinTsClientParameter
import net.dankito.banking.client.model.parameter.GetAccountDataParameter
import net.dankito.banking.client.model.parameter.RetrieveTransactions
import net.dankito.banking.client.model.response.ErrorCode
import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Laenderkennzeichen
import net.dankito.banking.fints.model.*
@ -10,6 +13,8 @@ import net.dankito.banking.fints.response.client.FinTsClientResponse
import net.dankito.banking.fints.response.client.GetAccountTransactionsResponse
import net.dankito.banking.fints.response.segments.AccountType
import net.dankito.banking.fints.util.BicFinder
import net.dankito.utils.multiplatform.extensions.minusDays
import net.dankito.utils.multiplatform.extensions.todayAtEuropeBerlin
open class FinTsModelMapper {
@ -96,6 +101,29 @@ open class FinTsModelMapper {
}
open fun toGetAccountTransactionsParameter(param: GetAccountDataParameter, bank: BankData, account: AccountData): GetAccountTransactionsParameter {
val retrieveTransactionsFrom = when (param.retrieveTransactions) {
RetrieveTransactions.No -> LocalDate.todayAtEuropeBerlin() // TODO: implement RetrieveTransactions.No
RetrieveTransactions.OfLast90Days -> calculate90DaysAgo()
RetrieveTransactions.AccordingToRetrieveFromAndTo -> param.retrieveTransactionsFrom
else -> null
}
val retrieveTransactionsTo = when (param.retrieveTransactions) {
RetrieveTransactions.AccordingToRetrieveFromAndTo -> param.retrieveTransactionsTo
else -> null
}
return GetAccountTransactionsParameter(bank, account, param.retrieveBalance, retrieveTransactionsFrom,
retrieveTransactionsTo, abortIfTanIsRequired = param.abortIfTanIsRequired)
}
open fun calculate90DaysAgo(): LocalDate {
// Europe/Berlin: we're communicating with German bank servers, so we have to use their time zone
return LocalDate.todayAtEuropeBerlin().minusDays(90)
}
open fun mapErrorCode(response: FinTsClientResponse): ErrorCode? {
return when {
response.didReceiveResponse == false -> ErrorCode.NetworkError