{ lateinit var walletRequestValues: Q lateinit var useCaseCallback: UseCaseCallback+ fun setRequestValues(requestValues: Q) { this.walletRequestValues = requestValues } diff --git a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseFactory.kt b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseFactory.kt index f37ef91a5..ea1eb6bb7 100644 --- a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseFactory.kt +++ b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseFactory.kt @@ -1,25 +1,33 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.base -import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.domain.usecase.account.FetchAccountTransfer import org.mifospay.core.data.domain.usecase.client.FetchClientDetails +import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.Constants import javax.inject.Inject -/** - * Created by ankur on 17/June/2018 - */ class UseCaseFactory @Inject constructor( - private val mFineractRepository: FineractRepository + private val mFineractRepository: FineractRepository, ) { fun getUseCase(useCase: String): UseCase<*, *>? { - return when(useCase) { + return when (useCase) { Constants.FETCH_ACCOUNT_TRANSFER_USECASE -> { FetchAccountTransfer(mFineractRepository) } + Constants.FETCH_CLIENT_DETAILS_USE_CASE -> { FetchClientDetails(mFineractRepository) } + else -> null } } diff --git a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseHandler.kt b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseHandler.kt index cc0159af2..9fe654b62 100644 --- a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseHandler.kt +++ b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseHandler.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.base import org.mifospay.core.data.base.UseCase.UseCaseCallback @@ -7,30 +16,32 @@ import org.mifospay.core.data.base.UseCase.UseCaseCallback */ class UseCaseHandler(private val mUseCaseScheduler: UseCaseScheduler) { fun
execute( - useCase: UseCase , values: T?, callback: UseCaseCallback + useCase: UseCase , + values: T?, + callback: UseCaseCallback , ) { - values?.let { useCase.walletRequestValues = values } + values?.let { useCase.walletRequestValues = values } useCase.useCaseCallback = UiCallbackWrapper(callback, this) mUseCaseScheduler.execute { useCase.run() } } fun notifyResponse( response: V, - useCaseCallback: UseCaseCallback ? + useCaseCallback: UseCaseCallback ?, ) { mUseCaseScheduler.notifyResponse(response, useCaseCallback) } private fun notifyError( message: String?, - useCaseCallback: UseCaseCallback ? + useCaseCallback: UseCaseCallback ?, ) { mUseCaseScheduler.onError(message, useCaseCallback) } private class UiCallbackWrapper ( private val mCallback: UseCaseCallback ?, - private val mUseCaseHandler: UseCaseHandler + private val mUseCaseHandler: UseCaseHandler, ) : UseCaseCallback { override fun onSuccess(response: V) { mUseCaseHandler.notifyResponse(response, mCallback) diff --git a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseScheduler.kt b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseScheduler.kt index cb388b8d1..bff30b7e4 100644 --- a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseScheduler.kt +++ b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseScheduler.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.base import org.mifospay.core.data.base.UseCase.UseCaseCallback @@ -8,10 +17,12 @@ import org.mifospay.core.data.base.UseCase.UseCaseCallback interface UseCaseScheduler { fun execute(runnable: Runnable?) fun notifyResponse( - response: V, useCaseCallback: UseCaseCallback ? + response: V, + useCaseCallback: UseCaseCallback ?, ) fun onError( - message: String?, useCaseCallback: UseCaseCallback ? + message: String?, + useCaseCallback: UseCaseCallback ?, ) } diff --git a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt index 681435f6e..2066f1faa 100644 --- a/core/data/src/main/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt +++ b/core/data/src/main/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt @@ -1,6 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.base import android.os.Handler +import android.os.Looper import org.mifospay.core.data.base.UseCase.UseCaseCallback import java.util.concurrent.ThreadPoolExecutor import java.util.concurrent.TimeUnit @@ -9,20 +19,19 @@ import java.util.concurrent.TimeUnit * Executes asynchronous tasks using a [ThreadPoolExecutor]. * * - * See also [Executors] for a list of factory methods to create common + * See also [ThreadPoolExecutor] for a list of factory methods to create common * [java.util.concurrent.ExecutorService]s for different scenarios. */ class UseCaseThreadPoolScheduler : UseCaseScheduler { - private val mHandler = Handler() - var mThreadPoolExecutor: ThreadPoolExecutor - - init { - mThreadPoolExecutor = ThreadPoolExecutor( - POOL_SIZE, MAX_POOL_SIZE, TIMEOUT.toLong(), - TimeUnit.SECONDS, ThreadPoolQueue(MAX_POOL_SIZE) - ) - } + private val mHandler = Handler(Looper.getMainLooper()) + private var mThreadPoolExecutor: ThreadPoolExecutor = ThreadPoolExecutor( + POOL_SIZE, + MAX_POOL_SIZE, + TIMEOUT.toLong(), + TimeUnit.SECONDS, + ThreadPoolQueue(MAX_POOL_SIZE), + ) override fun execute(runnable: Runnable?) { mThreadPoolExecutor.execute(runnable) @@ -30,14 +39,14 @@ class UseCaseThreadPoolScheduler : UseCaseScheduler { override fun notifyResponse( response: V, - useCaseCallback: UseCaseCallback ? + useCaseCallback: UseCaseCallback ?, ) { mHandler.post { useCaseCallback!!.onSuccess(response) } } override fun onError( message: String?, - useCaseCallback: UseCaseCallback ? + useCaseCallback: UseCaseCallback ?, ) { mHandler.post { useCaseCallback!!.onError(message!!) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/di/DataModule.kt b/core/data/src/main/java/org/mifospay/core/data/di/DataModule.kt index 604bb014e..53faaa865 100644 --- a/core/data/src/main/java/org/mifospay/core/data/di/DataModule.kt +++ b/core/data/src/main/java/org/mifospay/core/data/di/DataModule.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.di import dagger.Module @@ -26,7 +35,7 @@ class DataModule { @Provides fun providesFineractRepository( fineractApiManager: FineractApiManager, - selfServiceApiManager: SelfServiceApiManager + selfServiceApiManager: SelfServiceApiManager, ): FineractRepository { return FineractRepository(fineractApiManager, selfServiceApiManager) } diff --git a/core/data/src/main/java/org/mifospay/core/data/di/LocalDataModule.kt b/core/data/src/main/java/org/mifospay/core/data/di/LocalDataModule.kt index 972ec7529..9b477903d 100644 --- a/core/data/src/main/java/org/mifospay/core/data/di/LocalDataModule.kt +++ b/core/data/src/main/java/org/mifospay/core/data/di/LocalDataModule.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.di import dagger.Binds diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt index fab98a4a9..85951cd10 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import org.mifospay.core.data.base.UseCase @@ -8,27 +17,28 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 29/June/2018 - */ -class BlockUnblockCommand @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { - protected override fun executeUseCase(requestValues: RequestValues) { +class BlockUnblockCommand @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { + + override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.blockUnblockAccount(requestValues.accountId, requestValues.command) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError( - "Error " + requestValues.command + "ing account" - ) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError( + "Error " + requestValues.command + "ing account", + ) + } - override fun onNext(genericResponse: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue) - } - }) + override fun onNext(genericResponse: GenericResponse) { + useCaseCallback.onSuccess(ResponseValue) + } + }, + ) } data class RequestValues(val accountId: Long, val command: String) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt index fad50a0d6..f6bc1058f 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import okhttp3.ResponseBody @@ -9,30 +18,29 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 06/June/2018 - */ -class DownloadTransactionReceipt @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { - override fun executeUseCase(requestValues: RequestValues) { - requestValues.transactionId?.let { - mFineractRepository.getTransactionReceipt(Constants.PDF, it) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } +class DownloadTransactionReceipt @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { + override fun executeUseCase(requestValues: RequestValues) { + requestValues.transactionId?.let { + mFineractRepository.getTransactionReceipt(Constants.PDF, it) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } - override fun onNext(t: ResponseBody) { - val responseBody = t - useCaseCallback.onSuccess(ResponseValue(responseBody)) - } - }) - } + override fun onNext(t: ResponseBody) { + useCaseCallback.onSuccess(ResponseValue(t)) + } + }, + ) + } } - data class RequestValues( val transactionId: String?) : UseCase.RequestValues + data class RequestValues(val transactionId: String?) : UseCase.RequestValues data class ResponseValue(val responseBody: ResponseBody) : UseCase.ResponseValue } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt index 7c65629d6..314e4deff 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt @@ -1,58 +1,67 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account - +import com.mifospay.core.model.domain.Account +import com.mifospay.core.model.entity.client.ClientAccounts import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.entity.mapper.AccountMapper import org.mifospay.core.data.fineract.repository.FineractRepository -import com.mifospay.core.model.domain.Account -import com.mifospay.core.model.entity.client.ClientAccounts import org.mifospay.core.data.util.Constants import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers - import javax.inject.Inject -class FetchAccount @Inject constructor(private val fineractRepository: FineractRepository) : - UseCase () { - - @Inject - lateinit var accountMapper: AccountMapper +class FetchAccount @Inject constructor( + private val fineractRepository: FineractRepository, + private val accountMapper: AccountMapper, +) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { fineractRepository.getSelfAccounts(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = accountMapper.transform(clientAccounts) - if (!accounts.isNullOrEmpty()) { - var walletAccount: Account? = null - for (account in accounts) { - if (account.productId.toInt() == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) + } + + override fun onNext(clientAccounts: ClientAccounts) { + val accounts = accountMapper.transform(clientAccounts) + + if (accounts.isNotEmpty()) { + var walletAccount: Account? = null + for (account in accounts) { + if (account.productId.toInt() == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { + walletAccount = account + break + } + } + if (walletAccount != null) { + useCaseCallback.onSuccess(ResponseValue(walletAccount)) + } else { + useCaseCallback.onError(Constants.NO_ACCOUNT_FOUND) } - } - if (walletAccount != null) { - useCaseCallback.onSuccess(ResponseValue(walletAccount)) } else { - useCaseCallback.onError(Constants.NO_ACCOUNT_FOUND) + useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) } - } else { - useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) } - } - }) + }, + ) } - data class RequestValues(val clientId: Long) : UseCase.RequestValues + data class RequestValues(val clientId: Long) : UseCase.RequestValues data class ResponseValue(val account: Account) : UseCase.ResponseValue } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt index b84c25a4e..196604e4e 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import com.mifospay.core.model.domain.Transaction @@ -11,49 +20,44 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by Shivansh on 15/6/19. - */ class FetchAccountTransaction @Inject constructor( - val fineractRepository: FineractRepository, - val transactionMapper: TransactionMapper + private val fineractRepository: FineractRepository, + private val transactionMapper: TransactionMapper, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { fineractRepository.getSelfAccountTransactionFromId( requestValues.accountId, - requestValues.transactionId + requestValues.transactionId, ) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Observer { - override fun onCompleted() {} - override fun onError(e: Throwable) { - if (e.message == "HTTP 401 Unauthorized") { - useCaseCallback.onError(Constants.UNAUTHORIZED_ERROR) - } else { - useCaseCallback.onError( - Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS - ) + .subscribe( + object : Observer { + override fun onCompleted() {} + override fun onError(e: Throwable) { + if (e.message == "HTTP 401 Unauthorized") { + useCaseCallback.onError(Constants.UNAUTHORIZED_ERROR) + } else { + useCaseCallback.onError( + Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS, + ) + } } - } - override fun onNext(transaction: Transactions?) { - useCaseCallback.onSuccess( - ResponseValue( - transactionMapper - .transformInvoice(transaction) + override fun onNext(transaction: Transactions?) { + useCaseCallback.onSuccess( + ResponseValue(transactionMapper.transformInvoice(transaction)), ) - ) - } - }) + } + }, + ) } data class RequestValues( val accountId: Long, - val transactionId: Long + val transactionId: Long, ) : UseCase.RequestValues - data class ResponseValue(val transaction: Transaction) : UseCase.ResponseValue } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt index 53a7a7507..5a2a5c318 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import com.mifospay.core.model.domain.Transaction @@ -11,34 +20,33 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 11/7/17. - */ class FetchAccountTransactions @Inject constructor( private val fineractRepository: FineractRepository, - private val transactionMapper: TransactionMapper + private val transactionMapper: TransactionMapper, ) : UseCase () { - protected override fun executeUseCase(requestValues: RequestValues) { + override fun executeUseCase(requestValues: RequestValues) { fineractRepository.getSelfAccountTransactions(requestValues.accountId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError( - Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS - ) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError( + Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS, + ) + } - override fun onNext(transactions: SavingsWithAssociations) { - useCaseCallback.onSuccess( - ResponseValue( - transactionMapper.transformTransactionList(transactions) + override fun onNext(transactions: SavingsWithAssociations) { + useCaseCallback.onSuccess( + ResponseValue( + transactionMapper.transformTransactionList(transactions), + ), ) - ) - } - }) + } + }, + ) } data class RequestValues(var accountId: Long) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt index dcb413760..05890a5b3 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import com.mifospay.core.model.entity.accounts.savings.TransferDetail @@ -8,11 +17,8 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 05/June/2018 - */ class FetchAccountTransfer @Inject constructor( - private val mFineractRepository: FineractRepository + private val mFineractRepository: FineractRepository, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.getAccountTransfer(requestValues.transferId) diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt index 9e29c8ace..60895b71d 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import com.mifospay.core.model.domain.Account @@ -11,37 +20,35 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 11/7/17. - */ class FetchAccounts @Inject constructor( private val fineractRepository: FineractRepository, - val accountMapper: AccountMapper) : - UseCase () { - + private val accountMapper: AccountMapper, +) : UseCase () { + override fun executeUseCase(requestValues: RequestValues) { fineractRepository.getAccounts(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) + } - override fun onNext(t: ClientAccounts?) { - val accounts = t - if (accounts != null) { - useCaseCallback.onSuccess( - ResponseValue( - accountMapper!!.transform(accounts) + override fun onNext(t: ClientAccounts?) { + if (t != null) { + useCaseCallback.onSuccess( + ResponseValue( + accountMapper.transform(t), + ), ) - ) - } else { - useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) + } else { + useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) + } } - } - }) + }, + ) } data class RequestValues(val clientId: Long) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt index ae00bc663..a1da35556 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import com.mifospay.core.model.entity.Page @@ -11,35 +20,37 @@ import rx.schedulers.Schedulers import javax.inject.Inject class FetchMerchants @Inject constructor( - private val mFineractRepository: FineractRepository + private val mFineractRepository: FineractRepository, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.savingsAccounts .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + e.message?.let { useCaseCallback.onError(it) } + } - override fun onNext(savingsWithAssociationsPage: Page ) { - val savingsWithAssociationsList = savingsWithAssociationsPage.pageItems - val merchantsList: MutableList = ArrayList() - for (i in savingsWithAssociationsList.indices) { - if (savingsWithAssociationsList[i].savingsProductId == - Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID - ) { - merchantsList.add(savingsWithAssociationsList[i]) + override fun onNext(savingsWithAssociationsPage: Page ) { + val savingsWithAssociationsList = savingsWithAssociationsPage.pageItems + val merchantsList: MutableList = ArrayList() + for (i in savingsWithAssociationsList.indices) { + if (savingsWithAssociationsList[i].savingsProductId == + Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID + ) { + merchantsList.add(savingsWithAssociationsList[i]) + } } + useCaseCallback.onSuccess(ResponseValue(merchantsList)) } - useCaseCallback.onSuccess(ResponseValue(merchantsList)) - } - }) + }, + ) } class RequestValues : UseCase.RequestValues data class ResponseValue( - val savingsWithAssociationsList: List + val savingsWithAssociationsList: List , ) : UseCase.ResponseValue } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/PayFunds.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/PayFunds.kt deleted file mode 100644 index 0b1fe53b0..000000000 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/PayFunds.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.mifospay.core.data.domain.usecase.account - -class PayFunds \ No newline at end of file diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt index b8b38c903..fdb32c9b2 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.account import com.mifospay.core.model.entity.TPTResponse @@ -19,10 +28,11 @@ import rx.schedulers.Schedulers import javax.inject.Inject @Suppress("UnusedPrivateMember") -class TransferFunds @Inject constructor( private val apiRepository: FineractRepository) : - UseCase () { +class TransferFunds @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { - // override var requestValues: RequestValues + // override var requestValues: RequestValues private lateinit var fromClient: Client private lateinit var toClient: Client private lateinit var fromAccount: SavingAccount @@ -33,135 +43,145 @@ class TransferFunds @Inject constructor( private val apiRepository: FineractRepo apiRepository.getSelfClientDetails(requestValues.fromClientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - fromClient = client - fetchToClientDetails() - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) + } + + override fun onNext(client: Client) { + fromClient = client + fetchToClientDetails() + } + }, + ) } private fun fetchToClientDetails() { apiRepository.getClientDetails(walletRequestValues.toClientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - toClient = client - fetchFromAccountDetails() - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) + } + + override fun onNext(client: Client) { + toClient = client + fetchFromAccountDetails() + } + }, + ) } private fun fetchFromAccountDetails() { apiRepository.getSelfAccounts(walletRequestValues.fromClientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = clientAccounts.savingsAccounts - if (accounts != null && accounts.isNotEmpty()) { - var walletAccount: SavingAccount? = null - for (account in accounts) { - if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) + } + + override fun onNext(clientAccounts: ClientAccounts) { + val accounts = clientAccounts.savingsAccounts + if (accounts.isNotEmpty()) { + var walletAccount: SavingAccount? = null + for (account in accounts) { + if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { + walletAccount = account + break + } + } + if (walletAccount != null) { + fromAccount = walletAccount + fetchToAccountDetails() + } else { + useCaseCallback.onError(Constants.NO_WALLET_FOUND) } - } - if (walletAccount != null) { - fromAccount = walletAccount - fetchToAccountDetails() } else { - useCaseCallback.onError(Constants.NO_WALLET_FOUND) + useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) } - } else { - useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) } - } - }) + }, + ) } private fun fetchToAccountDetails() { apiRepository.getAccounts(walletRequestValues.toClientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = clientAccounts.savingsAccounts - if (!accounts.isNullOrEmpty()) { - var walletAccount: SavingAccount? = null - for (account in accounts) { - if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) + } + + override fun onNext(clientAccounts: ClientAccounts) { + val accounts = clientAccounts.savingsAccounts + if (accounts.isNotEmpty()) { + var walletAccount: SavingAccount? = null + for (account in accounts) { + if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { + walletAccount = account + break + } + } + if (walletAccount != null) { + toAccount = walletAccount + makeTransfer() + } else { + useCaseCallback.onError(Constants.NO_WALLET_FOUND) } - } - if (walletAccount != null) { - toAccount = walletAccount - makeTransfer() } else { - useCaseCallback.onError(Constants.NO_WALLET_FOUND) + useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) } - } else { - useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) } - } - }) + }, + ) } private fun checkBeneficiary() { apiRepository.beneficiaryList .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_BENEFICIARIES) - } - - override fun onNext(beneficiaries: List
) { - var exists = false - beneficiaries.forEach { beneficiary -> - if (beneficiary.accountNumber == toAccount.accountNo) { - exists = true - if (beneficiary.transferLimit >= walletRequestValues.amount) { - makeTransfer() - } else { - updateTransferLimit(beneficiary.id?.toLong()!!) + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_BENEFICIARIES) + } + + override fun onNext(beneficiaries: List
) { + var exists = false + beneficiaries.forEach { beneficiary -> + if (beneficiary.accountNumber == toAccount.accountNo) { + exists = true + if (beneficiary.transferLimit >= walletRequestValues.amount) { + makeTransfer() + } else { + updateTransferLimit(beneficiary.id?.toLong()!!) + } + return@forEach } - return@forEach + } + if (!exists) { + addBeneficiary() } } - if (!exists) { - addBeneficiary() - } - } - }) + }, + ) } private fun addBeneficiary() { @@ -176,17 +196,19 @@ class TransferFunds @Inject constructor( private val apiRepository: FineractRepo apiRepository.createBeneficiary(payload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} + .subscribe( + object : Subscriber () { + override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_ADDING_BENEFICIARY) - } + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_ADDING_BENEFICIARY) + } - override fun onNext(responseBody: ResponseBody) { - makeTransfer() - } - }) + override fun onNext(responseBody: ResponseBody) { + makeTransfer() + } + }, + ) } private fun updateTransferLimit(beneficiaryId: Long) { @@ -196,17 +218,19 @@ class TransferFunds @Inject constructor( private val apiRepository: FineractRepo apiRepository.updateBeneficiary(beneficiaryId, updatePayload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} + .subscribe( + object : Subscriber () { + override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_ADDING_BENEFICIARY) - } + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_ADDING_BENEFICIARY) + } - override fun onNext(responseBody: ResponseBody) { - makeTransfer() - } - }) + override fun onNext(responseBody: ResponseBody) { + makeTransfer() + } + }, + ) } private fun makeTransfer() { @@ -227,23 +251,25 @@ class TransferFunds @Inject constructor( private val apiRepository: FineractRepo apiRepository.makeThirdPartyTransfer(transferPayload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} + .subscribe( + object : Subscriber () { + override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_MAKING_TRANSFER) - } + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_MAKING_TRANSFER) + } - override fun onNext(responseBody: TPTResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + override fun onNext(responseBody: TPTResponse) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } data class RequestValues( val fromClientId: Long, val toClientId: Long, - val amount: Double + val amount: Double, ) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt index 234e1bc11..64246586f 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt @@ -1,5 +1,15 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.client +import com.mifospay.core.model.domain.client.NewClient import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.ErrorJsonMessageHelper.getUserMessage @@ -9,35 +19,37 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 20/8/17. - */ -class CreateClient @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { +class CreateClient @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { + + data class RequestValues(val client: NewClient) : UseCase.RequestValues - data class RequestValues(val client: com.mifospay.core.model.domain.client.NewClient) : UseCase.RequestValues data class ResponseValue(val clientId: Int) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { apiRepository.createClient(requestValues.client) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - var message: String - try { - message = (e as HttpException).response()?.errorBody()?.string().toString() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + var message: String + try { + message = + (e as HttpException).response()?.errorBody()?.string().toString() + message = getUserMessage(message) + } catch (e1: Exception) { + message = e1.message.toString() + } + useCaseCallback.onError(message) } - useCaseCallback.onError(message) - } - override fun onNext(genericResponse: ResponseValue) { - useCaseCallback.onSuccess(genericResponse) - } - }) + override fun onNext(genericResponse: ResponseValue) { + useCaseCallback.onSuccess(genericResponse) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt index d13fef6df..2d74601ce 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt @@ -1,8 +1,17 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.client -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.Page import com.mifospay.core.model.entity.client.Client +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.entity.mapper.ClientDetailsMapper import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.Constants @@ -11,8 +20,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -class FetchClientData @Inject constructor(private val fineractRepository: FineractRepository) : - UseCase () { +class FetchClientData @Inject constructor( + private val fineractRepository: FineractRepository, +) : UseCase () { @Inject lateinit var clientDetailsMapper: ClientDetailsMapper @@ -22,43 +32,47 @@ class FetchClientData @Inject constructor(private val fineractRepository: Finera fineractRepository.getSelfClientDetails(clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) + } - override fun onNext(client: Client) { - useCaseCallback.onSuccess( - ResponseValue(clientDetailsMapper.transform(client)) - ) - } - }) + override fun onNext(client: Client) { + useCaseCallback.onSuccess( + ResponseValue(clientDetailsMapper.transform(client)), + ) + } + }, + ) } ?: run { fineractRepository.selfClientDetails .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) + } - override fun onNext(client: Page ) { - if (client.pageItems.size != 0) { - useCaseCallback.onSuccess( - ResponseValue(clientDetailsMapper.transform(client.pageItems[0])) - ) - } else { - useCaseCallback.onError(Constants.NO_CLIENT_FOUND) + override fun onNext(client: Page ) { + if (client.pageItems.size != 0) { + useCaseCallback.onSuccess( + ResponseValue(clientDetailsMapper.transform(client.pageItems[0])), + ) + } else { + useCaseCallback.onError(Constants.NO_CLIENT_FOUND) + } } - } - }) + }, + ) } } data class RequestValues(val clientId: Long?) : UseCase.RequestValues data class ResponseValue( - val clientDetails: com.mifospay.core.model.domain.client.Client + val clientDetails: com.mifospay.core.model.domain.client.Client, ) : UseCase.ResponseValue } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt index 98c528aa7..7728aeee4 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt @@ -1,7 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.client -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.client.Client +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.Constants import rx.Subscriber @@ -9,11 +18,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 24/July/2018 - */ -class FetchClientDetails @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchClientDetails @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { data class RequestValues(val clientId: Long) : UseCase.RequestValues data class ResponseValue(val client: Client) : UseCase.ResponseValue @@ -22,15 +29,17 @@ class FetchClientDetails @Inject constructor(private val mFineractRepository: Fi mFineractRepository.getClientDetails(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) + } - override fun onNext(client: Client) { - useCaseCallback.onSuccess(ResponseValue(client)) - } - }) + override fun onNext(client: Client) { + useCaseCallback.onSuccess(ResponseValue(client)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt index f8f4f8e00..db51bf3fe 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.client import okhttp3.ResponseBody @@ -9,25 +18,29 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -class FetchClientImage @Inject constructor(private val mFineractRepository: FineractRepository) : +class FetchClientImage @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { - data class RequestValues(val clientid: Long) : UseCase.RequestValues + data class RequestValues(val clientId: Long) : UseCase.RequestValues data class ResponseValue(val responseBody: ResponseBody) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.getClientImage(requestValues.clientid) + mFineractRepository.getClientImage(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - getUserMessage(e)?.let { useCaseCallback.onError(it) } - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + getUserMessage(e)?.let { useCaseCallback.onError(it) } + } - override fun onNext(responseBody: ResponseBody) { - useCaseCallback.onSuccess(ResponseValue(responseBody)) - } - }) + override fun onNext(responseBody: ResponseBody) { + useCaseCallback.onSuccess(ResponseValue(responseBody)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt index a986a010c..4cf55ef81 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt @@ -1,21 +1,28 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.client -import org.mifospay.core.data.base.UseCase +import com.mifospay.core.model.domain.SearchResult import com.mifospay.core.model.entity.SearchedEntity +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.entity.mapper.SearchedEntitiesMapper import org.mifospay.core.data.fineract.repository.FineractRepository -import com.mifospay.core.model.domain.SearchResult import org.mifospay.core.data.util.Constants import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 19/8/17. - */ -class SearchClient @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { +class SearchClient @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { @Inject lateinit var searchedEntitiesMapper: SearchedEntitiesMapper @@ -27,23 +34,25 @@ class SearchClient @Inject constructor(private val apiRepository: FineractReposi apiRepository.searchResources(requestValues.externalId, Constants.CLIENTS, false) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_SEARCHING_CLIENTS) - } + .subscribe( + object : Subscriber
>() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_SEARCHING_CLIENTS) + } - override fun onNext(results: List
) { - if (results.isNotEmpty()) { - useCaseCallback.onSuccess( - ResponseValue( - searchedEntitiesMapper.transformList(results) + override fun onNext(results: List ) { + if (results.isNotEmpty()) { + useCaseCallback.onSuccess( + ResponseValue( + searchedEntitiesMapper.transformList(results), + ), ) - ) - } else { - useCaseCallback.onError(Constants.NO_CLIENTS_FOUND) + } else { + useCaseCallback.onError(Constants.NO_CLIENTS_FOUND) + } } - } - }) + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt index 2a6ffe270..c6d533071 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.client import okhttp3.ResponseBody @@ -10,11 +19,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 19/8/17. - */ -class UpdateClient @Inject constructor(private val fineractRepository: FineractRepository) : - UseCase () { +class UpdateClient @Inject constructor( + private val fineractRepository: FineractRepository, +) : UseCase () { data class RequestValues(val updateClientEntity: Any, val clientId: Long) : UseCase.RequestValues @@ -25,22 +32,25 @@ class UpdateClient @Inject constructor(private val fineractRepository: FineractR fineractRepository.updateClient(requestValues.clientId, requestValues.updateClientEntity) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - var message: String - try { - message = (e as HttpException).response()?.errorBody()?.string().toString() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + var message: String + try { + message = + (e as HttpException).response()?.errorBody()?.string().toString() + message = getUserMessage(message) + } catch (e1: Exception) { + message = e1.message.toString() + } + useCaseCallback.onError(message) } - useCaseCallback.onError(message) - } - override fun onNext(responseBody: ResponseBody) { - useCaseCallback.onSuccess(ResponseValue(responseBody)) - } - }) + override fun onNext(responseBody: ResponseBody) { + useCaseCallback.onSuccess(ResponseValue(responseBody)) + } + }, + ) } -} \ No newline at end of file +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt index 3ed07e2f7..bfdcfb24e 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.invoice import android.net.Uri @@ -11,21 +20,17 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 07/June/2018 - */ -class FetchInvoice @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchInvoice @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val uniquePaymentLink: Uri?) : UseCase.RequestValues class ResponseValue( - val invoices: List + val invoices: List , ) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { val paymentLink = requestValues.uniquePaymentLink - val scheme = paymentLink?.scheme // "https" - val host = paymentLink?.host // "invoice.mifospay.com" try { val params = paymentLink?.pathSegments val clientId = params?.get(0) // "clientId" @@ -34,21 +39,22 @@ class FetchInvoice @Inject constructor(private val mFineractRepository: Fineract mFineractRepository.fetchInvoice(clientId, invoiceId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber ?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.INVALID_UPL) - } - - override fun onNext(invoices: List
?) { - if (invoices?.isNotEmpty() == true) { - useCaseCallback.onSuccess(ResponseValue(invoices)) - } else { - useCaseCallback.onError(Constants.INVOICE_DOES_NOT_EXIST) + .subscribe( + object : Subscriber ?>() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.INVALID_UPL) } - } - }) + override fun onNext(invoices: List
?) { + if (invoices?.isNotEmpty() == true) { + useCaseCallback.onSuccess(ResponseValue(invoices)) + } else { + useCaseCallback.onError(Constants.INVOICE_DOES_NOT_EXIST) + } + } + }, + ) } } catch (e: IndexOutOfBoundsException) { Log.e("Error", e.message.toString()) diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt index e6fe0500e..50caac4f2 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt @@ -1,40 +1,49 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.invoice import android.util.Log -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.Invoice +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 11/June/2018 - */ -class FetchInvoices @Inject constructor(private val mFineractRepository: FineractRepository) : +class FetchInvoices @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: String) : UseCase.RequestValues class ResponseValue( - val invoiceList: List + val invoiceList: List , ) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.fetchInvoices(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - Log.e("Invoices", e.message.toString()) - useCaseCallback.onError(e.toString()) - } - - override fun onNext(invoices: List
) { - useCaseCallback.onSuccess(ResponseValue(invoices)) - } - }) + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + Log.e("Invoices", e.message.toString()) + useCaseCallback.onError(e.toString()) + } + override fun onNext(invoices: List
) { + useCaseCallback.onSuccess(ResponseValue(invoices)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt index f36b6c20c..2cf235a3d 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt @@ -1,40 +1,48 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.kyc -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.kyc.KYCLevel1Details +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 24/May/2018 - */ -class FetchKYCLevel1Details @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchKYCLevel1Details @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: Int) : UseCase.RequestValues class ResponseValue( - val kycLevel1DetailsList: List + val kycLevel1DetailsList: List , ) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.fetchKYCLevel1Details(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(kycLevel1Details: List
) { - useCaseCallback.onSuccess( - ResponseValue(kycLevel1Details) - ) - } - }) + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(kycLevel1Details: List
) { + useCaseCallback.onSuccess( + ResponseValue(kycLevel1Details), + ) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt index d4d178d8f..90b1c0d4a 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt @@ -1,7 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.kyc -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.kyc.KYCLevel1Details +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.network.GenericResponse import rx.Subscriber @@ -9,15 +18,13 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 25/May/2018 - */ -class UpdateKYCLevel1Details @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class UpdateKYCLevel1Details @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues( val clientId: Int, - val kycLevel1Details: KYCLevel1Details + val kycLevel1Details: KYCLevel1Details, ) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue @@ -25,21 +32,21 @@ class UpdateKYCLevel1Details @Inject constructor(private val mFineractRepository override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.updateKYCLevel1Details( requestValues.clientId, - requestValues.kycLevel1Details + requestValues.kycLevel1Details, ) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - - }) - + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + + override fun onNext(t: GenericResponse) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt index f4238e713..c62971778 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.kyc import okhttp3.MultipartBody @@ -9,36 +18,41 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 16/May/2018 - */ -class UploadKYCDocs @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { +class UploadKYCDocs @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { class RequestValues( - val entitytype: String, val clientId: Long, val docname: String, - val identityType: String, val file: MultipartBody.Part + val entityType: String, + val clientId: Long, + val docname: String, + val identityType: String, + val file: MultipartBody.Part, ) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { apiRepository.uploadKYCDocs( - requestValues.entitytype, requestValues.clientId, - requestValues.docname, requestValues.identityType, requestValues.file + requestValues.entityType, + requestValues.clientId, + requestValues.docname, + requestValues.identityType, + requestValues.file, ) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(t: GenericResponse) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt index 93a92ddcc..cf8627e6b 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt @@ -1,7 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.kyc -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.kyc.KYCLevel1Details +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.network.GenericResponse import rx.Subscriber @@ -9,14 +18,12 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 24/May/2018 - */ -class UploadKYCLevel1Details @Inject constructor(var mFineractRepository: FineractRepository) : - UseCase () { +class UploadKYCLevel1Details @Inject constructor( + var mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues( val clientId: Int, - val mKYCLevel1Details: KYCLevel1Details + val mKYCLevel1Details: KYCLevel1Details, ) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue @@ -24,20 +31,21 @@ class UploadKYCLevel1Details @Inject constructor(var mFineractRepository: Finera override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.uploadKYCLevel1Details( requestValues.clientId, - requestValues.mKYCLevel1Details + requestValues.mKYCLevel1Details, ) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(t: GenericResponse) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt index ea37ac6e4..7aef23b3b 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt @@ -1,40 +1,47 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.notification +import com.mifospay.core.model.domain.NotificationPayload import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository -import com.mifospay.core.model.domain.NotificationPayload import org.mifospay.core.data.util.Constants import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 24/July/2018 - */ -class FetchNotifications @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchNotifications @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: Long) : UseCase.RequestValues class ResponseValue( - val notificationPayloadList: List ? + val notificationPayloadList: List ?, ) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.fetchNotifications(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_NOTIFICATIONS) - } - - override fun onNext(notificationPayloads: List
) { - useCaseCallback.onSuccess(ResponseValue(notificationPayloads)) - } - }) + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_FETCHING_NOTIFICATIONS) + } + override fun onNext(notificationPayloads: List
) { + useCaseCallback.onSuccess(ResponseValue(notificationPayloads)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt index ac6f93363..85b01ae6e 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt @@ -1,7 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.savedcards -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.savedcards.Card +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.network.GenericResponse import rx.Subscriber @@ -9,11 +18,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 21/May/2018 - */ -class AddCard @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class AddCard @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: Long, val card: Card) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue @@ -21,16 +28,17 @@ class AddCard @Inject constructor(private val mFineractRepository: FineractRepos mFineractRepository.addSavedCards(requestValues.clientId, requestValues.card) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(t: GenericResponse?) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } -} \ No newline at end of file +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt index b4161120b..d143d1ea4 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.savedcards import org.mifospay.core.data.base.UseCase @@ -8,11 +17,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 22/May/2018 - */ -class DeleteCard @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class DeleteCard @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: Int, val cardId: Int) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue @@ -21,16 +28,17 @@ class DeleteCard @Inject constructor(private val mFineractRepository: FineractRe mFineractRepository.deleteSavedCard(requestValues.clientId, requestValues.cardId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(t: GenericResponse?) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt index f96a1db3a..b27627897 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt @@ -1,7 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.savedcards -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.savedcards.Card +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.network.GenericResponse import rx.Subscriber @@ -9,11 +18,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 22/May/2018 - */ -class EditCard @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class EditCard @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: Int, val card: Card) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue @@ -22,16 +29,17 @@ class EditCard @Inject constructor(private val mFineractRepository: FineractRepo mFineractRepository.editSavedCard(requestValues.clientId, requestValues.card) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(t: GenericResponse?) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt index 994351885..6400ae78d 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt @@ -1,7 +1,16 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.savedcards -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.savedcards.Card +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.Constants import rx.Subscriber @@ -9,11 +18,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 21/May/2018 - */ -class FetchSavedCards @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchSavedCards @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val clientId: Long) : UseCase.RequestValues class ResponseValue(val cardList: List ) : UseCase.ResponseValue @@ -22,20 +29,21 @@ class FetchSavedCards @Inject constructor(private val mFineractRepository: Finer mFineractRepository.fetchSavedCards(requestValues.clientId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(cards: List
) { - if (cards.isNotEmpty()) { - useCaseCallback.onSuccess(ResponseValue(cards)) - } else { - useCaseCallback.onError(Constants.NO_SAVED_CARDS) + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) } - } - }) + override fun onNext(cards: List
) { + if (cards.isNotEmpty()) { + useCaseCallback.onSuccess(ResponseValue(cards)) + } else { + useCaseCallback.onError(Constants.NO_SAVED_CARDS) + } + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt index 5a11f2612..690651c9a 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt @@ -1,11 +1,20 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.standinginstruction -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.accounts.savings.SavingAccount import com.mifospay.core.model.entity.client.Client import com.mifospay.core.model.entity.client.ClientAccounts -import com.mifospay.core.model.entity.standinginstruction.SDIResponse import com.mifospay.core.model.entity.payload.StandingInstructionPayload +import com.mifospay.core.model.entity.standinginstruction.SDIResponse +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.Constants import rx.Subscriber @@ -13,9 +22,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject - -class CreateStandingTransaction @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { +class CreateStandingTransaction @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { lateinit var fromClient: Client lateinit var toClient: Client @@ -24,12 +33,12 @@ class CreateStandingTransaction @Inject constructor(private val apiRepository: F override fun executeUseCase(requestValues: RequestValues) { apiRepository.getSelfClientDetails(requestValues.fromClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { @@ -40,17 +49,18 @@ class CreateStandingTransaction @Inject constructor(private val apiRepository: F fromClient = client fetchToClientData() } - }) + }, + ) } private fun fetchToClientData() { apiRepository.getClientDetails(walletRequestValues.toClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { @@ -61,16 +71,17 @@ class CreateStandingTransaction @Inject constructor(private val apiRepository: F toClient = client fetchFromAccountDetails() } - }) + }, + ) } private fun fetchFromAccountDetails() { apiRepository.getSelfAccounts(walletRequestValues.fromClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { @@ -79,32 +90,34 @@ class CreateStandingTransaction @Inject constructor(private val apiRepository: F override fun onNext(clientAccounts: ClientAccounts) { val accounts = clientAccounts.savingsAccounts - if (accounts != null && accounts.size != 0) { + if (accounts.isNotEmpty()) { var walletAccount: SavingAccount? = null for (account in accounts) { if (account.productId == - Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { + Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID + ) { walletAccount = account break } } - walletAccount?.let{ + walletAccount?.let { fromAccount = walletAccount fetchToAccountDetails() - }?: useCaseCallback.onError(Constants.NO_WALLET_FOUND) - + } ?: useCaseCallback.onError(Constants.NO_WALLET_FOUND) } else { useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) } } - }) + }, + ) } private fun fetchToAccountDetails() { apiRepository.getAccounts(walletRequestValues.toClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { override fun onCompleted() {} override fun onError(e: Throwable) { useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) @@ -112,60 +125,61 @@ class CreateStandingTransaction @Inject constructor(private val apiRepository: F override fun onNext(clientAccounts: ClientAccounts) { val accounts = clientAccounts.savingsAccounts - if (accounts != null && accounts.size != 0) { + if (accounts.isNotEmpty()) { var walletAccount: SavingAccount? = null for (account in accounts) { if (account.productId == - Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { + Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID + ) { walletAccount = account break } } - walletAccount?.let{ + walletAccount?.let { toAccount = walletAccount createNewStandingInstruction() - }?: useCaseCallback.onError(Constants.NO_WALLET_FOUND) - + } ?: useCaseCallback.onError(Constants.NO_WALLET_FOUND) } else { useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) } } - }) + }, + ) } private fun createNewStandingInstruction() { - val standingInstructionPayload = StandingInstructionPayload( - fromClient.officeId, - fromClient.id, - 2, - "wallet standing transaction", - 1, - 2, - 1, - fromAccount.id, - toClient.officeId, - toClient.id, - 2, - toAccount.id, - 1, - walletRequestValues.amount, - walletRequestValues.validFrom, - 1, - walletRequestValues.recurrenceInterval, - 2, - "en", - "dd MM yyyy", - walletRequestValues.validTill, - walletRequestValues.recurrenceOnDayMonth, - "dd MM") + fromClient.officeId, + fromClient.id, + 2, + "wallet standing transaction", + 1, + 2, + 1, + fromAccount.id, + toClient.officeId, + toClient.id, + 2, + toAccount.id, + 1, + walletRequestValues.amount, + walletRequestValues.validFrom, + 1, + walletRequestValues.recurrenceInterval, + 2, + "en", + "dd MM yyyy", + walletRequestValues.validTill, + walletRequestValues.recurrenceOnDayMonth, + "dd MM", + ) apiRepository.createStandingInstruction(standingInstructionPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { @@ -175,17 +189,19 @@ class CreateStandingTransaction @Inject constructor(private val apiRepository: F override fun onNext(sdiResponse: SDIResponse) { useCaseCallback.onSuccess(ResponseValue()) } - }) + }, + ) } - class RequestValues(val validTill: String, - val validFrom: String, - val recurrenceInterval: Int, - val recurrenceOnDayMonth: String, - val fromClientId: Long, - val toClientId: Long, - val amount: Double ) : UseCase.RequestValues + class RequestValues( + val validTill: String, + val validFrom: String, + val recurrenceInterval: Int, + val recurrenceOnDayMonth: String, + val fromClientId: Long, + val toClientId: Long, + val amount: Double, + ) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue - -} \ No newline at end of file +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt index 7ab5ee612..dea053f75 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.standinginstruction import org.mifospay.core.data.base.UseCase @@ -8,36 +17,32 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by Devansh on 09/06/2020 - */ class DeleteStandingInstruction @Inject constructor( - private val apiRepository: FineractRepository) : - UseCase () { + private val apiRepository: FineractRepository, +) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { apiRepository.deleteStandingInstruction(requestValues.standingInstructionId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { e.message?.let { useCaseCallback.onError(it) } } - override fun onNext(genericResponse: GenericResponse) - = useCaseCallback.onSuccess(ResponseValue()) - }) + override fun onNext(genericResponse: GenericResponse) = + useCaseCallback.onSuccess(ResponseValue()) + }, + ) } class RequestValues(val standingInstructionId: Long) : - UseCase.RequestValues + UseCase.RequestValues class ResponseValue : UseCase.ResponseValue - -} \ No newline at end of file +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt index 7dfd32a4b..c14f2815d 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt @@ -1,17 +1,22 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.standinginstruction -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.standinginstruction.StandingInstruction +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by Devansh on 09/06/2020 - */ - class FetchStandingInstruction @Inject constructor( private val apiRepository: FineractRepository, ) : UseCase () { @@ -24,14 +29,12 @@ class FetchStandingInstruction @Inject constructor( object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { e.message?.let { useCaseCallback.onError(it) } } - override fun onNext(standingInstruction: StandingInstruction) = useCaseCallback.onSuccess(ResponseValue(standingInstruction)) }, @@ -41,5 +44,4 @@ class FetchStandingInstruction @Inject constructor( class RequestValues(val standingInstructionId: Long) : UseCase.RequestValues class ResponseValue(val standingInstruction: StandingInstruction) : UseCase.ResponseValue - -} \ No newline at end of file +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt index c33d74a16..cd715c479 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt @@ -1,46 +1,52 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.standinginstruction -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.Page import com.mifospay.core.model.entity.standinginstruction.StandingInstruction +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by Devansh 08/06/2020 - */ - -class GetAllStandingInstructions @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { - +class GetAllStandingInstructions @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { apiRepository.getAllStandingInstructions(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { + .observeOn(AndroidSchedulers.mainThread()) + .subscribeOn(Schedulers.io()) + .subscribe( + object : Subscriber >() { override fun onCompleted() { - } override fun onError(e: Throwable) { e.message?.let { useCaseCallback.onError(it) } } - - override fun onNext(standingInstructionPage: Page ) - = useCaseCallback.onSuccess(ResponseValue(standingInstructionPage.pageItems)) - - }) + override fun onNext(standingInstructionPage: Page ) { + return useCaseCallback.onSuccess( + ResponseValue(standingInstructionPage.pageItems), + ) + } + }, + ) } class RequestValues(val clientId: Long) : UseCase.RequestValues - class ResponseValue(val standingInstructionsList: List ) - : UseCase.ResponseValue - -} \ No newline at end of file + class ResponseValue(val standingInstructionsList: List ) : + UseCase.ResponseValue +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt index 6542220d8..81bfc27e2 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt @@ -1,8 +1,17 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.standinginstruction -import org.mifospay.core.data.base.UseCase import com.mifospay.core.model.entity.payload.StandingInstructionPayload import com.mifospay.core.model.entity.standinginstruction.StandingInstruction +import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.network.GenericResponse import rx.Subscriber @@ -10,26 +19,19 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by Devansh on 09/06/2020 - */ class UpdateStandingInstruction @Inject constructor( private val apiRepository: FineractRepository, -) : - UseCase< - UpdateStandingInstruction.RequestValues, - UpdateStandingInstruction.ResponseValue, - >() { +) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { val validTillString = "${requestValues.standingInstruction.validTill?.get(2)} " + - "${requestValues.standingInstruction.validTill?.get(1)} " + - "${requestValues.standingInstruction.validTill?.get(0)}" + "${requestValues.standingInstruction.validTill?.get(1)} " + + "${requestValues.standingInstruction.validTill?.get(0)}" val validFromString = "${requestValues.standingInstruction.validFrom[2]} " + - "${requestValues.standingInstruction.validFrom[1]} " + - "${requestValues.standingInstruction.validFrom[0]}" + "${requestValues.standingInstruction.validFrom[1]} " + + "${requestValues.standingInstruction.validFrom[0]}" val recurrenceOnMonthDayString = "${requestValues.standingInstruction.validFrom[2]} " + - "${requestValues.standingInstruction.validFrom[1]}" + "${requestValues.standingInstruction.validFrom[1]}" val standingInstructionPayload = StandingInstructionPayload( requestValues.standingInstruction.fromClient.officeId, @@ -67,7 +69,6 @@ class UpdateStandingInstruction @Inject constructor( object : Subscriber () { override fun onCompleted() { - } override fun onError(e: Throwable) { @@ -86,5 +87,4 @@ class UpdateStandingInstruction @Inject constructor( ) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue - -} \ No newline at end of file +} diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt index 699be8f9b..4698b3934 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt @@ -1,38 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.twofactor +import com.mifospay.core.model.domain.twofactor.DeliveryMethod import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository -import com.mifospay.core.model.domain.twofactor.DeliveryMethod import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 01/June/2018 - */ -class FetchDeliveryMethods @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchDeliveryMethods @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues : UseCase.RequestValues class ResponseValue( - val deliveryMethodList: List + val deliveryMethodList: List , ) : UseCase.ResponseValue override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.deliveryMethods .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber >() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(deliveryMethods: List
) { - useCaseCallback.onSuccess(ResponseValue(deliveryMethods)) - } + .subscribe( + object : Subscriber >() { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } - }) + override fun onNext(deliveryMethods: List
) { + useCaseCallback.onSuccess(ResponseValue(deliveryMethods)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt index c22c9784a..d2f9dc829 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.twofactor import org.mifospay.core.data.base.UseCase @@ -7,11 +16,9 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 01/June/2018 - */ -class RequestOTP @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class RequestOTP @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val deliveryMethod: String) : UseCase.RequestValues class ResponseValue(val response: String) : UseCase.ResponseValue @@ -20,16 +27,17 @@ class RequestOTP @Inject constructor(private val mFineractRepository: FineractRe mFineractRepository.requestOTP(requestValues.deliveryMethod) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(response: String) { - useCaseCallback.onSuccess(ResponseValue(response)) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(response: String) { + useCaseCallback.onSuccess(ResponseValue(response)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt index a60baf165..76ddc75ba 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt @@ -1,18 +1,25 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.twofactor +import com.mifospay.core.model.domain.twofactor.AccessToken import org.mifospay.core.data.base.UseCase import org.mifospay.core.data.fineract.repository.FineractRepository -import com.mifospay.core.model.domain.twofactor.AccessToken import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 01/June/2018 - */ -class ValidateOTP @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class ValidateOTP @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { class RequestValues(val token: String) : UseCase.RequestValues class ResponseValue(val accessToken: AccessToken) : UseCase.ResponseValue @@ -21,16 +28,17 @@ class ValidateOTP @Inject constructor(private val mFineractRepository: FineractR mFineractRepository.validateToken(requestValues.token) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(accessToken: AccessToken) { - useCaseCallback.onSuccess(ResponseValue(accessToken)) - } - }) + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(e.toString()) + } + override fun onNext(accessToken: AccessToken) { + useCaseCallback.onSuccess(ResponseValue(accessToken)) + } + }, + ) } } diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt index c009d6543..2bb822304 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import com.mifospay.core.model.domain.user.User @@ -11,7 +20,7 @@ import rx.schedulers.Schedulers import javax.inject.Inject class AuthenticateUser @Inject constructor( - private val apiRepository: FineractRepository + private val apiRepository: FineractRepository, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt index 9a4821550..7cbfc079b 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import com.mifospay.core.model.domain.user.NewUser @@ -10,33 +19,32 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 17/6/17. - */ class CreateUser @Inject constructor(private val apiRepository: FineractRepository) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { apiRepository.createUser(requestValues.user) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - getUserMessage(e) - var message: String - try { - message = (e as HttpException).response()!!.errorBody()!!.string() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + getUserMessage(e) + var message: String + try { + message = (e as HttpException).response()!!.errorBody()!!.string() + message = getUserMessage(message) + } catch (e1: Exception) { + message = e1.message.toString() + } + useCaseCallback.onError(message) } - useCaseCallback.onError(message) - } - override fun onNext(genericResponse: ResponseValue) { - useCaseCallback.onSuccess(genericResponse) - } - }) + override fun onNext(genericResponse: ResponseValue) { + useCaseCallback.onSuccess(genericResponse) + } + }, + ) } class RequestValues(val user: NewUser) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt index 00483dc36..8bf1177c8 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import org.mifospay.core.data.base.UseCase @@ -8,25 +17,25 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 26/June/2018 - */ -class DeleteUser @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class DeleteUser @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.deleteUser(requestValues.userId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + e.message?.let { useCaseCallback.onError(it) } + } - override fun onNext(genericResponse: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + override fun onNext(genericResponse: GenericResponse) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } class RequestValues(val userId: Int) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt index 513ede86e..c019540f5 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import com.mifospay.core.model.entity.UserWithRole @@ -8,25 +17,25 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 09/July/2018 - */ -class FetchUserDetails @Inject constructor(private val mFineractRepository: FineractRepository) : - UseCase () { +class FetchUserDetails @Inject constructor( + private val mFineractRepository: FineractRepository, +) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.getUser() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + e.message?.let { useCaseCallback.onError(it) } + } - override fun onNext(userWithRole: UserWithRole) { - useCaseCallback.onSuccess(ResponseValue(userWithRole)) - } - }) + override fun onNext(userWithRole: UserWithRole) { + useCaseCallback.onSuccess(ResponseValue(userWithRole)) + } + }, + ) } class RequestValues(val userId: Long) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt index 97938f9ab..b2813e61e 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import com.mifospay.core.model.entity.UserWithRole @@ -10,7 +19,7 @@ import rx.schedulers.Schedulers import javax.inject.Inject class FetchUsers @Inject constructor( - private val mFineractRepository: FineractRepository + private val mFineractRepository: FineractRepository, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt index 6be2a3dbc..3eaed68e2 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import com.mifospay.core.model.entity.register.RegisterPayload @@ -10,25 +19,26 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 17/8/17. - */ -class RegisterUser @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { - protected override fun executeUseCase(requestValues: RequestValues) { +class RegisterUser @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { + + override fun executeUseCase(requestValues: RequestValues) { apiRepository.registerUser(requestValues.registerPayload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_REGISTERING_USER) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_REGISTERING_USER) + } - override fun onNext(t: ResponseBody?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + override fun onNext(t: ResponseBody?) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } data class RequestValues(val registerPayload: RegisterPayload) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt index 5cb280f7b..a53f16fda 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import org.mifospay.core.data.base.UseCase @@ -10,33 +19,32 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by ankur on 25/June/2018 - */ class UpdateUser @Inject constructor( - private val mFineractRepository: FineractRepository + private val mFineractRepository: FineractRepository, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { mFineractRepository.updateUser(requestValues.updateUserEntity, requestValues.userId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - var message: String - try { - message = (e as HttpException).response()!!.errorBody()!!.string() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + var message: String + try { + message = (e as HttpException).response()!!.errorBody()!!.string() + message = getUserMessage(message) + } catch (e1: Exception) { + message = e1.message.toString() + } + useCaseCallback.onError(message) } - useCaseCallback.onError(message) - } - override fun onNext(genericResponse: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + override fun onNext(genericResponse: GenericResponse?) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } class RequestValues(val updateUserEntity: Any, val userId: Int) : UseCase.RequestValues diff --git a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt index b3be9fbc3..cd68fbb97 100644 --- a/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt +++ b/core/data/src/main/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.domain.usecase.user import com.mifospay.core.model.entity.register.UserVerify @@ -10,27 +19,27 @@ import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers import javax.inject.Inject -/** - * Created by naman on 17/8/17. - */ -class VerifyUser @Inject constructor(private val apiRepository: FineractRepository) : - UseCase () { - override fun executeUseCase(requestValues: RequestValues) { +class VerifyUser @Inject constructor( + private val apiRepository: FineractRepository, +) : UseCase () { + override fun executeUseCase(requestValues: RequestValues) { apiRepository.verifyUser(requestValues.userVerify) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber () { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_VERIFYING_USER) - } + .subscribe( + object : Subscriber () { + override fun onCompleted() {} + override fun onError(e: Throwable) { + useCaseCallback.onError(Constants.ERROR_VERIFYING_USER) + } - override fun onNext(t: ResponseBody?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }) + override fun onNext(t: ResponseBody?) { + useCaseCallback.onSuccess(ResponseValue()) + } + }, + ) } - class RequestValues( val userVerify: UserVerify) : UseCase.RequestValues + class RequestValues(val userVerify: UserVerify) : UseCase.RequestValues class ResponseValue : UseCase.ResponseValue } diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt index 7fcd21127..64f21ba33 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt @@ -1,10 +1,21 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.entity.mapper -import com.mifospay.core.model.entity.client.ClientAccounts import com.mifospay.core.model.domain.Account +import com.mifospay.core.model.entity.client.ClientAccounts import javax.inject.Inject -class AccountMapper @Inject constructor(private val currencyMapper: CurrencyMapper) { +class AccountMapper @Inject constructor( + private val currencyMapper: CurrencyMapper, +) { fun transform(clientAccounts: ClientAccounts?): List { val accountList = mutableListOf () diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt index 5cb38667c..8c96d6542 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.entity.mapper import com.mifospay.core.model.entity.client.Client diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt index 6a873d845..a96dc6802 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt @@ -1,10 +1,18 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.entity.mapper import com.mifospay.core.model.entity.accounts.savings.Currency import javax.inject.Inject import com.mifospay.core.model.domain.Currency as DomainCurrency - class CurrencyMapper @Inject internal constructor() { fun transform(savingsCurrency: Currency): DomainCurrency { val currency: DomainCurrency = diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt index 37d156b07..4073c72ef 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt @@ -1,19 +1,27 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.entity.mapper -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository import com.mifospay.core.model.domain.Account import com.mifospay.core.model.entity.client.ClientAccounts +import org.mifospay.core.data.base.UseCase +import org.mifospay.core.data.fineract.repository.FineractRepository import org.mifospay.core.data.util.Constants import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers - import javax.inject.Inject class FetchAccount @Inject constructor( private val fineractRepository: FineractRepository, - private val accountMapper: AccountMapper + private val accountMapper: AccountMapper, ) : UseCase () { override fun executeUseCase(requestValues: RequestValues) { diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt index 61a4ac134..4f9b58ea1 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt @@ -1,12 +1,18 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.entity.mapper import com.mifospay.core.model.domain.SearchResult import com.mifospay.core.model.entity.SearchedEntity import javax.inject.Inject -/** - * Created by naman on 19/8/17. - */ class SearchedEntitiesMapper @Inject internal constructor() { fun transformList(searchedEntities: List ?): List { val searchResults: MutableList = ArrayList() diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt index 34bf9ad28..9f2c09513 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt @@ -1,13 +1,24 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.entity.mapper -import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations -import com.mifospay.core.model.entity.accounts.savings.Transactions import com.mifospay.core.model.domain.Transaction import com.mifospay.core.model.domain.TransactionType +import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations +import com.mifospay.core.model.entity.accounts.savings.Transactions import com.mifospay.core.model.utils.DateHelper import javax.inject.Inject -class TransactionMapper @Inject constructor(private val currencyMapper: CurrencyMapper) { +class TransactionMapper @Inject constructor( + private val currencyMapper: CurrencyMapper, +) { fun transformTransactionList(savingsWithAssociations: SavingsWithAssociations?): List { val transactionList = ArrayList () @@ -18,7 +29,7 @@ class TransactionMapper @Inject constructor(private val currencyMapper: Currency return transactionList } - fun transformInvoice(transactions: Transactions?): Transaction { + fun transformInvoice(transactions: Transactions?): Transaction { val transaction = Transaction() if (transactions != null) { @@ -27,7 +38,7 @@ class TransactionMapper @Inject constructor(private val currencyMapper: Currency transaction.receiptId = it.receiptNumber } transaction.amount = transactions.amount - transactions.submittedOnDate?.let { + transactions.submittedOnDate.let { transaction.date = DateHelper.getDateAsString(it) } transaction.currency = currencyMapper.transform(transactions.currency) @@ -41,7 +52,7 @@ class TransactionMapper @Inject constructor(private val currencyMapper: Currency transaction.transactionType = TransactionType.DEBIT } - transactions.transfer?.let { + transactions.transfer.let { transaction.transferId = it.id } } diff --git a/core/data/src/main/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt b/core/data/src/main/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt index 7d7ec21af..4e2a4577a 100644 --- a/core/data/src/main/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt +++ b/core/data/src/main/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.data.fineract.repository import com.mifospay.core.model.domain.NewAccount @@ -41,12 +50,11 @@ import rx.Observable import javax.inject.Inject import javax.inject.Singleton - @Singleton @Suppress("TooManyFunctions") class FineractRepository @Inject constructor( private val fineractApiManager: FineractApiManager, - private val selfApiManager: SelfServiceApiManager + private val selfApiManager: SelfServiceApiManager, ) { fun createClient(newClient: NewClient): Observable