Moved ProductData to JobContext and implemented that startNewDialog() create DialogContext

This commit is contained in:
dankito 2021-11-12 20:53:00 +01:00
parent 0a9b31b393
commit f3552248dc
6 changed files with 49 additions and 42 deletions

View File

@ -18,7 +18,8 @@ import kotlin.jvm.JvmOverloads
*/ */
open class FinTsClient @JvmOverloads constructor( open class FinTsClient @JvmOverloads constructor(
open var callback: FinTsClientCallback, open var callback: FinTsClientCallback,
protected open val jobExecutor: FinTsJobExecutor = FinTsJobExecutor() protected open val jobExecutor: FinTsJobExecutor = FinTsJobExecutor(),
protected open val product: ProductData = ProductData("15E53C26816138699C7B6A3E8", "1.0.0") // TODO: get version dynamically
) { ) {
companion object { companion object {
@ -50,7 +51,7 @@ open class FinTsClient @JvmOverloads constructor(
* On success [bank] parameter is updated afterwards. * On success [bank] parameter is updated afterwards.
*/ */
open fun getAnonymousBankInfo(bank: BankData, callback: (FinTsClientResponse) -> Unit) { open fun getAnonymousBankInfo(bank: BankData, callback: (FinTsClientResponse) -> Unit) {
jobExecutor.getAnonymousBankInfo(JobContext(JobContextType.AnonymousBankInfo, this.callback, bank)) { response -> jobExecutor.getAnonymousBankInfo(JobContext(JobContextType.AnonymousBankInfo, this.callback, product, bank)) { response ->
callback(FinTsClientResponse(response)) callback(FinTsClientResponse(response))
} }
} }
@ -58,7 +59,7 @@ open class FinTsClient @JvmOverloads constructor(
open fun addAccountAsync(parameter: AddAccountParameter, callback: (AddAccountResponse) -> Unit) { open fun addAccountAsync(parameter: AddAccountParameter, callback: (AddAccountResponse) -> Unit) {
val bank = parameter.bank val bank = parameter.bank
val context = JobContext(JobContextType.AddAccount, this.callback, bank) val context = JobContext(JobContextType.AddAccount, this.callback, product, bank)
/* First dialog: Get user's basic data like BPD, customer system ID and her TAN methods */ /* First dialog: Get user's basic data like BPD, customer system ID and her TAN methods */
@ -155,7 +156,7 @@ open class FinTsClient @JvmOverloads constructor(
open fun getTransactionsAsync(parameter: GetTransactionsParameter, bank: BankData, callback: (GetTransactionsResponse) -> Unit) { open fun getTransactionsAsync(parameter: GetTransactionsParameter, bank: BankData, callback: (GetTransactionsResponse) -> Unit) {
val context = JobContext(JobContextType.GetTransactions, this.callback, bank, parameter.account) val context = JobContext(JobContextType.GetTransactions, this.callback, product, bank, parameter.account)
jobExecutor.getTransactionsAsync(context, parameter, callback) jobExecutor.getTransactionsAsync(context, parameter, callback)
} }
@ -164,14 +165,14 @@ open class FinTsClient @JvmOverloads constructor(
open fun getTanMediaList(bank: BankData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle, open fun getTanMediaList(bank: BankData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle,
tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien, callback: (GetTanMediaListResponse) -> Unit) { tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien, callback: (GetTanMediaListResponse) -> Unit) {
val context = JobContext(JobContextType.GetTanMedia, this.callback, bank) val context = JobContext(JobContextType.GetTanMedia, this.callback, product, bank)
jobExecutor.getTanMediaList(context, tanMediaKind, tanMediumClass, callback) jobExecutor.getTanMediaList(context, tanMediaKind, tanMediumClass, callback)
} }
open fun changeTanMedium(newActiveTanMedium: TanGeneratorTanMedium, bank: BankData, callback: (FinTsClientResponse) -> Unit) { open fun changeTanMedium(newActiveTanMedium: TanGeneratorTanMedium, bank: BankData, callback: (FinTsClientResponse) -> Unit) {
val context = JobContext(JobContextType.ChangeTanMedium, this.callback, bank) val context = JobContext(JobContextType.ChangeTanMedium, this.callback, product, bank)
jobExecutor.changeTanMedium(context, newActiveTanMedium) { response -> jobExecutor.changeTanMedium(context, newActiveTanMedium) { response ->
callback(FinTsClientResponse(response)) callback(FinTsClientResponse(response))
@ -180,7 +181,7 @@ open class FinTsClient @JvmOverloads constructor(
open fun doBankTransferAsync(bankTransferData: BankTransferData, bank: BankData, account: AccountData, callback: (FinTsClientResponse) -> Unit) { open fun doBankTransferAsync(bankTransferData: BankTransferData, bank: BankData, account: AccountData, callback: (FinTsClientResponse) -> Unit) {
val context = JobContext(JobContextType.TransferMoney, this.callback, bank, account) val context = JobContext(JobContextType.TransferMoney, this.callback, product, bank, account)
jobExecutor.doBankTransferAsync(context, bankTransferData, callback) jobExecutor.doBankTransferAsync(context, bankTransferData, callback)
} }

View File

@ -32,7 +32,7 @@ open class FinTsClientForCustomer(
: this(bank, callback, RequestExecutor(MessageBuilder(), webClient, base64Service)) : this(bank, callback, RequestExecutor(MessageBuilder(), webClient, base64Service))
protected val client = FinTsClient(callback, FinTsJobExecutor(requestExecutor, messageBuilder, mt940Parser, modelMapper, tanMethodSelector, product)) protected val client = FinTsClient(callback, FinTsJobExecutor(requestExecutor, messageBuilder, mt940Parser, modelMapper, tanMethodSelector), product)
open val messageLogWithoutSensitiveData: List<MessageLogEntry> open val messageLogWithoutSensitiveData: List<MessageLogEntry>

View File

@ -36,8 +36,7 @@ open class FinTsJobExecutor(
protected open val messageBuilder: MessageBuilder = MessageBuilder(), protected open val messageBuilder: MessageBuilder = MessageBuilder(),
protected open val mt940Parser: IAccountTransactionsParser = Mt940AccountTransactionsParser(), protected open val mt940Parser: IAccountTransactionsParser = Mt940AccountTransactionsParser(),
protected open val modelMapper: ModelMapper = ModelMapper(messageBuilder), protected open val modelMapper: ModelMapper = ModelMapper(messageBuilder),
protected open val tanMethodSelector: TanMethodSelector = TanMethodSelector(), protected open val tanMethodSelector: TanMethodSelector = TanMethodSelector()
protected open val product: ProductData = ProductData("15E53C26816138699C7B6A3E8", "1.0.0") // TODO: get version dynamically
) { ) {
companion object { companion object {
@ -55,8 +54,7 @@ open class FinTsJobExecutor(
open fun getAnonymousBankInfo(context: JobContext, callback: (BankResponse) -> Unit) { open fun getAnonymousBankInfo(context: JobContext, callback: (BankResponse) -> Unit) {
val dialogContext = DialogContext(context.bank, product) context.startNewDialog()
context.startNewDialog(dialogContext)
val message = messageBuilder.createAnonymousDialogInitMessage(context) val message = messageBuilder.createAnonymousDialogInitMessage(context)
@ -106,8 +104,7 @@ open class FinTsJobExecutor(
bank.resetSelectedTanMethod() bank.resetSelectedTanMethod()
// this is the only case where Einschritt-TAN-Verfahren is accepted: to get user's TAN methods // this is the only case where Einschritt-TAN-Verfahren is accepted: to get user's TAN methods
val dialogContext = DialogContext(bank, product, closeDialog, versionOfSecurityMethod = VersionDesSicherheitsverfahrens.Version_1) context.startNewDialog(closeDialog, versionOfSecurityMethod = VersionDesSicherheitsverfahrens.Version_1)
context.startNewDialog(dialogContext)
val message = messageBuilder.createInitDialogMessage(context) val message = messageBuilder.createInitDialogMessage(context)
@ -166,8 +163,7 @@ open class FinTsJobExecutor(
getUsersTanMethod(context) { didSelectTanMethod -> getUsersTanMethod(context) { didSelectTanMethod ->
if (didSelectTanMethod) { if (didSelectTanMethod) {
val dialogContext = DialogContext(bank, product) context.startNewDialog()
context.startNewDialog(dialogContext)
initDialogWithStrongCustomerAuthenticationAfterSuccessfulPreconditionChecks(context) { initDialogResponse -> initDialogWithStrongCustomerAuthenticationAfterSuccessfulPreconditionChecks(context) { initDialogResponse ->
closeDialog(context) closeDialog(context)
@ -185,8 +181,7 @@ open class FinTsJobExecutor(
open fun getAccounts(context: JobContext, callback: (BankResponse) -> Unit) { open fun getAccounts(context: JobContext, callback: (BankResponse) -> Unit) {
val dialogContext = DialogContext(context.bank, product, false) context.startNewDialog(false)
context.startNewDialog(dialogContext)
initDialogWithStrongCustomerAuthenticationAfterSuccessfulPreconditionChecks(context) { response -> initDialogWithStrongCustomerAuthenticationAfterSuccessfulPreconditionChecks(context) { response ->
closeDialog(context) closeDialog(context)
@ -198,8 +193,7 @@ open class FinTsJobExecutor(
open fun getTransactionsAsync(context: JobContext, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) { open fun getTransactionsAsync(context: JobContext, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) {
val dialogContext = DialogContext(context.bank, product) val dialogContext = context.startNewDialog()
context.startNewDialog(dialogContext)
initDialogWithStrongCustomerAuthentication(context) { initDialogResponse -> initDialogWithStrongCustomerAuthentication(context) { initDialogResponse ->
@ -300,8 +294,7 @@ open class FinTsJobExecutor(
*/ */
protected open fun synchronizeCustomerSystemId(context: JobContext, callback: (FinTsClientResponse) -> Unit) { protected open fun synchronizeCustomerSystemId(context: JobContext, callback: (FinTsClientResponse) -> Unit) {
val dialogContext = DialogContext(context.bank, product) context.startNewDialog()
context.startNewDialog(dialogContext)
val message = messageBuilder.createSynchronizeCustomerSystemIdMessage(context) val message = messageBuilder.createSynchronizeCustomerSystemIdMessage(context)
@ -522,9 +515,7 @@ open class FinTsJobExecutor(
protected open fun resendMessageInNewDialog(context: JobContext, lastCreatedMessage: MessageBuilderResult?, callback: (BankResponse) -> Unit) { protected open fun resendMessageInNewDialog(context: JobContext, lastCreatedMessage: MessageBuilderResult?, callback: (BankResponse) -> Unit) {
if (lastCreatedMessage != null) { // do not use previousDialogContext.currentMessage as this may is previous dialog's dialog close message if (lastCreatedMessage != null) { // do not use previousDialogContext.currentMessage as this may is previous dialog's dialog close message
val previousDialog = context.dialog context.startNewDialog(chunkedResponseHandler = context.dialog.chunkedResponseHandler)
val newDialogContext = DialogContext(context.bank, previousDialog.product, chunkedResponseHandler = previousDialog.chunkedResponseHandler)
context.startNewDialog(newDialogContext)
initDialogWithStrongCustomerAuthentication(context) { initDialogResponse -> initDialogWithStrongCustomerAuthentication(context) { initDialogResponse ->
if (initDialogResponse.successful == false) { if (initDialogResponse.successful == false) {
@ -551,8 +542,7 @@ open class FinTsJobExecutor(
protected open fun sendMessageAndHandleResponse(context: JobContext, segmentForNonStrongCustomerAuthenticationTwoStepTanProcess: CustomerSegmentId? = null, protected open fun sendMessageAndHandleResponse(context: JobContext, segmentForNonStrongCustomerAuthenticationTwoStepTanProcess: CustomerSegmentId? = null,
closeDialog: Boolean = true, createMessage: () -> MessageBuilderResult, callback: (BankResponse) -> Unit) { closeDialog: Boolean = true, createMessage: () -> MessageBuilderResult, callback: (BankResponse) -> Unit) {
val dialogContext = DialogContext(context.bank, product, closeDialog) context.startNewDialog(closeDialog)
context.startNewDialog(dialogContext)
if (segmentForNonStrongCustomerAuthenticationTwoStepTanProcess == null) { if (segmentForNonStrongCustomerAuthenticationTwoStepTanProcess == null) {
initDialogWithStrongCustomerAuthentication(context) { initDialogResponse -> initDialogWithStrongCustomerAuthentication(context) { initDialogResponse ->

View File

@ -1,24 +1,43 @@
package net.dankito.banking.fints.model package net.dankito.banking.fints.model
import net.dankito.banking.fints.callback.FinTsClientCallback import net.dankito.banking.fints.callback.FinTsClientCallback
import net.dankito.banking.fints.messages.datenelemente.implementierte.signatur.VersionDesSicherheitsverfahrens
import net.dankito.banking.fints.response.BankResponse
class JobContext( open class JobContext(
val type: JobContextType, open val type: JobContextType,
val callback: FinTsClientCallback, open val callback: FinTsClientCallback,
val bank: BankData, open val product: ProductData,
open val bank: BankData,
/** /**
* Only set if the current context is for a specific account (like get account's transactions). * Only set if the current context is for a specific account (like get account's transactions).
*/ */
val account: AccountData? = null open val account: AccountData? = null
) { ) {
lateinit var dialog: DialogContext protected open val _dialogs = mutableListOf<DialogContext>()
fun startNewDialog(dialog: DialogContext) { open var dialog: DialogContext = DialogContext(bank, product) // create null value so that variable is not null
this.dialog = dialog protected set
open val dialogs: List<DialogContext>
get() = ArrayList(_dialogs) // create a copy
fun startNewDialog(closeDialog: Boolean = true, dialogId: String = DialogContext.InitialDialogId,
versionOfSecurityMethod: VersionDesSicherheitsverfahrens = VersionDesSicherheitsverfahrens.Version_2,
chunkedResponseHandler: ((BankResponse) -> Unit)? = null) : DialogContext {
val newDialogContext = DialogContext(bank, product, closeDialog, dialogId = dialogId,
versionOfSecurityMethod = versionOfSecurityMethod, chunkedResponseHandler = chunkedResponseHandler)
this.dialog = newDialogContext
this._dialogs.add(newDialogContext)
return newDialogContext
} }
} }

View File

@ -63,10 +63,8 @@ abstract class FinTsTestBase {
protected open fun createContext(dialogId: String = DialogContext.InitialDialogId): JobContext { protected open fun createContext(dialogId: String = DialogContext.InitialDialogId): JobContext {
val dialogContext = DialogContext(Bank, Product, dialogId = dialogId) val context = JobContext(JobContextType.AnonymousBankInfo, SimpleFinTsClientCallback(), Product, Bank)
context.startNewDialog(dialogId = dialogId)
val context = JobContext(JobContextType.AnonymousBankInfo, SimpleFinTsClientCallback(), Bank)
context.startNewDialog(dialogContext)
return context return context
} }

View File

@ -127,9 +127,8 @@ class BanksFinTsDetailsRetriever {
private fun getAnonymousBankInfo(bank: BankData): BankResponse { private fun getAnonymousBankInfo(bank: BankData): BankResponse {
val dialogContext = DialogContext(bank, product) val context = JobContext(JobContextType.AnonymousBankInfo, SimpleFinTsClientCallback(), product, bank)
val context = JobContext(JobContextType.AnonymousBankInfo, SimpleFinTsClientCallback(), bank) context.startNewDialog()
context.startNewDialog(dialogContext)
val requestBody = messageBuilder.createAnonymousDialogInitMessage(context) val requestBody = messageBuilder.createAnonymousDialogInitMessage(context)