diff --git a/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt b/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt index b8ce7497b2..aab84c3ce2 100644 --- a/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt +++ b/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt @@ -19,7 +19,7 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction -import org.gradle.internal.extensions.stdlib.capitalized +import org.gradle.configurationcache.extensions.capitalized import org.gradle.kotlin.dsl.register import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.process.ExecOperations diff --git a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt index a8b95ee856..f2f155f343 100644 --- a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt @@ -49,7 +49,6 @@ import com.mifos.core.data.repository.SearchRepository import com.mifos.core.data.repository.SignatureRepository import com.mifos.core.data.repository.SurveyListRepository import com.mifos.core.data.repository.SurveySubmitRepository -import com.mifos.core.data.repositoryImp.ActivateRepositoryImp import com.mifos.core.data.repositoryImp.CenterDetailsRepositoryImp import com.mifos.core.data.repositoryImp.CenterListRepositoryImp import com.mifos.core.data.repositoryImp.ChargeDialogRepositoryImp @@ -57,10 +56,8 @@ import com.mifos.core.data.repositoryImp.CheckerInboxRepositoryImp import com.mifos.core.data.repositoryImp.CheckerInboxTasksRepositoryImp import com.mifos.core.data.repositoryImp.ClientChargeRepositoryImp import com.mifos.core.data.repositoryImp.ClientIdentifierDialogRepositoryImp -import com.mifos.core.data.repositoryImp.ClientIdentifiersRepositoryImp import com.mifos.core.data.repositoryImp.CreateNewCenterRepositoryImp import com.mifos.core.data.repositoryImp.CreateNewGroupRepositoryImp -import com.mifos.core.data.repositoryImp.DataTableDataRepositoryImp import com.mifos.core.data.repositoryImp.DataTableListRepositoryImp import com.mifos.core.data.repositoryImp.DataTableRepositoryImp import com.mifos.core.data.repositoryImp.DataTableRowDialogRepositoryImp @@ -89,6 +86,9 @@ import com.mifos.core.data.repositoryImp.SearchRepositoryImp import com.mifos.core.data.repositoryImp.SignatureRepositoryImp import com.mifos.core.data.repositoryImp.SurveyListRepositoryImp import com.mifos.core.data.repositoryImp.SurveySubmitRepositoryImp +import com.mifos.core.data.repository_imp.ActivateRepositoryImp +import com.mifos.core.data.repository_imp.ClientIdentifiersRepositoryImp +import com.mifos.core.data.repository_imp.DataTableDataRepositoryImp import dagger.Binds import dagger.Module import dagger.hilt.InstallIn diff --git a/core/data/src/main/java/com/mifos/core/data/pagingSource/CenterListPagingSource.kt b/core/data/src/main/java/com/mifos/core/data/pagingSource/CenterListPagingSource.kt index 69a7209d99..9160114e55 100644 --- a/core/data/src/main/java/com/mifos/core/data/pagingSource/CenterListPagingSource.kt +++ b/core/data/src/main/java/com/mifos/core/data/pagingSource/CenterListPagingSource.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.pagingSource import androidx.paging.PagingSource @@ -27,7 +18,7 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) : override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { position -> state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition( - position, + position )?.nextKey?.minus(10) } } @@ -43,43 +34,21 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) : LoadResult.Page( data = centerListWithSync, prevKey = if (position <= 0) null else position - 10, - nextKey = if (position >= totalCenters) null else position + 10, + nextKey = if (position >= totalCenters) null else position + 10 ) } catch (e: Exception) { LoadResult.Error(e) } } - private suspend fun getCenterList(position: Int): Pair, Int> = - suspendCoroutine { continuation -> - try { - dataManagerCenter.getCenters(true, position, 10) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - } - - override fun onError(exception: Throwable) { - continuation.resumeWithException(exception) - } - - override fun onNext(center: Page
) { - continuation.resume( - Pair( - center.pageItems, - center.totalFilteredRecords, - ), - ) - } - }) - } catch (exception: Exception) { - continuation.resumeWithException(exception) - } - } + private suspend fun getCenterList(position: Int): Pair, Int> { + val pagedClient = dataManagerCenter.getCenters(true, position, 10) + return Pair(pagedClient.pageItems, pagedClient.totalFilteredRecords) + } private suspend fun getCenterDbList(): List
= suspendCoroutine { continuation -> try { + dataManagerCenter.allDatabaseCenters .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) @@ -100,9 +69,10 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) : } } + private fun getCenterListWithSync( centerList: List
, - centerDbList: List
, + centerDbList: List
): List
{ if (centerDbList.isNotEmpty()) { centerList.forEach { center -> @@ -115,4 +85,4 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) : } return centerList } -} +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientListPagingSource.kt b/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientListPagingSource.kt index 20b86929bf..896e609b77 100644 --- a/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientListPagingSource.kt +++ b/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientListPagingSource.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.pagingSource import androidx.paging.PagingSource @@ -14,7 +5,6 @@ import androidx.paging.PagingState import com.mifos.core.network.datamanager.DataManagerClient import com.mifos.core.objects.client.Client import com.mifos.core.objects.client.Page -import kotlinx.coroutines.suspendCancellableCoroutine import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers @@ -27,13 +17,13 @@ import kotlin.coroutines.suspendCoroutine */ class ClientListPagingSource( - private val dataManagerClient: DataManagerClient, + private val dataManagerClient: DataManagerClient ) : PagingSource() { override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { position -> state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition( - position, + position )?.nextKey?.minus(10) } } @@ -49,7 +39,7 @@ class ClientListPagingSource( LoadResult.Page( data = clientListWithSync, prevKey = if (position <= 0) null else position - 10, - nextKey = if (position >= totalClients) null else position + 10, + nextKey = if (position >= totalClients) null else position + 10 ) } catch (e: Exception) { LoadResult.Error(e) @@ -57,23 +47,8 @@ class ClientListPagingSource( } private suspend fun getClientList(position: Int): Pair, Int> { - return suspendCancellableCoroutine { continuation -> - dataManagerClient.getAllClients(offset = position, 10) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - continuation.resumeWithException(e) - } - - override fun onNext(t: Page) { - continuation.resume(Pair(t.pageItems, t.totalFilteredRecords)) - } - }) - } + val response = dataManagerClient.getAllClients(position, 10) + return Pair(response.pageItems, response.totalFilteredRecords) } private suspend fun getClientDbList(): List { @@ -98,7 +73,7 @@ class ClientListPagingSource( private fun getClientListWithSync( clientList: List, - clientDbList: List, + clientDbList: List ): List { if (clientDbList.isNotEmpty()) { clientList.forEach { client -> @@ -111,4 +86,4 @@ class ClientListPagingSource( } return clientList } -} +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/ActivateRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/ActivateRepository.kt index 2044609855..e423e4a252 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/ActivateRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/ActivateRepository.kt @@ -1,18 +1,9 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.repository import com.mifos.core.network.GenericResponse import com.mifos.core.objects.client.ActivatePayload -import org.apache.fineract.client.models.PostCentersCenterIdResponse -import org.apache.fineract.client.models.PostClientsClientIdResponse +import org.openapitools.client.models.PostCentersCenterIdResponse +import org.openapitools.client.models.PostClientsClientIdResponse import rx.Observable /** @@ -21,18 +12,19 @@ import rx.Observable interface ActivateRepository { - fun activateClient( + suspend fun activateClient( clientId: Int, - clientActivate: ActivatePayload?, - ): Observable + clientActivate: ActivatePayload? + ): PostClientsClientIdResponse - fun activateCenter( + suspend fun activateCenter( centerId: Int, - activatePayload: ActivatePayload?, - ): Observable + activatePayload: ActivatePayload? + ): PostCentersCenterIdResponse fun activateGroup( groupId: Int, - activatePayload: ActivatePayload?, + activatePayload: ActivatePayload? ): Observable -} + +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/ClientDetailsRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/ClientDetailsRepository.kt index a563d6cf4b..780b99c0f4 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/ClientDetailsRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/ClientDetailsRepository.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.repository import com.mifos.core.objects.accounts.ClientAccounts @@ -24,7 +15,8 @@ interface ClientDetailsRepository { fun deleteClientImage(clientId: Int): Observable - fun getClientAccounts(clientId: Int): Observable + suspend fun getClientAccounts(clientId: Int): ClientAccounts + + suspend fun getClient(clientId: Int): Client - fun getClient(clientId: Int): Observable -} +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifierDialogRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifierDialogRepository.kt index 68e00e2381..345fabcb80 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifierDialogRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifierDialogRepository.kt @@ -12,14 +12,13 @@ package com.mifos.core.data.repository import com.mifos.core.objects.noncore.IdentifierCreationResponse import com.mifos.core.objects.noncore.IdentifierPayload import com.mifos.core.objects.noncore.IdentifierTemplate -import rx.Observable /** * Created by Aditya Gupta on 16/08/23. */ interface ClientIdentifierDialogRepository { - fun getClientIdentifierTemplate(clientId: Int): Observable + suspend fun getClientIdentifierTemplate(clientId: Int): IdentifierTemplate suspend fun createClientIdentifier( clientId: Int, diff --git a/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifiersRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifiersRepository.kt index e467211c76..d7d84de7c5 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifiersRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/ClientIdentifiersRepository.kt @@ -1,27 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.repository import com.mifos.core.objects.noncore.Identifier -import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse -import rx.Observable +import org.openapitools.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse /** * Created by Aditya Gupta on 08/08/23. */ interface ClientIdentifiersRepository { - fun getClientIdentifiers(clientId: Int): Observable> + suspend fun getClientIdentifiers(clientId: Int): List - fun deleteClientIdentifier( + suspend fun deleteClientIdentifier( clientId: Int, - identifierId: Int, - ): Observable -} + identifierId: Int + ): DeleteClientsClientIdIdentifiersIdentifierIdResponse +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/CreateNewClientRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/CreateNewClientRepository.kt index 557df8d0fb..c2066f9977 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/CreateNewClientRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/CreateNewClientRepository.kt @@ -25,9 +25,9 @@ interface CreateNewClientRepository { fun clientTemplate(): Observable - fun offices(): Observable> + suspend fun offices(): List - fun getStaffInOffice(officeId: Int): Observable> + suspend fun getStaffInOffice(officeId: Int): List fun createClient(clientPayload: ClientPayload): Observable diff --git a/core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt index 882f551157..641b9732a9 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/CreateNewGroupRepository.kt @@ -19,7 +19,7 @@ import rx.Observable */ interface CreateNewGroupRepository { - fun offices(): Observable> + suspend fun offices(): List fun createGroup(groupPayload: GroupPayload): Observable } diff --git a/core/data/src/main/java/com/mifos/core/data/repository/DataTableDataRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/DataTableDataRepository.kt index 14053d5a2b..f798fd2d0d 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/DataTableDataRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/DataTableDataRepository.kt @@ -1,17 +1,7 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.repository import com.google.gson.JsonArray -import org.apache.fineract.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse -import rx.Observable +import org.openapitools.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse /** * Created by Aditya Gupta on 10/08/23. @@ -20,9 +10,10 @@ interface DataTableDataRepository { suspend fun getDataTableInfo(table: String, entityId: Int): JsonArray - fun deleteDataTableEntry( - table: String?, + suspend fun deleteDataTableEntry( + table: String, entity: Int, - rowId: Int, - ): Observable -} + rowId: Int + ): DeleteDataTablesDatatableAppTableIdDatatableIdResponse + +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt index ebacb26fe6..8b61e82da6 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt @@ -1,21 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.repository import com.mifos.core.objects.noncore.DataTable -import rx.Observable /** * Created by Aditya Gupta on 08/08/23. */ interface DataTableRepository { - fun getDataTable(tableName: String?): Observable> -} + suspend fun getDataTable(tableName: String?): List + +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/LoginRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/LoginRepository.kt index beeed2c5ab..1568efb6c7 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/LoginRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/LoginRepository.kt @@ -1,16 +1,6 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.data.repository -import org.apache.fineract.client.models.PostAuthenticationResponse -import rx.Observable +import org.openapitools.client.models.PostAuthenticationResponse /** * Created by Aditya Gupta on 06/08/23. @@ -18,5 +8,6 @@ import rx.Observable interface LoginRepository { - fun login(username: String, password: String): Observable -} + suspend fun login(username: String, password: String): PostAuthenticationResponse + +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/SyncCentersDialogRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/SyncCentersDialogRepository.kt index b1c006dbae..8333515423 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/SyncCentersDialogRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/SyncCentersDialogRepository.kt @@ -40,7 +40,7 @@ interface SyncCentersDialogRepository { fun syncGroupAccounts(groupId: Int): Observable - fun syncClientAccounts(clientId: Int): Observable + suspend fun syncClientAccounts(clientId: Int): ClientAccounts fun syncGroupInDatabase(group: Group): Observable diff --git a/core/data/src/main/java/com/mifos/core/data/repository/SyncClientsDialogRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/SyncClientsDialogRepository.kt index 962d75dc6c..e5e3a29971 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/SyncClientsDialogRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/SyncClientsDialogRepository.kt @@ -22,7 +22,7 @@ import rx.Observable */ interface SyncClientsDialogRepository { - fun syncClientAccounts(clientId: Int): Observable + suspend fun syncClientAccounts(clientId: Int): ClientAccounts fun syncLoanById(loanId: Int): Observable diff --git a/core/data/src/main/java/com/mifos/core/data/repository/SyncGroupsDialogRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/SyncGroupsDialogRepository.kt index aedf27df82..18009e6caf 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/SyncGroupsDialogRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/SyncGroupsDialogRepository.kt @@ -47,7 +47,7 @@ interface SyncGroupsDialogRepository { fun syncClientInDatabase(client: Client): Observable - fun syncClientAccounts(clientId: Int): Observable + suspend fun syncClientAccounts(clientId: Int): ClientAccounts fun syncGroupInDatabase(group: Group): Observable } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ActivateRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ActivateRepositoryImp.kt index 01d6a4df13..262d3561de 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ActivateRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ActivateRepositoryImp.kt @@ -1,13 +1,4 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ -package com.mifos.core.data.repositoryImp +package com.mifos.core.data.repository_imp import com.mifos.core.data.repository.ActivateRepository import com.mifos.core.network.GenericResponse @@ -15,8 +6,8 @@ import com.mifos.core.network.datamanager.DataManagerCenter import com.mifos.core.network.datamanager.DataManagerClient import com.mifos.core.network.datamanager.DataManagerGroups import com.mifos.core.objects.client.ActivatePayload -import org.apache.fineract.client.models.PostCentersCenterIdResponse -import org.apache.fineract.client.models.PostClientsClientIdResponse +import org.openapitools.client.models.PostCentersCenterIdResponse +import org.openapitools.client.models.PostClientsClientIdResponse import rx.Observable import javax.inject.Inject @@ -26,27 +17,27 @@ import javax.inject.Inject class ActivateRepositoryImp @Inject constructor( private val dataManagerClient: DataManagerClient, private val dataManagerCenter: DataManagerCenter, - private val dataManagerGroups: DataManagerGroups, + private val dataManagerGroups: DataManagerGroups ) : ActivateRepository { - override fun activateClient( + override suspend fun activateClient( clientId: Int, - clientActivate: ActivatePayload?, - ): Observable { + clientActivate: ActivatePayload? + ): PostClientsClientIdResponse { return dataManagerClient.activateClient(clientId, clientActivate) } - override fun activateCenter( + override suspend fun activateCenter( centerId: Int, - activatePayload: ActivatePayload?, - ): Observable { + activatePayload: ActivatePayload? + ): PostCentersCenterIdResponse { return dataManagerCenter.activateCenter(centerId, activatePayload) } override fun activateGroup( groupId: Int, - activatePayload: ActivatePayload?, + activatePayload: ActivatePayload? ): Observable { return dataManagerGroups.activateGroup(groupId, activatePayload) } -} +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientDetailsRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientDetailsRepositoryImp.kt index 1b4778f38a..eed9c06a74 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientDetailsRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientDetailsRepositoryImp.kt @@ -32,11 +32,11 @@ class ClientDetailsRepositoryImp @Inject constructor(private val dataManagerClie return dataManagerClient.deleteClientImage(clientId) } - override fun getClientAccounts(clientId: Int): Observable { + override suspend fun getClientAccounts(clientId: Int): ClientAccounts { return dataManagerClient.getClientAccounts(clientId) } - override fun getClient(clientId: Int): Observable { + override suspend fun getClient(clientId: Int): Client { return dataManagerClient.getClient(clientId) } } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifierDialogRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifierDialogRepositoryImp.kt index 903ec96000..71b3b9c2f1 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifierDialogRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifierDialogRepositoryImp.kt @@ -14,7 +14,6 @@ import com.mifos.core.network.datamanager.DataManagerClient import com.mifos.core.objects.noncore.IdentifierCreationResponse import com.mifos.core.objects.noncore.IdentifierPayload import com.mifos.core.objects.noncore.IdentifierTemplate -import rx.Observable import javax.inject.Inject /** @@ -23,7 +22,7 @@ import javax.inject.Inject class ClientIdentifierDialogRepositoryImp @Inject constructor(private val dataManagerClient: DataManagerClient) : ClientIdentifierDialogRepository { - override fun getClientIdentifierTemplate(clientId: Int): Observable { + override suspend fun getClientIdentifierTemplate(clientId: Int): IdentifierTemplate { return dataManagerClient.getClientIdentifierTemplate(clientId) } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifiersRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifiersRepositoryImp.kt index 34c6e29f13..a1443f235d 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifiersRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/ClientIdentifiersRepositoryImp.kt @@ -1,19 +1,9 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ -package com.mifos.core.data.repositoryImp +package com.mifos.core.data.repository_imp import com.mifos.core.data.repository.ClientIdentifiersRepository import com.mifos.core.network.datamanager.DataManagerClient import com.mifos.core.objects.noncore.Identifier -import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse -import rx.Observable +import org.openapitools.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse import javax.inject.Inject /** @@ -22,14 +12,15 @@ import javax.inject.Inject class ClientIdentifiersRepositoryImp @Inject constructor(private val dataManagerClient: DataManagerClient) : ClientIdentifiersRepository { - override fun getClientIdentifiers(clientId: Int): Observable> { + override suspend fun getClientIdentifiers(clientId: Int): List { return dataManagerClient.getClientIdentifiers(clientId) } - override fun deleteClientIdentifier( + override suspend fun deleteClientIdentifier( clientId: Int, - identifierId: Int, - ): Observable { + identifierId: Int + ): DeleteClientsClientIdIdentifiersIdentifierIdResponse { return dataManagerClient.deleteClientIdentifier(clientId, identifierId) } -} + +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewClientRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewClientRepositoryImp.kt index a213dd9cb3..5e3d2cebfb 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewClientRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewClientRepositoryImp.kt @@ -36,11 +36,11 @@ class CreateNewClientRepositoryImp @Inject constructor( return dataManagerClient.clientTemplate } - override fun offices(): Observable> { - return dataManagerOffices.offices + override suspend fun offices(): List { + return dataManagerOffices.offices() } - override fun getStaffInOffice(officeId: Int): Observable> { + override suspend fun getStaffInOffice(officeId: Int): List { return dataManagerStaff.getStaffInOffice(officeId) } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewGroupRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewGroupRepositoryImp.kt index a227acc182..657d184296 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewGroupRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/CreateNewGroupRepositoryImp.kt @@ -26,8 +26,8 @@ class CreateNewGroupRepositoryImp @Inject constructor( private val dataManagerGroups: DataManagerGroups, ) : CreateNewGroupRepository { - override fun offices(): Observable> { - return dataManagerOffices.offices + override suspend fun offices(): List { + return dataManagerOffices.offices() } override fun createGroup(groupPayload: GroupPayload): Observable { diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableDataRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableDataRepositoryImp.kt index c2071d9948..a1f5fc9a44 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableDataRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableDataRepositoryImp.kt @@ -1,19 +1,9 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ -package com.mifos.core.data.repositoryImp +package com.mifos.core.data.repository_imp import com.google.gson.JsonArray import com.mifos.core.data.repository.DataTableDataRepository import com.mifos.core.network.datamanager.DataManagerDataTable -import org.apache.fineract.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse -import rx.Observable +import org.openapitools.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse import javax.inject.Inject /** @@ -26,11 +16,12 @@ class DataTableDataRepositoryImp @Inject constructor(private val dataManagerData return dataManagerDataTable.getDataTableInfo(table, entityId) } - override fun deleteDataTableEntry( - table: String?, + override suspend fun deleteDataTableEntry( + table: String, entity: Int, - rowId: Int, - ): Observable { + rowId: Int + ): DeleteDataTablesDatatableAppTableIdDatatableIdResponse { return dataManagerDataTable.deleteDataTableEntry(table, entity, rowId) } -} + +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableRepositoryImp.kt index a0a8b09942..0be9fef3d2 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/DataTableRepositoryImp.kt @@ -12,7 +12,6 @@ package com.mifos.core.data.repositoryImp import com.mifos.core.data.repository.DataTableRepository import com.mifos.core.network.datamanager.DataManagerDataTable import com.mifos.core.objects.noncore.DataTable -import rx.Observable import javax.inject.Inject /** @@ -21,7 +20,7 @@ import javax.inject.Inject class DataTableRepositoryImp @Inject constructor(private val dataManagerDataTable: DataManagerDataTable) : DataTableRepository { - override fun getDataTable(tableName: String?): Observable> { + override suspend fun getDataTable(tableName: String?): List { return dataManagerDataTable.getDataTable(tableName) } } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/GroupsListRepositoryImpl.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/GroupsListRepositoryImpl.kt index d441c7bc40..36fb8a95c2 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/GroupsListRepositoryImpl.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/GroupsListRepositoryImpl.kt @@ -15,7 +15,6 @@ import com.mifos.core.objects.client.Page import com.mifos.core.objects.group.Group import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.suspendCancellableCoroutine import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers @@ -27,26 +26,8 @@ import kotlin.coroutines.suspendCoroutine class GroupsListRepositoryImpl @Inject constructor( private val dataManager: DataManagerGroups, ) : GroupsListRepository { - override suspend fun getAllGroups(paged: Boolean, offset: Int, limit: Int): List { - return suspendCancellableCoroutine { continuation -> - dataManager - .getGroups(paged, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - } - - override fun onError(error: Throwable) { - continuation.resumeWithException(error) - } - - override fun onNext(groups: Page) { - continuation.resume(groups.pageItems) - } - }) - } - } + override suspend fun getAllGroups(paged: Boolean, offset: Int, limit: Int): List = + dataManager.getGroups(paged, offset, limit).pageItems override fun getAllLocalGroups(): Flow> { return flow { diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/LoginRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/LoginRepositoryImp.kt index b98da6c315..efdc181204 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/LoginRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/LoginRepositoryImp.kt @@ -11,8 +11,7 @@ package com.mifos.core.data.repositoryImp import com.mifos.core.data.repository.LoginRepository import com.mifos.core.network.datamanger.DataManagerAuth -import org.apache.fineract.client.models.PostAuthenticationResponse -import rx.Observable +import org.openapitools.client.models.PostAuthenticationResponse import javax.inject.Inject /** @@ -22,7 +21,7 @@ import javax.inject.Inject class LoginRepositoryImp @Inject constructor(private val dataManagerAuth: DataManagerAuth) : LoginRepository { - override fun login(username: String, password: String): Observable { + override suspend fun login(username: String, password: String): PostAuthenticationResponse { return dataManagerAuth.login(username, password) } } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncCentersDialogRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncCentersDialogRepositoryImp.kt index c71a843480..1ed198ba81 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncCentersDialogRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncCentersDialogRepositoryImp.kt @@ -65,7 +65,7 @@ class SyncCentersDialogRepositoryImp @Inject constructor( return dataManagerGroups.syncGroupAccounts(groupId) } - override fun syncClientAccounts(clientId: Int): Observable { + override suspend fun syncClientAccounts(clientId: Int): ClientAccounts { return dataManagerClient.syncClientAccounts(clientId) } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncClientsDialogRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncClientsDialogRepositoryImp.kt index ff3b9df29e..7be61d67d9 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncClientsDialogRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncClientsDialogRepositoryImp.kt @@ -31,7 +31,7 @@ class SyncClientsDialogRepositoryImp @Inject constructor( private val dataManagerSavings: DataManagerSavings, ) : SyncClientsDialogRepository { - override fun syncClientAccounts(clientId: Int): Observable { + override suspend fun syncClientAccounts(clientId: Int): ClientAccounts { return dataManagerClient.getClientAccounts(clientId) } diff --git a/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncGroupsDialogRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncGroupsDialogRepositoryImp.kt index ec3b5e6817..3630e8838a 100644 --- a/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncGroupsDialogRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repositoryImp/SyncGroupsDialogRepositoryImp.kt @@ -76,7 +76,7 @@ class SyncGroupsDialogRepositoryImp @Inject constructor( return dataManagerClient.syncClientInDatabase(client) } - override fun syncClientAccounts(clientId: Int): Observable { + override suspend fun syncClientAccounts(clientId: Int): ClientAccounts { return dataManagerClient.getClientAccounts(clientId) } diff --git a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt index c468858059..1a8e8b1d74 100644 --- a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt +++ b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt @@ -20,9 +20,9 @@ import com.mifos.core.model.ServerConfig import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow -import org.apache.fineract.client.models.PostAuthenticationResponse import org.mifos.core.sharedpreference.Key import org.mifos.core.sharedpreference.UserPreferences +import org.openapitools.client.models.PostAuthenticationResponse import javax.inject.Inject /** diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateCenterUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateCenterUseCase.kt index 014c517c85..bd566997dd 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateCenterUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateCenterUseCase.kt @@ -1,51 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.ActivateRepository import com.mifos.core.objects.client.ActivatePayload -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import org.apache.fineract.client.models.PostCentersCenterIdResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow +import org.openapitools.client.models.PostCentersCenterIdResponse import javax.inject.Inject class ActivateCenterUseCase @Inject constructor(private val activateRepository: ActivateRepository) { suspend operator fun invoke( centerId: Int, - centerPayload: ActivatePayload, - ): Flow> = callbackFlow { + centerPayload: ActivatePayload + ): Flow> = flow { try { - trySend(Resource.Loading()) - activateRepository.activateCenter(centerId, centerPayload) - .subscribeOn(AndroidSchedulers.mainThread()) - .observeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - - override fun onError(exception: Throwable) { - trySend(Resource.Error(exception.message.toString())) - } - - override fun onNext(response: PostCentersCenterIdResponse) { - trySend(Resource.Success(response)) - } - }) - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = activateRepository.activateCenter(centerId, centerPayload) + emit(Resource.Success(response)) } catch (exception: Exception) { - trySend(Resource.Error(exception.message.toString())) + emit(Resource.Error(exception.message.toString())) } } -} +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateClientUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateClientUseCase.kt index 47656bf8b9..a42844c656 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateClientUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/ActivateClientUseCase.kt @@ -1,51 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.ActivateRepository import com.mifos.core.objects.client.ActivatePayload -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import org.apache.fineract.client.models.PostClientsClientIdResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow +import org.openapitools.client.models.PostClientsClientIdResponse import javax.inject.Inject class ActivateClientUseCase @Inject constructor(private val activateRepository: ActivateRepository) { suspend operator fun invoke( clientId: Int, - clientPayload: ActivatePayload, - ): Flow> = callbackFlow { + clientPayload: ActivatePayload + ): Flow> = flow { try { - trySend(Resource.Loading()) - activateRepository.activateClient(clientId, clientPayload) - .subscribeOn(AndroidSchedulers.mainThread()) - .observeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - - override fun onError(exception: Throwable) { - trySend(Resource.Error(exception.message.toString())) - } - - override fun onNext(response: PostClientsClientIdResponse) { - trySend(Resource.Success(response)) - } - }) - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = activateRepository.activateClient(clientId, clientPayload) + emit(Resource.Success(response)) } catch (exception: Exception) { - trySend(Resource.Error(exception.message.toString())) + emit(Resource.Error(exception.message.toString())) } } -} +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteDataTableEntryUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteDataTableEntryUseCase.kt index 7b4a7ba477..21b38206b7 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteDataTableEntryUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteDataTableEntryUseCase.kt @@ -1,52 +1,26 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.DataTableDataRepository -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import org.apache.fineract.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow +import org.openapitools.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse import javax.inject.Inject class DeleteDataTableEntryUseCase @Inject constructor(private val repository: DataTableDataRepository) { suspend operator fun invoke( - table: String?, + table: String, entity: Int, - rowId: Int, - ): Flow> = callbackFlow { + rowId: Int + ): Flow> = flow { try { - trySend(Resource.Loading()) - repository.deleteDataTableEntry(table, entity, rowId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : - Subscriber() { - override fun onCompleted() {} - - override fun onError(exception: Throwable) { - trySend(Resource.Error(exception.message.toString())) - } - - override fun onNext(response: DeleteDataTablesDatatableAppTableIdDatatableIdResponse) { - trySend(Resource.Success(response)) - } - }) - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = repository.deleteDataTableEntry(table, entity, rowId) + emit(Resource.Success(response)) } catch (exception: Exception) { - trySend(Resource.Error(exception.message.toString())) + emit(Resource.Error(exception.message.toString())) } } -} + +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteIdentifierUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteIdentifierUseCase.kt index 033f1cc8ce..f8b31ad02c 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteIdentifierUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/DeleteIdentifierUseCase.kt @@ -1,52 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.ClientIdentifiersRepository -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow +import org.openapitools.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse import javax.inject.Inject class DeleteIdentifierUseCase @Inject constructor(private val repository: ClientIdentifiersRepository) { suspend operator fun invoke( clientId: Int, - identifierId: Int, - ): Flow> = callbackFlow { + identifierId: Int + ): Flow> = flow { try { - trySend(Resource.Loading()) - repository.deleteClientIdentifier(clientId = clientId, identifierId = identifierId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : - Subscriber() { - override fun onCompleted() {} - - override fun onError(exception: Throwable) { - trySend(Resource.Error(exception.message.toString())) - } - - override fun onNext(response: DeleteClientsClientIdIdentifiersIdentifierIdResponse?) { - trySend(Resource.Success(response)) - } - }) - - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = + repository.deleteClientIdentifier(clientId = clientId, identifierId = identifierId) + emit(Resource.Success(response)) } catch (exception: Exception) { - trySend(Resource.Error(exception.message.toString())) + emit(Resource.Error(exception.message.toString())) } } -} +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientDetailsUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientDetailsUseCase.kt index 9919deeb4b..a0bf14b288 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientDetailsUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientDetailsUseCase.kt @@ -1,24 +1,13 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.ClientDetailsRepository import com.mifos.core.objects.zipmodels.ClientAndClientAccounts -import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import rx.Observable -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.withContext import javax.inject.Inject /** @@ -27,34 +16,24 @@ import javax.inject.Inject class GetClientDetailsUseCase @Inject constructor(private val repository: ClientDetailsRepository) { - operator fun invoke(clientId: Int): Flow> = callbackFlow { + operator fun invoke(clientId: Int): Flow> = flow { try { - trySend(Resource.Loading()) + emit(Resource.Loading()) + val clientAndClientAccounts = withContext(Dispatchers.IO) { + val clientAccountsDeferred = async { repository.getClientAccounts(clientId) } + val clientDeferred = async { repository.getClient(clientId) } - Observable.zip( - repository.getClientAccounts(clientId), - repository.getClient(clientId), - ) { clientAccounts, client -> - val clientAndClientAccounts = ClientAndClientAccounts() - clientAndClientAccounts.client = client - clientAndClientAccounts.clientAccounts = clientAccounts - clientAndClientAccounts - } - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - trySend(Resource.Error(e.message.toString())) - } + val clientAccounts = clientAccountsDeferred.await() + val client = clientDeferred.await() - override fun onNext(clientAndClientAccounts: ClientAndClientAccounts) { - trySend(Resource.Success(clientAndClientAccounts)) - } - }) - awaitClose { channel.close() } + ClientAndClientAccounts().apply { + this.client = client + this.clientAccounts = clientAccounts + } + } + emit(Resource.Success(clientAndClientAccounts)) } catch (e: Exception) { - trySend(Resource.Error(e.message.toString())) + emit(Resource.Error(e.message.toString())) } } -} +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifierTemplateUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifierTemplateUseCase.kt index e9dcf3d72b..36c5650752 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifierTemplateUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifierTemplateUseCase.kt @@ -12,36 +12,19 @@ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.ClientIdentifierDialogRepository import com.mifos.core.objects.noncore.IdentifierTemplate -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow import javax.inject.Inject class GetClientIdentifierTemplateUseCase @Inject constructor(private val repository: ClientIdentifierDialogRepository) { - suspend operator fun invoke(clientId: Int): Flow> = callbackFlow { + suspend operator fun invoke(clientId: Int): Flow> = flow { try { - trySend(Resource.Loading()) - repository.getClientIdentifierTemplate(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - - override fun onError(exception: Throwable) { - trySend(Resource.Error(exception.message.toString())) - } - - override fun onNext(response: IdentifierTemplate) { - trySend(Resource.Success(response)) - } - }) - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = repository.getClientIdentifierTemplate(clientId) + emit(Resource.Success(response)) } catch (exception: Exception) { - trySend(Resource.Error(exception.message.toString())) + emit(Resource.Error(exception.message.toString())) } } } diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifiersUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifiersUseCase.kt index 8c3d499958..49dfcb21db 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifiersUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetClientIdentifiersUseCase.kt @@ -1,48 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.ClientIdentifiersRepository import com.mifos.core.objects.noncore.Identifier -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow import javax.inject.Inject class GetClientIdentifiersUseCase @Inject constructor(private val clientIdentifiersRepository: ClientIdentifiersRepository) { - suspend operator fun invoke(clientId: Int): Flow>> = callbackFlow { + suspend operator fun invoke(clientId: Int): Flow>> = flow { try { - trySend(Resource.Loading()) - clientIdentifiersRepository.getClientIdentifiers(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - - override fun onError(exception: Throwable) { - trySend(Resource.Error(exception.message.toString())) - } - - override fun onNext(identifiers: List) { - trySend(Resource.Success(identifiers)) - } - }) - - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = clientIdentifiersRepository.getClientIdentifiers(clientId) + emit(Resource.Success(response)) } catch (exception: Exception) { - trySend(Resource.Error(exception.message.toString())) + emit(Resource.Error(exception.message.toString())) } } -} +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetGroupOfficesUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetGroupOfficesUseCase.kt index 3019238f51..9e48f1cd6a 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetGroupOfficesUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetGroupOfficesUseCase.kt @@ -1,23 +1,10 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.domain.useCases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.CreateNewGroupRepository import com.mifos.core.objects.organisation.Office -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow import javax.inject.Inject /** @@ -26,28 +13,13 @@ import javax.inject.Inject class GetGroupOfficesUseCase @Inject constructor(private val repository: CreateNewGroupRepository) { - suspend operator fun invoke(): Flow>> = callbackFlow { + suspend operator fun invoke(): Flow>> = flow { try { - trySend(Resource.Loading()) - - repository.offices() - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { } - - override fun onError(e: Throwable) { - trySend(Resource.Error(e.message.toString())) - } - - override fun onNext(offices: List) { - trySend(Resource.Success(offices)) - } - }) - - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = repository.offices() + emit(Resource.Success(response)) } catch (e: Exception) { - trySend(Resource.Error(e.message.toString())) + emit(Resource.Error(e.message.toString())) } } -} +} \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetStaffInOfficeForCreateNewClientUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetStaffInOfficeForCreateNewClientUseCase.kt index fb5a833832..0ab3aec137 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/GetStaffInOfficeForCreateNewClientUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/GetStaffInOfficeForCreateNewClientUseCase.kt @@ -1,23 +1,10 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ -package com.mifos.core.domain.useCases +package com.mifos.core.domain.use_cases import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.CreateNewClientRepository import com.mifos.core.objects.organisation.Staff -import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.callbackFlow -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers +import kotlinx.coroutines.flow.flow import javax.inject.Inject /** @@ -26,28 +13,13 @@ import javax.inject.Inject class GetStaffInOfficeForCreateNewClientUseCase @Inject constructor(private val repository: CreateNewClientRepository) { suspend operator fun invoke(officeId: Int): Flow>> = - callbackFlow { + flow { try { - trySend(Resource.Loading()) - - repository.getStaffInOffice(officeId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - trySend(Resource.Error(e.message.toString())) - } - - override fun onNext(staffList: List) { - trySend(Resource.Success(staffList)) - } - }) - - awaitClose { channel.close() } + emit(Resource.Loading()) + val response = repository.getStaffInOffice(officeId) + emit(Resource.Success(response)) } catch (e: Exception) { - trySend(Resource.Error(e.message.toString())) + emit(Resource.Error(e.message.toString())) } } } diff --git a/core/domain/src/main/java/com/mifos/core/domain/useCases/LoginUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/useCases/LoginUseCase.kt index e00bc05977..8248470eb4 100644 --- a/core/domain/src/main/java/com/mifos/core/domain/useCases/LoginUseCase.kt +++ b/core/domain/src/main/java/com/mifos/core/domain/useCases/LoginUseCase.kt @@ -13,13 +13,7 @@ import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.LoginRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.suspendCancellableCoroutine -import org.apache.fineract.client.models.PostAuthenticationResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException +import org.openapitools.client.models.PostAuthenticationResponse /** * Created by Aditya Gupta on 11/02/24. @@ -33,31 +27,11 @@ class LoginUseCase(private val loginRepository: LoginRepository) { ): Flow> = flow { try { emit(Resource.Loading()) - val result = login(username, password) - emit(result) + val result = loginRepository.login(username, password) + emit(Resource.Success(result)) } catch (e: Exception) { emit(Resource.Error(e.message.toString())) } } - suspend fun login(username: String, password: String): Resource { - return suspendCancellableCoroutine { continuation -> - loginRepository.login(username, password) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onNext(user: PostAuthenticationResponse) { - continuation.resume(Resource.Success(user)) - } - - override fun onCompleted() { - // No operation needed - } - - override fun onError(e: Throwable) { - continuation.resumeWithException(e) - } - }) - } - } } diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerAuth.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerAuth.kt index cf15d55095..e728337b99 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerAuth.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerAuth.kt @@ -9,10 +9,9 @@ */ package com.mifos.core.network.datamanager -import org.apache.fineract.client.models.PostAuthenticationRequest -import org.apache.fineract.client.models.PostAuthenticationResponse import org.mifos.core.apimanager.BaseApiManager -import rx.Observable +import org.openapitools.client.models.PostAuthenticationRequest +import org.openapitools.client.models.PostAuthenticationResponse import javax.inject.Inject import javax.inject.Singleton @@ -26,11 +25,8 @@ class DataManagerAuth @Inject constructor(private val baseApiManager: BaseApiMan * @param password Password * @return Basic OAuth */ - fun login(username: String, password: String): Observable { - val body = PostAuthenticationRequest().apply { - this.username = username - this.password = password - } + suspend fun login(username: String, password: String): PostAuthenticationResponse { + val body = PostAuthenticationRequest(username = username, password = password) return baseApiManager.getAuthApi().authenticate(body, true) } } diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt index f1f5712b44..2f76d0adbb 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.datamanager import com.mifos.core.data.CenterPayload @@ -21,8 +12,8 @@ import com.mifos.core.objects.group.Center import com.mifos.core.objects.group.CenterWithAssociations import com.mifos.core.objects.organisation.Office import com.mifos.core.objects.response.SaveResponse -import org.apache.fineract.client.models.PostCentersCenterIdRequest -import org.apache.fineract.client.models.PostCentersCenterIdResponse +import org.openapitools.client.models.PostCentersCenterIdRequest +import org.openapitools.client.models.PostCentersCenterIdResponse import rx.Observable import javax.inject.Inject import javax.inject.Singleton @@ -38,7 +29,7 @@ class DataManagerCenter @Inject constructor( val mBaseApiManager: BaseApiManager, private val mDatabaseHelperCenter: DatabaseHelperCenter, private val baseApiManager: org.mifos.core.apimanager.BaseApiManager, - private val prefManager: com.mifos.core.datastore.PrefManager, + private val prefManager: com.mifos.core.datastore.PrefManager ) { /** * This Method sending the Request to REST API if UserStatus is 0 and @@ -56,24 +47,31 @@ class DataManagerCenter @Inject constructor( * @param limit Maximum Number of centers will come in response * @return Centers List page from offset to max Limit */ - fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable> { - return when (prefManager.userStatus) { - false -> baseApiManager.getCenterApi() + suspend fun getCenters(paged: Boolean, offset: Int, limit: Int): Page
{ + return baseApiManager.getCenterApi() .retrieveAll23( null, null, null, null, null, paged, - offset, limit, null, null, null, null, null, - ).map(GetCentersResponseMapper::mapFromEntity) - - true -> { - /** - * Return All Centers List from DatabaseHelperCenter only one time. - * If offset is zero this means this is first request and - * return all centers from DatabaseHelperCenter - */ - if (offset == 0) mDatabaseHelperCenter.readAllCenters() else Observable.just(Page()) - } + offset, limit, null, null, null, null, null + ).let(GetCentersResponseMapper::mapFromEntity) } - } +// suspend fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable> { +// return when (prefManager.userStatus) { +// false -> baseApiManager.getCenterApi() +// .retrieveAll23( +// null, null, null, null, null, paged, +// offset, limit, null, null, null, null, null +// ).map(GetCentersResponseMapper::mapFromEntity) +// +// true -> { +// /** +// * Return All Centers List from DatabaseHelperCenter only one time. +// * If offset is zero this means this is first request and +// * return all centers from DatabaseHelperCenter +// */ +// if (offset == 0) mDatabaseHelperCenter.readAllCenters() else Observable.just(Page()) +// } +// } +// } /** * This method save the single Center in Database. @@ -97,7 +95,7 @@ class DataManagerCenter @Inject constructor( .concatMap { centerAccounts -> mDatabaseHelperCenter.saveCenterAccounts( centerAccounts, - centerId, + centerId ) } } @@ -152,15 +150,16 @@ class DataManagerCenter @Inject constructor( val allDatabaseCenters: Observable> get() = mDatabaseHelperCenter.readAllCenters() - val offices: Observable> - get() = baseApiManager.getOfficeApi().retrieveOffices(null, null, null) - .map(GetOfficeResponseMapper::mapFromEntityList) + suspend fun offices(): List { + return baseApiManager.getOfficeApi().retrieveOffices(null, null, null) + .map(GetOfficeResponseMapper::mapFromEntity) + } /** * This method loading the all CenterPayloads from the Database. * * @return List - */ + */ val allDatabaseCenterPayload: Observable> get() = mDatabaseHelperCenter.readAllCenterPayload() @@ -192,18 +191,17 @@ class DataManagerCenter @Inject constructor( * @param centerId * @return GenericResponse */ - fun activateCenter( + suspend fun activateCenter( centerId: Int, - activatePayload: ActivatePayload?, - ): Observable { + activatePayload: ActivatePayload? + ): PostCentersCenterIdResponse { return baseApiManager.getCenterApi().activate2( centerId.toLong(), - PostCentersCenterIdRequest().apply { - closureDate = activatePayload?.activationDate - dateFormat = activatePayload?.dateFormat + PostCentersCenterIdRequest( + closureDate = activatePayload?.activationDate, + dateFormat = activatePayload?.dateFormat, locale = activatePayload?.locale - }, - "activate", + ), "activate" ) } -} +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerClient.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerClient.kt index 8ecc258a11..b13d5a5f66 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerClient.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerClient.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.datamanager import com.mifos.core.databasehelper.DatabaseHelperClient @@ -30,9 +21,9 @@ import com.mifos.core.objects.noncore.IdentifierTemplate import com.mifos.core.objects.templates.clients.ClientsTemplate import okhttp3.MultipartBody import okhttp3.ResponseBody -import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse -import org.apache.fineract.client.models.PostClientsClientIdRequest -import org.apache.fineract.client.models.PostClientsClientIdResponse +import org.openapitools.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse +import org.openapitools.client.models.PostClientsClientIdRequest +import org.openapitools.client.models.PostClientsClientIdResponse import rx.Observable import javax.inject.Inject import javax.inject.Singleton @@ -47,7 +38,7 @@ class DataManagerClient @Inject constructor( val mBaseApiManager: BaseApiManager, private val mDatabaseHelperClient: DatabaseHelperClient, private val baseApiManager: org.mifos.core.apimanager.BaseApiManager, - private val prefManager: com.mifos.core.datastore.PrefManager, + private val prefManager: com.mifos.core.datastore.PrefManager ) { /** * This Method sending the Request to REST API if UserStatus is 0 and @@ -65,25 +56,33 @@ class DataManagerClient @Inject constructor( * @param limit Maximum Number of clients will come in response * @return Client List from offset to max Limit */ - fun getAllClients(offset: Int, limit: Int): Observable> { - return when (prefManager.userStatus) { - false -> baseApiManager.getClientsApi().retrieveAll21( - null, null, null, - null, null, null, - null, null, offset, - limit, null, null, null, - ).map(GetClientResponseMapper::mapFromEntity) - - true -> { - /** - * Return All Clients List from DatabaseHelperClient only one time. - * If offset is zero this means this is first request and - * return all clients from DatabaseHelperClient - */ - if (offset == 0) mDatabaseHelperClient.readAllClients() else Observable.just(Page()) - } - } + suspend fun getAllClients(offset: Int, limit: Int): Page { + return baseApiManager.getClientsApi().retrieveAll21( + null, null, null, + null, null, null, + null, offset, + limit, null, null, null + ).let(GetClientResponseMapper::mapFromEntity) } +// fun getAllClients(offset: Int, limit: Int): Observable> { +// return when (prefManager.userStatus) { +// false -> baseApiManager.getClientsApi().retrieveAll21( +// null, null, null, +// null, null, null, +// null, null, offset, +// limit, null, null, null +// ).map(GetClientResponseMapper::mapFromEntity) +// +// true -> { +// /** +// * Return All Clients List from DatabaseHelperClient only one time. +// * If offset is zero this means this is first request and +// * return all clients from DatabaseHelperClient +// */ +// if (offset == 0) mDatabaseHelperClient.readAllClients() else Observable.just(Page()) +// } +// } +// } /** * This Method Request to the DatabaseHelperClient and DatabaseHelperClient Read the All @@ -100,18 +99,21 @@ class DataManagerClient @Inject constructor( * @param clientId for Query in database or REST API request. * @return The Client Details */ - fun getClient(clientId: Int): Observable { - return when (prefManager.userStatus) { - false -> mBaseApiManager.clientsApi.getClient(clientId) - .concatMap { client -> Observable.just(client) } - - true -> - /** - * Return Clients from DatabaseHelperClient only one time. - */ - mDatabaseHelperClient.getClient(clientId) - } + suspend fun getClient(clientId: Int): Client { + return mBaseApiManager.clientsApi.getClient(clientId) } +// fun getClient(clientId: Int): Observable { +// return when (prefManager.userStatus) { +// false -> mBaseApiManager.clientsApi.getClient(clientId) +// .concatMap { client -> Observable.just(client) } +// +// true -> +// /** +// * Return Clients from DatabaseHelperClient only one time. +// */ +// mDatabaseHelperClient.getClient(clientId) +// } +// } fun syncClientInDatabase(client: Client): Observable { return mDatabaseHelperClient.saveClient(client) @@ -128,18 +130,22 @@ class DataManagerClient @Inject constructor( * @param clientId Client Id * @return All Clients Account, Like Savings, Loan etc Accounts. */ - fun getClientAccounts(clientId: Int): Observable { - return when (prefManager.userStatus) { - false -> baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong()) - .map(GetClientsClientIdAccountMapper::mapFromEntity) - - true -> - /** - * Return Clients from DatabaseHelperClient only one time. - */ - mDatabaseHelperClient.realClientAccounts(clientId) - } + suspend fun getClientAccounts(clientId: Int): ClientAccounts { + return baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong()) + .let(GetClientsClientIdAccountMapper::mapFromEntity) } +// fun getClientAccounts(clientId: Int): Observable { +// return when (prefManager.userStatus) { +// false -> baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong()) +// .map(GetClientsClientIdAccountMapper::mapFromEntity) +// +// true -> +// /** +// * Return Clients from DatabaseHelperClient only one time. +// */ +// mDatabaseHelperClient.realClientAccounts(clientId) +// } +// } /** * This Method Fetching the Client Accounts (Loan, saving, etc Accounts ) from REST API @@ -149,16 +155,20 @@ class DataManagerClient @Inject constructor( * @param clientId Client Id * @return ClientAccounts */ - fun syncClientAccounts(clientId: Int): Observable { + suspend fun syncClientAccounts(clientId: Int): ClientAccounts { return baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong()) - .map(GetClientsClientIdAccountMapper::mapFromEntity) - .concatMap { clientAccounts -> - mDatabaseHelperClient.saveClientAccounts( - clientAccounts, - clientId, - ) - } + .let(GetClientsClientIdAccountMapper::mapFromEntity) } +// fun syncClientAccounts(clientId: Int): Observable { +// return baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong()) +// .map(GetClientsClientIdAccountMapper::mapFromEntity) +// .concatMap { clientAccounts -> +// mDatabaseHelperClient.saveClientAccounts( +// clientAccounts, +// clientId +// ) +// } +// } /** * This Method for removing the Client Image from his profile on server @@ -198,13 +208,12 @@ class DataManagerClient @Inject constructor( */ val clientTemplate: Observable get() = when (prefManager.userStatus) { - false -> - mBaseApiManager.clientsApi.clientTemplate - .concatMap { clientsTemplate -> - mDatabaseHelperClient.saveClientTemplate( - clientsTemplate, - ) - } + false -> mBaseApiManager.clientsApi.clientTemplate + .concatMap { clientsTemplate -> + mDatabaseHelperClient.saveClientTemplate( + clientsTemplate + ) + } true -> /** @@ -256,7 +265,7 @@ class DataManagerClient @Inject constructor( */ fun deleteAndUpdatePayloads( id: Int, - clientCreationTIme: Long, + clientCreationTIme: Long ): Observable> { return mDatabaseHelperClient.deleteAndUpdatePayloads(id, clientCreationTIme) } @@ -276,10 +285,10 @@ class DataManagerClient @Inject constructor( * * @param clientId Client Id * @return List - */ - fun getClientIdentifiers(clientId: Int): Observable> { + */ + suspend fun getClientIdentifiers(clientId: Int): List { return baseApiManager.getClient().clientIdentifiers.retrieveAllClientIdentifiers(clientId.toLong()) - .map(IdentifierMapper::mapFromEntityList) + .map(IdentifierMapper::mapFromEntity) } /** @@ -290,8 +299,7 @@ class DataManagerClient @Inject constructor( * @return IdentifierCreationResponse */ suspend fun createClientIdentifier( - clientId: Int, - identifierPayload: IdentifierPayload, + clientId: Int, identifierPayload: IdentifierPayload ): IdentifierCreationResponse { return mBaseApiManager.clientsApi.createClientIdentifier(clientId, identifierPayload) } @@ -302,9 +310,9 @@ class DataManagerClient @Inject constructor( * @param clientId Client Id * @return IdentifierTemplate */ - fun getClientIdentifierTemplate(clientId: Int): Observable { + suspend fun getClientIdentifierTemplate(clientId: Int): IdentifierTemplate { return baseApiManager.getClient().clientIdentifiers.newClientIdentifierDetails(clientId.toLong()) - .map(GetIdentifiersTemplateMapper::mapFromEntity) + .let(GetIdentifiersTemplateMapper::mapFromEntity) } /** @@ -314,13 +322,13 @@ class DataManagerClient @Inject constructor( * @param identifierId Identifier Id * @return GenericResponse */ - fun deleteClientIdentifier( + suspend fun deleteClientIdentifier( clientId: Int, - identifierId: Int, - ): Observable { + identifierId: Int + ): DeleteClientsClientIdIdentifiersIdentifierIdResponse { return baseApiManager.getClient().clientIdentifiers.deleteClientIdentifier( clientId.toLong(), - identifierId.toLong(), + identifierId.toLong() ) } @@ -344,7 +352,7 @@ class DataManagerClient @Inject constructor( */ suspend fun addClientPinpointLocation( clientId: Int, - address: ClientAddressRequest?, + address: ClientAddressRequest? ): GenericResponse { return mBaseApiManager.clientsApi.addClientPinpointLocation(clientId, address) } @@ -358,7 +366,7 @@ class DataManagerClient @Inject constructor( */ suspend fun deleteClientAddressPinpointLocation( apptableId: Int, - datatableId: Int, + datatableId: Int ): GenericResponse { return mBaseApiManager.clientsApi .deleteClientPinpointLocation(apptableId, datatableId) @@ -375,12 +383,10 @@ class DataManagerClient @Inject constructor( suspend fun updateClientPinpointLocation( apptableId: Int, datatableId: Int, - address: ClientAddressRequest?, + address: ClientAddressRequest? ): GenericResponse { return mBaseApiManager.clientsApi.updateClientPinpointLocation( - apptableId, - datatableId, - address, + apptableId, datatableId, address ) } @@ -390,18 +396,17 @@ class DataManagerClient @Inject constructor( * @param clientId * @return GenericResponse */ - fun activateClient( + suspend fun activateClient( clientId: Int, - clientActivate: ActivatePayload?, - ): Observable { + clientActivate: ActivatePayload? + ): PostClientsClientIdResponse { return baseApiManager.getClientsApi().activate1( clientId.toLong(), - PostClientsClientIdRequest().apply { - activationDate = clientActivate?.activationDate - dateFormat = clientActivate?.dateFormat + PostClientsClientIdRequest( + activationDate = clientActivate?.activationDate, + dateFormat = clientActivate?.dateFormat, locale = clientActivate?.locale - }, - "activate", + ), "activate" ) } -} +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerDataTable.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerDataTable.kt index db61c21d60..c34552b24a 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerDataTable.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerDataTable.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.datamanager import com.google.gson.JsonArray @@ -16,7 +7,7 @@ import com.mifos.core.network.GenericResponse import com.mifos.core.network.mappers.dataTable.GetDataTablesResponseMapper import com.mifos.core.objects.noncore.DataTable import com.mifos.core.objects.user.UserLocation -import org.apache.fineract.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse +import org.openapitools.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse import rx.Observable import javax.inject.Inject import javax.inject.Singleton @@ -31,7 +22,7 @@ import javax.inject.Singleton class DataManagerDataTable @Inject constructor( val mBaseApiManager: BaseApiManager, val mDatabaseHelperDataTable: DatabaseHelperDataTable, - private val baseApiManager: org.mifos.core.apimanager.BaseApiManager, + private val baseApiManager: org.mifos.core.apimanager.BaseApiManager ) { /** * This Method Request the REST API of Datatable and In response give the List of DataTable @@ -41,10 +32,10 @@ class DataManagerDataTable @Inject constructor( * 3. m_loan * @param tableName DataTable Name * @return List - */ - fun getDataTable(tableName: String?): Observable> { + */ + suspend fun getDataTable(tableName: String?): List { return baseApiManager.getDataTableApi().getDatatables(tableName).map( - GetDataTablesResponseMapper::mapFromEntityList, + GetDataTablesResponseMapper::mapFromEntity ) } @@ -53,21 +44,22 @@ class DataManagerDataTable @Inject constructor( } suspend fun addDataTableEntry( - table: String, - entityId: Int, - payload: Map, + table: String, entityId: Int, payload: Map ): GenericResponse { return mBaseApiManager.dataTableApi .createEntryInDataTable(table, entityId, payload) } - fun deleteDataTableEntry( - table: String?, + suspend fun deleteDataTableEntry( + table: String, entity: Int, - rowId: Int, - ): Observable { - return baseApiManager.getDataTableApi() - .deleteDatatableEntries1(table, entity.toLong(), rowId.toLong()) + rowId: Int + ): DeleteDataTablesDatatableAppTableIdDatatableIdResponse { + return baseApiManager.getDataTableApi().deleteDatatableEntry( + datatable = table, + apptableId = entity.toLong(), + datatableId = rowId.toLong() + ) } /** @@ -79,7 +71,7 @@ class DataManagerDataTable @Inject constructor( */ fun addUserPathTracking( userId: Int, - userLocation: UserLocation?, + userLocation: UserLocation? ): Observable { return mBaseApiManager.dataTableApi.addUserPathTracking(userId, userLocation) } @@ -89,8 +81,8 @@ class DataManagerDataTable @Inject constructor( * * @param userId UserId Id * @return List - */ + */ suspend fun getUserPathTracking(userId: Int): List { return mBaseApiManager.dataTableApi.getUserPathTracking(userId) } -} +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerGroups.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerGroups.kt index 0ce1daa2fe..bb005550ed 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerGroups.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerGroups.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.datamanager import com.mifos.core.databasehelper.DatabaseHelperClient @@ -37,7 +28,7 @@ class DataManagerGroups @Inject constructor( private val mDatabaseHelperGroups: DatabaseHelperGroups, private val mDatabaseHelperClient: DatabaseHelperClient, private val baseApiManager: org.mifos.core.apimanager.BaseApiManager, - private val prefManager: com.mifos.core.datastore.PrefManager, + private val prefManager: com.mifos.core.datastore.PrefManager ) { /** * This Method sending the Request to REST API if UserStatus is 0 and @@ -55,41 +46,56 @@ class DataManagerGroups @Inject constructor( * @param limit Maximum Number of clients will come in response * @return Groups List page from offset to max Limit */ - fun getGroups(paged: Boolean, offset: Int, limit: Int): Observable> { - return when (prefManager.userStatus) { - false -> baseApiManager.getGroupApi().retrieveAll24( - null, - null, - null, - null, - null, - paged, - offset, - limit, - null, - null, - null, - ).map(GetGroupsResponseMapper::mapFromEntity) - - true -> { - /** - * offset : is the value from which position we want to fetch the list, It means - * if offset is 0 and User is in the Offline Mode So fetch all groups - * Return All Groups List from DatabaseHelperGroups only one time. - * If offset is zero this means this is first request and - * return all clients from DatabaseHelperClient - */ - mDatabaseHelperGroups.readAllGroups(offset, limit) - } - } + suspend fun getGroups(paged: Boolean, offset: Int, limit: Int): Page { + return baseApiManager.getGroupApi().retrieveAll24( + null, + null, + null, + null, + null, + paged, + offset, + limit, + null, + null, + null + ).let(GetGroupsResponseMapper::mapFromEntity) } +// suspend fun getGroups(paged: Boolean, offset: Int, limit: Int): Observable> { +// return when (prefManager.userStatus) { +// false -> baseApiManager.getGroupApi().retrieveAll24( +// null, +// null, +// null, +// null, +// null, +// paged, +// offset, +// limit, +// null, +// null, +// null +// ).map(GetGroupsResponseMapper::mapFromEntity) +// +// true -> { +// /** +// * offset : is the value from which position we want to fetch the list, It means +// * if offset is 0 and User is in the Offline Mode So fetch all groups +// * Return All Groups List from DatabaseHelperGroups only one time. +// * If offset is zero this means this is first request and +// * return all clients from DatabaseHelperClient +// */ +// mDatabaseHelperGroups.readAllGroups(offset, limit) +// } +// } +// } /** * This method call the DatabaseHelperGroups Helper and mDatabaseHelperGroups.readAllGroups() * read the all Groups from the Database Group table and returns the Page. * * @return Page - */ + */ val databaseGroups: Observable> get() = mDatabaseHelperGroups.readAllGroups() @@ -167,7 +173,7 @@ class DataManagerGroups @Inject constructor( .concatMap { groupAccounts -> mDatabaseHelperGroups.saveGroupAccounts( groupAccounts, - groupId, + groupId ) } } @@ -194,7 +200,7 @@ class DataManagerGroups @Inject constructor( * This method loading the all GroupPayloads from the Database. * * @return List - */ + */ val allDatabaseGroupPayload: Observable> get() = mDatabaseHelperGroups.realAllGroupPayload() @@ -228,8 +234,8 @@ class DataManagerGroups @Inject constructor( */ fun activateGroup( groupId: Int, - activatePayload: ActivatePayload?, + activatePayload: ActivatePayload? ): Observable { return mBaseApiManager.groupApi.activateGroup(groupId, activatePayload) } -} +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerOffices.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerOffices.kt index d834d25044..e455967f9a 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerOffices.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerOffices.kt @@ -1,19 +1,9 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.datamanager import com.mifos.core.databasehelper.DatabaseHelperOffices import com.mifos.core.network.BaseApiManager import com.mifos.core.network.mappers.offices.GetOfficeResponseMapper import com.mifos.core.objects.organisation.Office -import rx.Observable import javax.inject.Inject import javax.inject.Singleton @@ -29,23 +19,28 @@ class DataManagerOffices @Inject constructor( val mBaseApiManager: BaseApiManager, private val mDatabaseHelperOffices: DatabaseHelperOffices, private val baseApiManager: org.mifos.core.apimanager.BaseApiManager, - private val prefManager: com.mifos.core.datastore.PrefManager, + private val prefManager: com.mifos.core.datastore.PrefManager ) { /** * return all List of Offices from DatabaseHelperOffices */ - val offices: Observable> - get() = when (prefManager.userStatus) { - false -> baseApiManager.getOfficeApi().retrieveOffices(null, null, null) - .map(GetOfficeResponseMapper::mapFromEntityList) - - true -> - /** - * return all List of Offices from DatabaseHelperOffices - */ - /** - * return all List of Offices from DatabaseHelperOffices - */ - mDatabaseHelperOffices.readAllOffices() - } -} + suspend fun offices(): List { + return baseApiManager.getOfficeApi().retrieveOffices(null, null, null).map( + GetOfficeResponseMapper::mapFromEntity + ) + } +// val offices: Observable> +// get() = when (prefManager.userStatus) { +// false -> baseApiManager.getOfficeApi().retrieveOffices(null, null, null) +// .map(GetOfficeResponseMapper::mapFromEntityList) +// +// true -> +// /** +// * return all List of Offices from DatabaseHelperOffices +// */ +// /** +// * return all List of Offices from DatabaseHelperOffices +// */ +// mDatabaseHelperOffices.readAllOffices() +// } +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerStaff.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerStaff.kt index b52fcb761c..317d3b1938 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerStaff.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerStaff.kt @@ -1,19 +1,9 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.datamanager import com.mifos.core.databasehelper.DatabaseHelperStaff import com.mifos.core.network.BaseApiManager import com.mifos.core.network.mappers.staffs.StaffMapper import com.mifos.core.objects.organisation.Staff -import rx.Observable import javax.inject.Inject import javax.inject.Singleton @@ -25,22 +15,26 @@ class DataManagerStaff @Inject constructor( val mBaseApiManager: BaseApiManager, private val mDatabaseHelperStaff: DatabaseHelperStaff, private val baseApiManager: org.mifos.core.apimanager.BaseApiManager, - private val prefManager: com.mifos.core.datastore.PrefManager, + private val prefManager: com.mifos.core.datastore.PrefManager ) { /** * @param officeId * @return */ - fun getStaffInOffice(officeId: Int): Observable> { - return when (prefManager.userStatus) { - false -> baseApiManager.getStaffApi().retrieveAll16(officeId.toLong(), null, null, null) - .map(StaffMapper::mapFromEntityList) - - true -> - /** - * return all List of Staffs of Office from DatabaseHelperOffices - */ - mDatabaseHelperStaff.readAllStaffOffices(officeId) - } + suspend fun getStaffInOffice(officeId: Int): List { + return baseApiManager.getStaffApi().retrieveAll16(officeId.toLong(), null, null, null) + .map(StaffMapper::mapFromEntity) } -} +// fun getStaffInOffice(officeId: Int): Observable> { +// return when (prefManager.userStatus) { +// false -> baseApiManager.getStaffApi().retrieveAll16(officeId.toLong(), null, null, null) +// .map(StaffMapper::mapFromEntityList) +// +// true -> +// /** +// * return all List of Staffs of Office from DatabaseHelperOffices +// */ +// mDatabaseHelperStaff.readAllStaffOffices(officeId) +// } +// } +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanger/DataManagerAuth.kt b/core/network/src/main/java/com/mifos/core/network/datamanger/DataManagerAuth.kt index 184276cdfc..f10b32dd4f 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanger/DataManagerAuth.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanger/DataManagerAuth.kt @@ -9,10 +9,9 @@ */ package com.mifos.core.network.datamanger -import org.apache.fineract.client.models.PostAuthenticationRequest -import org.apache.fineract.client.models.PostAuthenticationResponse import org.mifos.core.apimanager.BaseApiManager -import rx.Observable +import org.openapitools.client.models.PostAuthenticationRequest +import org.openapitools.client.models.PostAuthenticationResponse import javax.inject.Inject import javax.inject.Singleton @@ -26,11 +25,8 @@ class DataManagerAuth @Inject constructor(private val baseApiManager: BaseApiMan * @param password Password * @return Basic OAuth */ - fun login(username: String, password: String): Observable { - val body = PostAuthenticationRequest().apply { - this.username = username - this.password = password - } + suspend fun login(username: String, password: String): PostAuthenticationResponse { + val body = PostAuthenticationRequest(username = username, password = password) return baseApiManager.getAuthApi().authenticate(body, true) } } diff --git a/core/network/src/main/java/com/mifos/core/network/di/NetworkModule.kt b/core/network/src/main/java/com/mifos/core/network/di/NetworkModule.kt index e99129c9dd..2b9db1561d 100644 --- a/core/network/src/main/java/com/mifos/core/network/di/NetworkModule.kt +++ b/core/network/src/main/java/com/mifos/core/network/di/NetworkModule.kt @@ -42,7 +42,7 @@ object NetworkModule { baseManager.createService( usernamePassword.first, usernamePassword.second, - prefManager.getServerConfig.getInstanceUrl(), + prefManager.getServerConfig.getInstanceUrl().dropLast(3), prefManager.getServerConfig.tenant, false, ) diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/centers/CenterMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/centers/CenterMapper.kt index be71919bed..c6e864f1ee 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/centers/CenterMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/centers/CenterMapper.kt @@ -11,22 +11,22 @@ package com.mifos.core.network.mappers.centers import com.mifos.core.objects.client.Status import com.mifos.core.objects.group.Center -import org.apache.fineract.client.models.GetCentersPageItems -import org.apache.fineract.client.models.GetCentersStatus import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetCentersPageItems +import org.openapitools.client.models.GetCentersStatus object CenterMapper : AbstractMapper() { override fun mapFromEntity(entity: GetCentersPageItems): Center { return Center().apply { - id = entity.id + id = entity.id?.toInt() active = entity.active name = entity.name officeName = entity.officeName - officeId = entity.officeId + officeId = entity.officeId?.toInt() hierarchy = entity.hierarchy status = Status().apply { - id = entity.status?.id!! + id = entity.status?.id!!.toInt() code = entity.status?.code value = entity.status?.description } @@ -34,18 +34,18 @@ object CenterMapper : AbstractMapper() { } override fun mapToEntity(domainModel: Center): GetCentersPageItems { - return GetCentersPageItems().apply { - id = domainModel.id - active = domainModel.active - name = domainModel.name - officeName = domainModel.officeName - officeId = domainModel.officeId - hierarchy = domainModel.hierarchy - status = GetCentersStatus().apply { - id = domainModel.status?.id!! - code = domainModel.status?.code + return GetCentersPageItems( + id = domainModel.id?.toLong(), + active = domainModel.active, + name = domainModel.name, + officeName = domainModel.officeName, + officeId = domainModel.officeId?.toLong(), + hierarchy = domainModel.hierarchy, + status = GetCentersStatus( + id = domainModel.status?.id?.toLong(), + code = domainModel.status?.code, description = domainModel.status?.value - } - } + ) + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/centers/GetCentersResponseMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/centers/GetCentersResponseMapper.kt index 44cafbf75a..f09b0539a2 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/centers/GetCentersResponseMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/centers/GetCentersResponseMapper.kt @@ -11,22 +11,22 @@ package com.mifos.core.network.mappers.centers import com.mifos.core.objects.client.Page import com.mifos.core.objects.group.Center -import org.apache.fineract.client.models.GetCentersResponse import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetCentersResponse object GetCentersResponseMapper : AbstractMapper>() { override fun mapFromEntity(entity: GetCentersResponse): Page
{ return Page
().apply { totalFilteredRecords = entity.totalFilteredRecords!! - pageItems = CenterMapper.mapFromEntityList(entity.pageItems!!) + pageItems = CenterMapper.mapFromEntityList(entity.pageItems!!.toList()) } } override fun mapToEntity(domainModel: Page
): GetCentersResponse { - return GetCentersResponse().apply { - totalFilteredRecords = domainModel.totalFilteredRecords - pageItems = CenterMapper.mapToEntityList(domainModel.pageItems) - } + return GetCentersResponse( + totalFilteredRecords = domainModel.totalFilteredRecords, + pageItems = CenterMapper.mapToEntityList(domainModel.pageItems).toSet() + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/clients/ClientMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/clients/ClientMapper.kt index 1a6f704df1..cb41e7e12b 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/clients/ClientMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/clients/ClientMapper.kt @@ -11,26 +11,26 @@ package com.mifos.core.network.mappers.clients import com.mifos.core.objects.client.Client import com.mifos.core.objects.client.Status -import org.apache.fineract.client.models.GetClientStatus -import org.apache.fineract.client.models.GetClientsPageItemsResponse import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetClientStatus +import org.openapitools.client.models.GetClientsPageItemsResponse object ClientMapper : AbstractMapper() { override fun mapFromEntity(entity: GetClientsPageItemsResponse): Client { return Client().apply { - id = entity.id!! + id = entity.id!!.toInt() accountNo = entity.accountNo fullname = entity.fullname firstname = entity.displayName!!.split(" ")[0] lastname = if (entity.displayName!!.split(" ").size >= 2) entity.displayName!!.split(" ")[1] else "" displayName = entity.displayName - officeId = entity.officeId!! + officeId = entity.officeId!!.toInt() officeName = entity.officeName active = entity.active!! status = Status().apply { - id = entity.status?.id!! + id = entity.status?.id!!.toInt() code = entity.status?.code value = entity.status?.description } @@ -38,19 +38,19 @@ object ClientMapper : AbstractMapper() { } override fun mapToEntity(domainModel: Client): GetClientsPageItemsResponse { - return GetClientsPageItemsResponse().apply { - id = domainModel.id - accountNo = domainModel.accountNo - fullname = domainModel.fullname - displayName = domainModel.displayName - officeId = domainModel.officeId - officeName = domainModel.officeName - active = domainModel.active - status = GetClientStatus().apply { - id = domainModel.status?.id - code = domainModel.status?.code + return GetClientsPageItemsResponse( + id = domainModel.id.toLong(), + accountNo = domainModel.accountNo, + fullname = domainModel.fullname, + displayName = domainModel.displayName, + officeId = domainModel.officeId.toLong(), + officeName = domainModel.officeName, + active = domainModel.active, + status = GetClientStatus( + id = domainModel.status?.id?.toLong(), + code = domainModel.status?.code, description = domainModel.status?.value - } - } + ) + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientResponseMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientResponseMapper.kt index 6834b9af4e..e0bc2caad3 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientResponseMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientResponseMapper.kt @@ -11,22 +11,22 @@ package com.mifos.core.network.mappers.clients import com.mifos.core.objects.client.Client import com.mifos.core.objects.client.Page -import org.apache.fineract.client.models.GetClientsResponse import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetClientsResponse object GetClientResponseMapper : AbstractMapper>() { override fun mapFromEntity(entity: GetClientsResponse): Page { return Page().apply { totalFilteredRecords = entity.totalFilteredRecords!! - pageItems = ClientMapper.mapFromEntityList(entity.pageItems!!) + pageItems = ClientMapper.mapFromEntityList(entity.pageItems!!.toList()) } } override fun mapToEntity(domainModel: Page): GetClientsResponse { - return GetClientsResponse().apply { - totalFilteredRecords = domainModel.totalFilteredRecords - pageItems = ClientMapper.mapToEntityList(domainModel.pageItems) - } + return GetClientsResponse( + totalFilteredRecords = domainModel.totalFilteredRecords, + pageItems = ClientMapper.mapToEntityList(domainModel.pageItems).toSet() + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientsClientIdAccountMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientsClientIdAccountMapper.kt index 78eb08a998..38501d81f8 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientsClientIdAccountMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetClientsClientIdAccountMapper.kt @@ -16,14 +16,15 @@ import com.mifos.core.objects.accounts.savings.Currency import com.mifos.core.objects.accounts.savings.DepositType import com.mifos.core.objects.accounts.savings.SavingsAccount import com.mifos.core.objects.accounts.savings.Status -import org.apache.fineract.client.models.GetClientsClientIdAccountsResponse -import org.apache.fineract.client.models.GetClientsLoanAccounts -import org.apache.fineract.client.models.GetClientsLoanAccountsStatus -import org.apache.fineract.client.models.GetClientsLoanAccountsType -import org.apache.fineract.client.models.GetClientsSavingsAccounts -import org.apache.fineract.client.models.GetClientsSavingsAccountsCurrency -import org.apache.fineract.client.models.GetClientsSavingsAccountsStatus import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetClientsClientIdAccountsResponse +import org.openapitools.client.models.GetClientsLoanAccounts +import org.openapitools.client.models.GetClientsLoanAccountsStatus +import org.openapitools.client.models.GetClientsLoanAccountsType +import org.openapitools.client.models.GetClientsSavingsAccounts +import org.openapitools.client.models.GetClientsSavingsAccountsCurrency +import org.openapitools.client.models.GetClientsSavingsAccountsDepositType +import org.openapitools.client.models.GetClientsSavingsAccountsStatus /** * Created by Aditya Gupta on 30/08/23. @@ -36,17 +37,17 @@ object GetClientsClientIdAccountMapper : return ClientAccounts().apply { savingsAccounts = entity.savingsAccounts?.map { SavingsAccount().apply { - id = it.id + id = it.id?.toInt() accountNo = it.accountNo - productId = it.productId + productId = it.productId?.toInt() productName = it.productName depositType = DepositType().apply { - id = it.depositType!!.id - code = it.depositType!!.code - value = it.depositType!!.value + id = it.depositType?.id?.toInt() + code = it.depositType?.code + value = it.depositType?.value } status = Status().apply { - id = it.status?.id + id = it.status?.id?.toInt() code = it.status?.code value = it.status?.value submittedAndPendingApproval = it.status?.submittedAndPendingApproval @@ -68,13 +69,13 @@ object GetClientsClientIdAccountMapper : }!! loanAccounts = entity.loanAccounts?.map { LoanAccount().apply { - id = it.id + id = it.id?.toInt() accountNo = it.accountNo externalId = it.externalId.toString() - productId = it.productId + productId = it.productId?.toInt() productName = it.productName status = com.mifos.core.objects.accounts.loan.Status().apply { - id = it.status?.id + id = it.status?.id?.toInt() code = it.status?.code value = it.status?.description pendingApproval = it.status?.pendingApproval @@ -87,7 +88,7 @@ object GetClientsClientIdAccountMapper : overpaid = it.status?.overpaid } loanType = LoanType().apply { - id = it.loanType?.id + id = it.loanType?.id?.toInt() code = it.loanType?.code value = it.loanType?.description } @@ -98,62 +99,66 @@ object GetClientsClientIdAccountMapper : } override fun mapToEntity(domainModel: ClientAccounts): GetClientsClientIdAccountsResponse { - return GetClientsClientIdAccountsResponse().apply { + return GetClientsClientIdAccountsResponse( savingsAccounts = domainModel.savingsAccounts.map { - GetClientsSavingsAccounts().apply { - id = it.id - accountNo = it.accountNo - productId = it.productId - productName = it.productName - status = GetClientsSavingsAccountsStatus().apply { - id = it.status?.id - code = it.status?.code - value = it.status?.value - submittedAndPendingApproval = it.status?.submittedAndPendingApproval - approved = it.status?.approved - rejected = it.status?.rejected - withdrawnByApplicant = it.status?.withdrawnByApplicant - active = it.status?.active + GetClientsSavingsAccounts( + id = it.id?.toLong(), + accountNo = it.accountNo, + productId = it.productId?.toLong(), + productName = it.productName, + depositType = GetClientsSavingsAccountsDepositType( + id = it.depositType?.id?.toLong(), + code = it.depositType?.code, + value = it.depositType?.value + ), + status = GetClientsSavingsAccountsStatus( + id = it.status?.id?.toLong(), + code = it.status?.code, + value = it.status?.value, + submittedAndPendingApproval = it.status?.submittedAndPendingApproval, + approved = it.status?.approved, + rejected = it.status?.rejected, + withdrawnByApplicant = it.status?.withdrawnByApplicant, + active = it.status?.active, closed = it.status?.closed - } - currency = GetClientsSavingsAccountsCurrency().apply { - code = it.currency!!.code - name = it.currency!!.name - nameCode = it.currency!!.nameCode - decimalPlaces = it.currency!!.decimalPlaces + ), + currency = GetClientsSavingsAccountsCurrency( + code = it.currency!!.code, + name = it.currency!!.name, + nameCode = it.currency!!.nameCode, + decimalPlaces = it.currency!!.decimalPlaces, displaySymbol = it.currency!!.displaySymbol - displayLabel = it.currency!!.displayLabel - } - } - } + ) + ) + }.toSet(), loanAccounts = domainModel.loanAccounts.map { - GetClientsLoanAccounts().apply { - id = it.id - accountNo = it.accountNo - externalId = it.externalId?.toInt() - productId = it.productId - productName = it.productName - status = GetClientsLoanAccountsStatus().apply { - id = it.status?.id - code = it.status?.code - description = it.status?.value - pendingApproval = it.status?.pendingApproval - waitingForDisbursal = it.status?.waitingForDisbursal - active = it.status?.active - closedObligationsMet = it.status?.closedObligationsMet - closedWrittenOff = it.status?.closedWrittenOff - closedRescheduled = it.status?.closedRescheduled - closed = it.status?.closed - overpaid = it.status?.overpaid - } - loanType = GetClientsLoanAccountsType().apply { - id = it.loanType?.id - code = it.loanType?.code + GetClientsLoanAccounts( + id = it.id?.toLong(), + accountNo = it.accountNo, + externalId = it.externalId, + productId = it.productId?.toLong(), + productName = it.productName, + status = GetClientsLoanAccountsStatus( + id = it.status?.id?.toLong(), + code = it.status?.code, + description = it.status?.value, + pendingApproval = it.status?.pendingApproval, + waitingForDisbursal = it.status?.waitingForDisbursal, + active = it.status?.active, + closedObligationsMet = it.status?.closedObligationsMet, + closedWrittenOff = it.status?.closedWrittenOff, + closedRescheduled = it.status?.closedRescheduled, + closed = it.status?.closed, + overpaid = it.status?.overpaid, + ), + loanType = GetClientsLoanAccountsType( + id = it.loanType?.id?.toLong(), + code = it.loanType?.code, description = it.loanType?.value - } + ), loanCycle = it.loanCycle - } - } - } + ) + }.toSet() + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetIdentifiersTemplateMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetIdentifiersTemplateMapper.kt index e1248412f4..40af78f54e 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetIdentifiersTemplateMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/clients/GetIdentifiersTemplateMapper.kt @@ -11,9 +11,9 @@ package com.mifos.core.network.mappers.clients import com.mifos.core.objects.noncore.DocumentType import com.mifos.core.objects.noncore.IdentifierTemplate -import org.apache.fineract.client.models.GetClientsAllowedDocumentTypes -import org.apache.fineract.client.models.GetClientsClientIdIdentifiersTemplateResponse import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetClientsAllowedDocumentTypes +import org.openapitools.client.models.GetClientsClientIdIdentifiersTemplateResponse /** * Created by Aditya Gupta on 30/08/23. @@ -26,7 +26,7 @@ object GetIdentifiersTemplateMapper : return IdentifierTemplate().apply { allowedDocumentTypes = entity.allowedDocumentTypes?.map { DocumentType().apply { - id = it.id + id = it.id?.toInt() name = it.name position = it.position } @@ -35,14 +35,14 @@ object GetIdentifiersTemplateMapper : } override fun mapToEntity(domainModel: IdentifierTemplate): GetClientsClientIdIdentifiersTemplateResponse { - return GetClientsClientIdIdentifiersTemplateResponse().apply { + return GetClientsClientIdIdentifiersTemplateResponse( allowedDocumentTypes = domainModel.allowedDocumentTypes?.map { - GetClientsAllowedDocumentTypes().apply { - id = it.id - name = it.name + GetClientsAllowedDocumentTypes( + id = it.id?.toLong(), + name = it.name, position = it.position - } - } - } + ) + }?.toSet() + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/clients/IdentifierMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/clients/IdentifierMapper.kt index 22b387c905..e59f7c4d02 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/clients/IdentifierMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/clients/IdentifierMapper.kt @@ -11,9 +11,9 @@ package com.mifos.core.network.mappers.clients import com.mifos.core.objects.noncore.DocumentType import com.mifos.core.objects.noncore.Identifier -import org.apache.fineract.client.models.GetClientsClientIdIdentifiersResponse -import org.apache.fineract.client.models.GetClientsDocumentType import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetClientsClientIdIdentifiersResponse +import org.openapitools.client.models.GetClientsDocumentType /** * Created by Aditya Gupta on 30/08/23. @@ -21,13 +21,13 @@ import org.mifos.core.data.AbstractMapper object IdentifierMapper : AbstractMapper() { override fun mapFromEntity(entity: GetClientsClientIdIdentifiersResponse): Identifier { return Identifier().apply { - id = entity.id - clientId = entity.clientId + id = entity.id?.toInt() + clientId = entity.clientId?.toInt() documentKey = entity.documentKey description = entity.description documentType = entity.documentType?.let { DocumentType().apply { - id = it.id + id = it.id?.toInt() name = it.name } } @@ -35,15 +35,17 @@ object IdentifierMapper : AbstractMapper>() { override fun mapFromEntity(entity: GetGroupsResponse): Page { return Page().apply { totalFilteredRecords = entity.totalFilteredRecords!! - pageItems = GroupMapper.mapFromEntityList(entity.pageItems!!) + pageItems = GroupMapper.mapFromEntityList(entity.pageItems!!.toList()) } } override fun mapToEntity(domainModel: Page): GetGroupsResponse { - return GetGroupsResponse().apply { - totalFilteredRecords = domainModel.totalFilteredRecords - pageItems = GroupMapper.mapToEntityList(domainModel.pageItems) - } + return GetGroupsResponse( + totalFilteredRecords = domainModel.totalFilteredRecords, + pageItems = GroupMapper.mapToEntityList(domainModel.pageItems).toSet() + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/groups/GroupMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/groups/GroupMapper.kt index c85da3dbd0..0fd30c20ae 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/groups/GroupMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/groups/GroupMapper.kt @@ -11,22 +11,22 @@ package com.mifos.core.network.mappers.groups import com.mifos.core.objects.client.Status import com.mifos.core.objects.group.Group -import org.apache.fineract.client.models.GetGroupsPageItems -import org.apache.fineract.client.models.GetGroupsStatus import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.GetGroupsPageItems +import org.openapitools.client.models.GetGroupsStatus object GroupMapper : AbstractMapper() { override fun mapFromEntity(entity: GetGroupsPageItems): Group { return Group().apply { - id = entity.id + id = entity.id?.toInt() name = entity.name active = entity.active - officeId = entity.officeId + officeId = entity.officeId?.toInt() officeName = entity.officeName hierarchy = entity.hierarchy status = Status().apply { - id = entity.status?.id!! + id = entity.status?.id!!.toInt() code = entity.status?.code value = entity.status?.description } @@ -34,18 +34,18 @@ object GroupMapper : AbstractMapper() { } override fun mapToEntity(domainModel: Group): GetGroupsPageItems { - return GetGroupsPageItems().apply { - id = domainModel.id - name = domainModel.name - active = domainModel.active - officeId = domainModel.officeId - officeName = domainModel.officeName - hierarchy = domainModel.hierarchy - status = GetGroupsStatus().apply { - id = domainModel.status?.id - code = domainModel.status?.code + return GetGroupsPageItems( + id = domainModel.id?.toLong(), + name = domainModel.name, + active = domainModel.active, + officeId = domainModel.officeId?.toLong(), + officeName = domainModel.officeName, + hierarchy = domainModel.hierarchy, + status = GetGroupsStatus( + id = domainModel.status?.id?.toLong(), + code = domainModel.status?.code, description = domainModel.status?.value - } - } + ) + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/offices/GetOfficeResponseMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/offices/GetOfficeResponseMapper.kt index ddb37ce2a7..3edfe21b1c 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/offices/GetOfficeResponseMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/offices/GetOfficeResponseMapper.kt @@ -1,18 +1,8 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.core.network.mappers.offices import com.mifos.core.objects.organisation.Office -import org.apache.fineract.client.models.GetOfficesResponse import org.mifos.core.data.AbstractMapper -import java.util.Date +import org.openapitools.client.models.GetOfficesResponse object GetOfficeResponseMapper : AbstractMapper() { @@ -21,26 +11,16 @@ object GetOfficeResponseMapper : AbstractMapper() { id = entity.id?.toInt() name = entity.name nameDecorated = entity.nameDecorated - openingDate = listOf( - entity.openingDate?.year, - entity.openingDate?.month, - entity.openingDate?.year, - ) externalId = entity.externalId } } override fun mapToEntity(domainModel: Office): GetOfficesResponse { - return GetOfficesResponse().apply { - id = domainModel.id?.toLong() - name = domainModel.name - nameDecorated = domainModel.nameDecorated - openingDate = Date().apply { - year = domainModel.openingDate[0]!! - month = domainModel.openingDate[1]!! - date = domainModel.openingDate[2]!! - } + return GetOfficesResponse( + id = domainModel.id?.toLong(), + name = domainModel.name, + nameDecorated = domainModel.nameDecorated, externalId = domainModel.externalId - } + ) } -} +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/mappers/staffs/StaffMapper.kt b/core/network/src/main/java/com/mifos/core/network/mappers/staffs/StaffMapper.kt index 49b5cb2880..daaafa7a1e 100644 --- a/core/network/src/main/java/com/mifos/core/network/mappers/staffs/StaffMapper.kt +++ b/core/network/src/main/java/com/mifos/core/network/mappers/staffs/StaffMapper.kt @@ -10,8 +10,8 @@ package com.mifos.core.network.mappers.staffs import com.mifos.core.objects.organisation.Staff -import org.apache.fineract.client.models.RetrieveOneResponse import org.mifos.core.data.AbstractMapper +import org.openapitools.client.models.RetrieveOneResponse object StaffMapper : AbstractMapper() { override fun mapFromEntity(entity: RetrieveOneResponse): Staff { @@ -28,15 +28,15 @@ object StaffMapper : AbstractMapper() { } override fun mapToEntity(domainModel: Staff): RetrieveOneResponse { - return RetrieveOneResponse().apply { - id = domainModel.id?.toLong() - firstname = domainModel.firstname - lastname = domainModel.lastname - displayName = domainModel.displayName - officeId = domainModel.officeId?.toLong() - officeName = domainModel.officeName - isLoanOfficer = domainModel.isLoanOfficer + return RetrieveOneResponse( + id = domainModel.id?.toLong(), + firstname = domainModel.firstname, + lastname = domainModel.lastname, + displayName = domainModel.displayName, + officeId = domainModel.officeId?.toLong(), + officeName = domainModel.officeName, + isLoanOfficer = domainModel.isLoanOfficer, isActive = domainModel.isActive - } + ) } } diff --git a/core/network/src/main/java/com/mifos/core/network/services/ClientService.kt b/core/network/src/main/java/com/mifos/core/network/services/ClientService.kt index f5255a21e8..a76138ffbd 100644 --- a/core/network/src/main/java/com/mifos/core/network/services/ClientService.kt +++ b/core/network/src/main/java/com/mifos/core/network/services/ClientService.kt @@ -54,7 +54,7 @@ interface ClientService { ): Observable> @GET(APIEndPoint.CLIENTS + "/{clientId}") - fun getClient(@Path("clientId") clientId: Int): Observable + suspend fun getClient(@Path("clientId") clientId: Int): Client @Multipart @POST(APIEndPoint.CLIENTS + "/{clientId}/images") diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt index 774c3970b5..6e6fa2f078 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt @@ -10,6 +10,7 @@ package com.mifos.feature.auth.login import android.content.Context +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Network @@ -25,8 +26,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import org.apache.fineract.client.models.PostAuthenticationResponse import org.mifos.core.apimanager.BaseApiManager +import org.openapitools.client.models.PostAuthenticationResponse import javax.inject.Inject /** @@ -71,7 +72,7 @@ class LoginViewModel @Inject constructor( baseApiManager.createService( username, password, - prefManager.getServerConfig.getInstanceUrl(), + prefManager.getServerConfig.getInstanceUrl().dropLast(3), prefManager.getServerConfig.tenant, true, ) @@ -90,6 +91,7 @@ class LoginViewModel @Inject constructor( is Resource.Error -> { _loginUiState.value = LoginUiState.ShowError(R.string.feature_auth_error_login_failed) + Log.e("@@@", "login: ${result.message}") } is Resource.Loading -> { diff --git a/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogScreen.kt index 867242b861..7f2531da60 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogScreen.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogScreen.kt @@ -40,6 +40,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.objects.group.Center import com.mifos.feature.center.R +import com.mifos.feature.center.sync_centers_dialog.SyncCentersDialogViewModel @Composable internal fun SyncCenterDialogScreen( diff --git a/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogViewModel.kt b/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogViewModel.kt index fd2ef27c7d..ab99393a1e 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogViewModel.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/syncCentersDialog/SyncCentersDialogViewModel.kt @@ -1,22 +1,13 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ -package com.mifos.feature.center.syncCentersDialog +package com.mifos.feature.center.sync_centers_dialog import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.NetworkUtilsWrapper import com.mifos.core.data.repository.SyncCentersDialogRepository import com.mifos.core.datastore.PrefManager import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.objects.accounts.CenterAccounts -import com.mifos.core.objects.accounts.ClientAccounts import com.mifos.core.objects.accounts.GroupAccounts import com.mifos.core.objects.accounts.loan.LoanAccount import com.mifos.core.objects.accounts.savings.SavingsAccount @@ -28,10 +19,14 @@ import com.mifos.core.objects.group.GroupWithAssociations import com.mifos.core.objects.zipmodels.LoanAndLoanRepayment import com.mifos.core.objects.zipmodels.SavingsAccountAndTransactionTemplate import com.mifos.feature.center.R +import com.mifos.feature.center.syncCentersDialog.SyncCentersDialogData +import com.mifos.feature.center.syncCentersDialog.SyncCentersDialogUiState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch import retrofit2.HttpException import rx.Observable import rx.Subscriber @@ -55,10 +50,11 @@ class SyncCentersDialogViewModel @Inject constructor( val syncCentersDialogUiState: StateFlow = _syncCentersDialogUiState private val _syncCenterData: MutableStateFlow = MutableStateFlow( - SyncCentersDialogData(), + SyncCentersDialogData() ) val syncCenterData: StateFlow = _syncCenterData + private var mLoanAccountList: List = ArrayList() private var mSavingsAccountList: List = ArrayList() private var mMemberLoanAccountsList: List = ArrayList() @@ -162,24 +158,23 @@ class SyncCentersDialogViewModel @Inject constructor( override fun onNext(centerAccounts: CenterAccounts) { mLoanAccountList = getActiveLoanAccounts( centerAccounts - .loanAccounts, + .loanAccounts ) mSavingsAccountList = getActiveSavingsAccounts( centerAccounts - .savingsAccounts, + .savingsAccounts ) mMemberLoanAccountsList = getActiveLoanAccounts( centerAccounts - .memberLoanAccounts, + .memberLoanAccounts ) - // Updating UI - maxSingleSyncCenterProgressBar = ( - mLoanAccountList.size + - mSavingsAccountList.size + mMemberLoanAccountsList.size - ) + //Updating UI + maxSingleSyncCenterProgressBar = (mLoanAccountList.size + + mSavingsAccountList.size + mMemberLoanAccountsList.size) checkAccountsSyncStatusAndSyncAccounts() } }) + } /** @@ -192,13 +187,13 @@ class SyncCentersDialogViewModel @Inject constructor( */ private fun checkAccountsSyncStatusAndSyncAccounts() { if (mLoanAccountList.isNotEmpty() && !mLoanAccountSyncStatus) { - // Sync the Active Loan and LoanRepayment + //Sync the Active Loan and LoanRepayment checkNetworkConnectionAndSyncLoanAndLoanRepayment() } else if (mSavingsAccountList.isNotEmpty() && !mSavingAccountSyncStatus) { - // Sync the Active Savings Account + //Sync the Active Savings Account checkNetworkConnectionAndSyncSavingsAccountAndTransactionTemplate() } else if (mMemberLoanAccountsList.isNotEmpty()) { - // Sync the Active member Loan Account + //Sync the Active member Loan Account checkNetworkConnectionAndSyncMemberLoanAndMemberLoanRepayment() } else { maxSingleSyncCenterProgressBar = 1 @@ -225,11 +220,6 @@ class SyncCentersDialogViewModel @Inject constructor( val endPoint = mMemberLoanAccountsList[mMemberLoanSyncIndex].loanType?.value val id = mSavingsAccountList[mSavingsAndTransactionSyncIndex].id - if (id != null) { - syncMemberLoanAndMemberLoanRepayment( - id, - ) - } if (endPoint != null && id != null) { syncSavingsAccountAndTemplate(endPoint, id) } @@ -328,6 +318,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -356,6 +347,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -386,11 +378,11 @@ class SyncCentersDialogViewModel @Inject constructor( private fun getLoanAndLoanRepayment(loanId: Int): Observable { return Observable.combineLatest( repository.syncLoanById(loanId), - repository.syncLoanRepaymentTemplate(loanId), + repository.syncLoanRepaymentTemplate(loanId) ) { loanWithAssociations, loanRepaymentTemplate -> LoanAndLoanRepayment( loanWithAssociations, - loanRepaymentTemplate, + loanRepaymentTemplate ) } .observeOn(AndroidSchedulers.mainThread()) @@ -405,24 +397,20 @@ class SyncCentersDialogViewModel @Inject constructor( * @return SavingsAccountAndTransactionTemplate */ private fun getSavingsAccountAndTemplate( - savingsAccountType: String, - savingsAccountId: Int, + savingsAccountType: String, savingsAccountId: Int ): Observable { return Observable.combineLatest( repository.syncSavingsAccount( - savingsAccountType, - savingsAccountId, - Constants.TRANSACTIONS, + savingsAccountType, savingsAccountId, + Constants.TRANSACTIONS ), repository.syncSavingsAccountTransactionTemplate( savingsAccountType, - savingsAccountId, - Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT, - ), + savingsAccountId, Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT + ) ) { savingsAccountWithAssociations, savingsAccountTransactionTemplate -> SavingsAccountAndTransactionTemplate( - savingsAccountWithAssociations, - savingsAccountTransactionTemplate, + savingsAccountWithAssociations, savingsAccountTransactionTemplate ) } .observeOn(AndroidSchedulers.mainThread()) @@ -457,6 +445,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -487,6 +476,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -515,15 +505,16 @@ class SyncCentersDialogViewModel @Inject constructor( override fun onNext(groupAccounts: GroupAccounts) { mLoanAccountList = getActiveLoanAccounts( groupAccounts - .loanAccounts, + .loanAccounts ) mSavingsAccountList = getActiveSavingsAccounts( groupAccounts - .savingsAccounts, + .savingsAccounts ) checkAccountsSyncStatusAndSyncGroupAccounts() } }) + } /** @@ -539,28 +530,17 @@ class SyncCentersDialogViewModel @Inject constructor( * * @param clientId Client Id */ - private fun syncClientAccounts(clientId: Int) { - repository.syncClientAccounts(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - onAccountSyncFailed(e) - } - - override fun onNext(clientAccounts: ClientAccounts) { - mLoanAccountList = getActiveLoanAccounts( - clientAccounts - .loanAccounts, - ) - mSavingsAccountList = getSyncableSavingsAccounts( - clientAccounts - .savingsAccounts, - ) - checkAccountsSyncStatusAndSyncClientAccounts() - } - }) + private fun syncClientAccounts(clientId: Int) = viewModelScope.launch(Dispatchers.IO) { + val clientAccounts = repository.syncClientAccounts(clientId) + mLoanAccountList = getActiveLoanAccounts( + clientAccounts + .loanAccounts + ) + mSavingsAccountList = getSyncableSavingsAccounts( + clientAccounts + .savingsAccounts + ) + checkAccountsSyncStatusAndSyncClientAccounts() } /** @@ -571,19 +551,19 @@ class SyncCentersDialogViewModel @Inject constructor( */ private fun checkAccountsSyncStatusAndSyncGroupAccounts() { if (mLoanAccountList.isNotEmpty() && !mLoanAccountSyncStatus) { - // Sync the Active Loan and LoanRepayment + //Sync the Active Loan and LoanRepayment mLoanAccountList[mLoanAndRepaymentSyncIndex].id?.let { syncGroupLoanAndLoanRepayment( - it, + it ) } } else if (mSavingsAccountList.isNotEmpty()) { - // Sync the Active Savings Account + //Sync the Active Savings Account mSavingsAccountList[mSavingsAndTransactionSyncIndex].id?.let { mSavingsAccountList[mSavingsAndTransactionSyncIndex].depositType?.endpoint?.let { it1 -> syncGroupSavingsAccountAndTemplate( it1, - it, + it ) } } @@ -600,19 +580,19 @@ class SyncCentersDialogViewModel @Inject constructor( */ private fun checkAccountsSyncStatusAndSyncClientAccounts() { if (mLoanAccountList.isNotEmpty() && !mLoanAccountSyncStatus) { - // Sync the Active Loan and LoanRepayment + //Sync the Active Loan and LoanRepayment mLoanAccountList[mLoanAndRepaymentSyncIndex].id?.let { syncClientLoanAndLoanRepayment( - it, + it ) } } else if (mSavingsAccountList.isNotEmpty()) { - // Sync the Active Savings Account + //Sync the Active Savings Account mSavingsAccountList[mSavingsAndTransactionSyncIndex].id?.let { mSavingsAccountList[mSavingsAndTransactionSyncIndex].depositType?.endpoint?.let { it1 -> syncClientSavingsAccountAndTemplate( it1, - it, + it ) } } @@ -650,6 +630,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -681,6 +662,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -705,7 +687,7 @@ class SyncCentersDialogViewModel @Inject constructor( if (mLoanAndRepaymentSyncIndex != mLoanAccountList.size) { mLoanAccountList[mLoanAndRepaymentSyncIndex].id?.let { syncGroupLoanAndLoanRepayment( - it, + it ) } } else { @@ -714,6 +696,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -738,7 +721,7 @@ class SyncCentersDialogViewModel @Inject constructor( if (mLoanAndRepaymentSyncIndex != mLoanAccountList.size) { mLoanAccountList[mLoanAndRepaymentSyncIndex].id?.let { syncClientLoanAndLoanRepayment( - it, + it ) } } else { @@ -747,6 +730,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -758,7 +742,7 @@ class SyncCentersDialogViewModel @Inject constructor( */ private fun syncGroupSavingsAccountAndTemplate( savingsAccountType: String, - savingsAccountId: Int, + savingsAccountId: Int ) { getSavingsAccountAndTemplate(savingsAccountType, savingsAccountId) .subscribe(object : Subscriber() { @@ -775,7 +759,7 @@ class SyncCentersDialogViewModel @Inject constructor( mSavingsAccountList[mSavingsAndTransactionSyncIndex].id?.let { it1 -> syncGroupSavingsAccountAndTemplate( it, - it1, + it1 ) } } @@ -784,6 +768,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } /** @@ -795,7 +780,7 @@ class SyncCentersDialogViewModel @Inject constructor( */ private fun syncClientSavingsAccountAndTemplate( savingsAccountType: String, - savingsAccountId: Int, + savingsAccountId: Int ) { getSavingsAccountAndTemplate(savingsAccountType, savingsAccountId) .subscribe(object : Subscriber() { @@ -812,7 +797,7 @@ class SyncCentersDialogViewModel @Inject constructor( .depositType?.endpoint?.let { it1 -> syncClientSavingsAccountAndTemplate( it1, - it, + it ) } } @@ -821,6 +806,7 @@ class SyncCentersDialogViewModel @Inject constructor( } } }) + } private fun updateTotalSyncProgressBarAndCount() { @@ -835,14 +821,14 @@ class SyncCentersDialogViewModel @Inject constructor( } private fun checkNetworkConnection( - taskWhenOnline: () -> Unit, + taskWhenOnline: () -> Unit ) { if (networkUtilsWrapper.isNetworkConnected()) { taskWhenOnline.invoke() } else { _syncCentersDialogUiState.value = SyncCentersDialogUiState.Error( messageResId = R.string.feature_center_error_not_connected_internet, - imageVector = MifosIcons.WifiOff, + imageVector = MifosIcons.WifiOff ) } } @@ -860,7 +846,7 @@ class SyncCentersDialogViewModel @Inject constructor( Observable.from(savingsAccounts) .filter { savingsAccount -> savingsAccount.status?.active == true && - !savingsAccount.depositType!!.isRecurring + !savingsAccount.depositType!!.isRecurring } .subscribe { savingsAccount -> accounts.add(savingsAccount) } return accounts @@ -879,10 +865,11 @@ class SyncCentersDialogViewModel @Inject constructor( Observable.from(savingsAccounts) .filter { savingsAccount -> savingsAccount.depositType?.value == "Savings" && - savingsAccount.status?.active == true && - !savingsAccount.depositType!!.isRecurring + savingsAccount.status?.active == true && + !savingsAccount.depositType!!.isRecurring } .subscribe { savingsAccount -> accounts.add(savingsAccount) } return accounts } -} + +} \ No newline at end of file diff --git a/feature/client/src/main/java/com/mifos/feature/client/createNewClient/CreateNewClientViewModel.kt b/feature/client/src/main/java/com/mifos/feature/client/createNewClient/CreateNewClientViewModel.kt index b872bbe616..408eeec42c 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/createNewClient/CreateNewClientViewModel.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/createNewClient/CreateNewClientViewModel.kt @@ -1,12 +1,3 @@ -/* - * 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/android-client/blob/master/LICENSE.md - */ package com.mifos.feature.client.createNewClient import android.util.Log @@ -15,7 +6,8 @@ import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Resource import com.mifos.core.data.repository.CreateNewClientRepository import com.mifos.core.domain.useCases.ClientTemplateUseCase -import com.mifos.core.domain.useCases.GetStaffInOfficeForCreateNewClientUseCase +import com.mifos.core.domain.useCases.GetOfficeListUseCase +import com.mifos.core.domain.use_cases.GetStaffInOfficeForCreateNewClientUseCase import com.mifos.core.objects.client.Client import com.mifos.core.objects.client.ClientPayload import com.mifos.core.objects.organisation.Office @@ -47,9 +39,11 @@ class CreateNewClientViewModel @Inject constructor( private val repository: CreateNewClientRepository, private val clientTemplateUseCase: ClientTemplateUseCase, private val getStaffInOffice: GetStaffInOfficeForCreateNewClientUseCase, + private val getOfficeListUseCase: GetOfficeListUseCase, ) : ViewModel() { - private val _createNewClientUiState = MutableStateFlow(CreateNewClientUiState.ShowProgressbar) + private val _createNewClientUiState = + MutableStateFlow(CreateNewClientUiState.ShowProgressbar) val createNewClientUiState: StateFlow get() = _createNewClientUiState private val _staffInOffices = MutableStateFlow>(emptyList()) @@ -66,46 +60,42 @@ class CreateNewClientViewModel @Inject constructor( private fun loadClientTemplate() = viewModelScope.launch(Dispatchers.IO) { clientTemplateUseCase().collect { result -> when (result) { - is Resource.Error -> - _createNewClientUiState.value = - CreateNewClientUiState.ShowError(R.string.feature_client_failed_to_fetch_client_template) + is Resource.Error -> _createNewClientUiState.value = + CreateNewClientUiState.ShowError(R.string.feature_client_failed_to_fetch_client_template) is Resource.Loading -> Unit - is Resource.Success -> - _createNewClientUiState.value = - CreateNewClientUiState.ShowClientTemplate(result.data ?: ClientsTemplate()) + is Resource.Success -> _createNewClientUiState.value = + CreateNewClientUiState.ShowClientTemplate(result.data ?: ClientsTemplate()) } } } - private fun loadOffices() { - repository.offices() - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - loadClientTemplate() - } - - override fun onError(e: Throwable) { + private fun loadOffices() = viewModelScope.launch(Dispatchers.IO) { + getOfficeListUseCase().collect { result -> + when (result) { + is Resource.Error -> { _createNewClientUiState.value = CreateNewClientUiState.ShowError(R.string.feature_client_failed_to_fetch_offices) } - override fun onNext(officeList: List) { - _showOffices.value = officeList + is Resource.Loading -> { + + } + + is Resource.Success -> { + _showOffices.value = result.data ?: emptyList() } - }) + } + } } fun loadStaffInOffices(officeId: Int) = viewModelScope.launch(Dispatchers.IO) { getStaffInOffice(officeId).collect { result -> when (result) { - is Resource.Error -> - _createNewClientUiState.value = - CreateNewClientUiState.ShowError(R.string.feature_client_failed_to_fetch_staffs) + is Resource.Error -> _createNewClientUiState.value = + CreateNewClientUiState.ShowError(R.string.feature_client_failed_to_fetch_staffs) is Resource.Loading -> Unit @@ -119,50 +109,54 @@ class CreateNewClientViewModel @Inject constructor( repository.createClient(clientPayload) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - } + .subscribe( + object : Subscriber() { + override fun onCompleted() { + } - override fun onError(e: Throwable) { - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() ?: "" - Log.d("error", errorMessage) - _createNewClientUiState.value = - CreateNewClientUiState.ShowStringError(errorMessage) + override fun onError(e: Throwable) { + try { + if (e is HttpException) { + val errorMessage = e.response()?.errorBody() + ?.string() ?: "" + Log.d("error", errorMessage) + _createNewClientUiState.value = + CreateNewClientUiState.ShowStringError(errorMessage) + + } + } catch (throwable: Throwable) { + RxJavaPlugins.getInstance().errorHandler.handleError(e) } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) } - } - override fun onNext(client: Client?) { - if (client != null) { - if (client.clientId != null) { - _createNewClientUiState.value = - CreateNewClientUiState.ShowClientCreatedSuccessfully(R.string.feature_client_client_created_successfully) - - _createNewClientUiState.value = client.clientId?.let { - CreateNewClientUiState.SetClientId( - it, - ) - }!! - } else { - _createNewClientUiState.value = client.clientId?.let { - CreateNewClientUiState.ShowWaitingForCheckerApproval( - it, - ) - }!! + override fun onNext(client: Client?) { + if (client != null) { + if (client.clientId != null) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowClientCreatedSuccessfully(R.string.feature_client_client_created_successfully) + + _createNewClientUiState.value = client.clientId?.let { + CreateNewClientUiState.SetClientId( + it, + ) + }!! + } else { + _createNewClientUiState.value = client.clientId?.let { + CreateNewClientUiState.ShowWaitingForCheckerApproval( + it, + ) + }!! + } } } - } - }) + }, + ) } fun uploadImage(id: Int, pngFile: File) { _createNewClientUiState.value = CreateNewClientUiState.ShowProgress("Uploading Client's Picture...") + val imagePath = pngFile.absolutePath // create RequestBody instance from file val requestFile = pngFile.asRequestBody("image/png".toMediaTypeOrNull()) @@ -172,19 +166,21 @@ class CreateNewClientViewModel @Inject constructor( repository.uploadClientImage(id, body) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() { - } + .subscribe( + object : Subscriber() { + override fun onCompleted() { + } - override fun onError(e: Throwable) { - _createNewClientUiState.value = - CreateNewClientUiState.ShowError(R.string.feature_client_Image_Upload_Failed) - } + override fun onError(e: Throwable) { + _createNewClientUiState.value = + CreateNewClientUiState.ShowError(R.string.feature_client_Image_Upload_Failed) + } - override fun onNext(t: ResponseBody) { - _createNewClientUiState.value = - CreateNewClientUiState.OnImageUploadSuccess(R.string.feature_client_Image_Upload_Successful) - } - }) + override fun onNext(t: ResponseBody) { + _createNewClientUiState.value = + CreateNewClientUiState.OnImageUploadSuccess(R.string.feature_client_Image_Upload_Successful) + } + }, + ) } -} +} \ No newline at end of file diff --git a/feature/client/src/main/java/com/mifos/feature/client/syncClientDialog/SyncClientsDialogViewModel.kt b/feature/client/src/main/java/com/mifos/feature/client/syncClientDialog/SyncClientsDialogViewModel.kt index 30a7c7acde..7e18c8a89a 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/syncClientDialog/SyncClientsDialogViewModel.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/syncClientDialog/SyncClientsDialogViewModel.kt @@ -1,21 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.feature.client.syncClientDialog import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.NetworkUtilsWrapper import com.mifos.core.data.repository.SyncClientsDialogRepository import com.mifos.core.datastore.PrefManager import com.mifos.core.designsystem.icon.MifosIcons -import com.mifos.core.objects.accounts.ClientAccounts import com.mifos.core.objects.accounts.loan.LoanAccount import com.mifos.core.objects.accounts.savings.SavingsAccount import com.mifos.core.objects.client.Client @@ -23,9 +14,11 @@ import com.mifos.core.objects.zipmodels.LoanAndLoanRepayment import com.mifos.core.objects.zipmodels.SavingsAccountAndTransactionTemplate import com.mifos.feature.client.R import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch import retrofit2.HttpException import rx.Observable import rx.Subscriber @@ -41,7 +34,7 @@ import javax.inject.Inject class SyncClientsDialogViewModel @Inject constructor( private val repository: SyncClientsDialogRepository, private val networkUtilsWrapper: NetworkUtilsWrapper, - private val prefManager: PrefManager, + private val prefManager: PrefManager ) : ViewModel() { private var mClientList: List = ArrayList() @@ -59,7 +52,7 @@ class SyncClientsDialogViewModel @Inject constructor( val syncClientsDialogUiState: StateFlow = _syncClientsDialogUiState private val _syncClientData: MutableStateFlow = MutableStateFlow( - SyncClientsDialogData(), + SyncClientsDialogData() ) val syncClientData: StateFlow = _syncClientData @@ -112,10 +105,10 @@ class SyncClientsDialogViewModel @Inject constructor( fun checkAccountsSyncStatusAndSyncAccounts() { if (mLoanAccountList.isNotEmpty() && !mLoanAccountSyncStatus) { - // Sync the Active Loan and LoanRepayment + //Sync the Active Loan and LoanRepayment checkNetworkConnectionAndSyncLoanAndLoanRepayment() } else if (mSavingsAccountList.isNotEmpty()) { - // Sync the Active Savings Account + //Sync the Active Savings Account checkNetworkConnectionAndSyncSavingsAccountAndTransactionTemplate() } else { // If LoanAccounts and SavingsAccount are null then sync Client to Database @@ -158,32 +151,21 @@ class SyncClientsDialogViewModel @Inject constructor( * * @param clientId Client Id */ - private fun syncClientAccounts(clientId: Int) { - repository.syncClientAccounts(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - onAccountSyncFailed(e) - } + private fun syncClientAccounts(clientId: Int) = viewModelScope.launch(Dispatchers.IO) { + val clientAccounts = repository.syncClientAccounts(clientId) + mLoanAccountList = getActiveLoanAccounts( + clientAccounts + .loanAccounts + ) + mSavingsAccountList = getSyncableSavingsAccounts( + clientAccounts + .savingsAccounts + ) - override fun onNext(clientAccounts: ClientAccounts) { - mLoanAccountList = getActiveLoanAccounts( - clientAccounts - .loanAccounts, - ) - mSavingsAccountList = getSyncableSavingsAccounts( - clientAccounts - .savingsAccounts, - ) - - // Updating UI - maxSingleSyncClientProgressBar = mLoanAccountList.size + - mSavingsAccountList.size - checkAccountsSyncStatusAndSyncAccounts() - } - }) + //Updating UI + maxSingleSyncClientProgressBar = mLoanAccountList.size + + mSavingsAccountList.size + checkAccountsSyncStatusAndSyncAccounts() } /** @@ -198,7 +180,7 @@ class SyncClientsDialogViewModel @Inject constructor( private fun syncLoanAndLoanRepayment(loanId: Int) { Observable.combineLatest( repository.syncLoanById(loanId), - repository.syncLoanRepaymentTemplate(loanId), + repository.syncLoanRepaymentTemplate(loanId) ) { loanWithAssociations, loanRepaymentTemplate -> val loanAndLoanRepayment = LoanAndLoanRepayment() loanAndLoanRepayment.loanWithAssociations = loanWithAssociations @@ -224,6 +206,7 @@ class SyncClientsDialogViewModel @Inject constructor( } } }) + } /** @@ -234,17 +217,16 @@ class SyncClientsDialogViewModel @Inject constructor( * @param savingsAccountId SavingsAccount Id */ private fun syncSavingsAccountAndTemplate(savingsAccountType: String?, savingsAccountId: Int) { + Observable.combineLatest( repository.syncSavingsAccount( - savingsAccountType, - savingsAccountId, - Constants.TRANSACTIONS, + savingsAccountType, savingsAccountId, + Constants.TRANSACTIONS ), repository.syncSavingsAccountTransactionTemplate( savingsAccountType, - savingsAccountId, - Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT, - ), + savingsAccountId, Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT + ) ) { savingsAccountWithAssociations, savingsAccountTransactionTemplate -> val accountAndTransactionTemplate = SavingsAccountAndTransactionTemplate() accountAndTransactionTemplate.savingsAccountTransactionTemplate = @@ -271,6 +253,7 @@ class SyncClientsDialogViewModel @Inject constructor( } } }) + } /** @@ -299,6 +282,7 @@ class SyncClientsDialogViewModel @Inject constructor( syncClient() } }) + } private fun updateTotalSyncProgressBarAndCount() { @@ -307,19 +291,19 @@ class SyncClientsDialogViewModel @Inject constructor( private fun updateClientName() { val clientName = mClientList[mClientSyncIndex].firstname + - mClientList[mClientSyncIndex].lastname + mClientList[mClientSyncIndex].lastname _syncClientData.update { it.copy(clientName = clientName) } } private fun checkNetworkConnection( - taskWhenOnline: () -> Unit, + taskWhenOnline: () -> Unit ) { if (networkUtilsWrapper.isNetworkConnected()) { taskWhenOnline.invoke() } else { _syncClientsDialogUiState.value = SyncClientsDialogUiState.Error( messageResId = R.string.feature_client_error_network_not_available, - imageVector = MifosIcons.WifiOff, + imageVector = MifosIcons.WifiOff ) } } @@ -337,10 +321,10 @@ class SyncClientsDialogViewModel @Inject constructor( Observable.from(savingsAccounts) .filter { savingsAccount -> savingsAccount.depositType?.value == "Savings" && - savingsAccount.status?.active == true && - !savingsAccount.depositType!!.isRecurring + savingsAccount.status?.active == true && + !savingsAccount.depositType!!.isRecurring } .subscribe { savingsAccount -> accounts.add(savingsAccount) } return accounts } -} +} \ No newline at end of file diff --git a/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt index 196056d9e2..3d432fae07 100644 --- a/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/dataTable/dataTable/DataTableViewModel.kt @@ -16,16 +16,12 @@ import com.google.gson.Gson import com.mifos.core.common.utils.Constants import com.mifos.core.data.repository.DataTableRepository import com.mifos.core.objects.navigation.DataTableNavigationArg -import com.mifos.core.objects.noncore.DataTable -import com.mifos.feature.data_table.R import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import javax.inject.Inject /** @@ -56,24 +52,13 @@ class DataTableViewModel @Inject constructor( } } - fun loadDataTable(tableName: String?) { + fun loadDataTable(tableName: String?) = viewModelScope.launch(Dispatchers.IO) { _dataTableUiState.value = DataTableUiState.ShowProgressbar - repository.getDataTable(tableName).observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()).subscribe(object : Subscriber>() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - _dataTableUiState.value = - DataTableUiState.ShowError(R.string.feature_data_table_failed_to_fetch_data_table) - } - - override fun onNext(dataTables: List) { - if (dataTables.isNotEmpty()) { - _dataTableUiState.value = DataTableUiState.ShowDataTables(dataTables) - } else { - _dataTableUiState.value = DataTableUiState.ShowEmptyDataTables - } - } - }) + val response = repository.getDataTable(tableName) + if (response.isEmpty()) { + _dataTableUiState.value = DataTableUiState.ShowEmptyDataTables + } else { + _dataTableUiState.value = DataTableUiState.ShowDataTables(response) + } } } diff --git a/feature/groups/src/main/java/com/mifos/feature/groups/syncGroupDialog/SyncGroupsDialogViewModel.kt b/feature/groups/src/main/java/com/mifos/feature/groups/syncGroupDialog/SyncGroupsDialogViewModel.kt index c372797c21..aba02cf073 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groups/syncGroupDialog/SyncGroupsDialogViewModel.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groups/syncGroupDialog/SyncGroupsDialogViewModel.kt @@ -1,21 +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/android-client/blob/master/LICENSE.md - */ package com.mifos.feature.groups.syncGroupDialog import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.NetworkUtilsWrapper import com.mifos.core.data.repository.SyncGroupsDialogRepository import com.mifos.core.datastore.PrefManager import com.mifos.core.designsystem.icon.MifosIcons -import com.mifos.core.objects.accounts.ClientAccounts import com.mifos.core.objects.accounts.GroupAccounts import com.mifos.core.objects.accounts.loan.LoanAccount import com.mifos.core.objects.accounts.savings.SavingsAccount @@ -26,9 +17,11 @@ import com.mifos.core.objects.zipmodels.LoanAndLoanRepayment import com.mifos.core.objects.zipmodels.SavingsAccountAndTransactionTemplate import com.mifos.feature.groups.R import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch import retrofit2.HttpException import rx.Observable import rx.Subscriber @@ -44,7 +37,7 @@ import javax.inject.Inject class SyncGroupsDialogViewModel @Inject constructor( private val repository: SyncGroupsDialogRepository, private val networkUtilsWrapper: NetworkUtilsWrapper, - private val prefManager: PrefManager, + private val prefManager: PrefManager ) : ViewModel() { private var mGroupList: List = ArrayList() @@ -60,12 +53,12 @@ class SyncGroupsDialogViewModel @Inject constructor( private var maxSingleSyncGroupProgressBar = 0 private val _syncGroupsDialogUiState = MutableStateFlow( - SyncGroupsDialogUiState.Loading, + SyncGroupsDialogUiState.Loading ) val syncGroupsDialogUiState: StateFlow = _syncGroupsDialogUiState private val _syncGroupData: MutableStateFlow = MutableStateFlow( - SyncGroupDialogData(), + SyncGroupDialogData() ) val syncGroupData: StateFlow = _syncGroupData @@ -100,6 +93,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } + /** * This Method Checking network connection and Syncing the LoanAndLoanRepayment. * If found no internet connection then stop syncing the groups and dismiss the dialog. @@ -116,7 +110,8 @@ class SyncGroupsDialogViewModel @Inject constructor( */ private fun checkNetworkConnectionAndSyncSavingsAccountAndTransactionTemplate() { checkNetworkConnection { - val endPoint = mSavingsAccountList[mSavingsAndTransactionSyncIndex].depositType?.endpoint + val endPoint = + mSavingsAccountList[mSavingsAndTransactionSyncIndex].depositType?.endpoint val id = mSavingsAccountList[mSavingsAndTransactionSyncIndex].id if (endPoint != null && id != null) { syncSavingsAccountAndTemplate(endPoint, id) @@ -132,10 +127,10 @@ class SyncGroupsDialogViewModel @Inject constructor( */ private fun checkAccountsSyncStatusAndSyncAccounts() { if (mLoanAccountList.isNotEmpty() && !mLoanAccountSyncStatus) { - // Sync the Active Loan and LoanRepayment + //Sync the Active Loan and LoanRepayment checkNetworkConnectionAndSyncLoanAndLoanRepayment() } else if (mSavingsAccountList.isNotEmpty()) { - // Sync the Active Savings Account + //Sync the Active Savings Account checkNetworkConnectionAndSyncSavingsAccountAndTransactionTemplate() } else { // If LoanAccounts and SavingsAccount are null then sync Client to Database @@ -209,17 +204,18 @@ class SyncGroupsDialogViewModel @Inject constructor( override fun onNext(groupAccounts: GroupAccounts) { mLoanAccountList = getActiveLoanAccounts( - groupAccounts.loanAccounts, + groupAccounts.loanAccounts ) mSavingsAccountList = getActiveSavingsAccounts( - groupAccounts.savingsAccounts, + groupAccounts.savingsAccounts ) - // Updating UI + //Updating UI maxSingleSyncGroupProgressBar = mLoanAccountList.size + mSavingsAccountList.size checkAccountsSyncStatusAndSyncAccounts() } }) + } /** @@ -251,6 +247,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } }) + } /** @@ -278,6 +275,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } }) + } /** @@ -308,6 +306,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } }) + } /** @@ -325,7 +324,8 @@ class SyncGroupsDialogViewModel @Inject constructor( .subscribe(object : Subscriber() { override fun onCompleted() {} override fun onError(e: Throwable) { - _syncGroupsDialogUiState.value = SyncGroupsDialogUiState.Error(message = e.message.toString()) + _syncGroupsDialogUiState.value = + SyncGroupsDialogUiState.Error(message = e.message.toString()) } override fun onNext(client: Client) { @@ -339,6 +339,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } }) + } /** @@ -349,12 +350,12 @@ class SyncGroupsDialogViewModel @Inject constructor( */ private fun checkAccountsSyncStatusAndSyncClientAccounts() { if (mLoanAccountList.isNotEmpty() && !mLoanAccountSyncStatus) { - // Sync the Active Loan and LoanRepayment + //Sync the Active Loan and LoanRepayment mLoanAccountList[mLoanAndRepaymentSyncIndex].id?.let { syncClientLoanAndLoanRepayment(it) } } else if (mSavingsAccountList.isNotEmpty()) { - // Sync the Active Savings Account + //Sync the Active Savings Account mSavingsAccountList[mSavingsAndTransactionSyncIndex].depositType?.endpoint?.let { mSavingsAccountList[mSavingsAndTransactionSyncIndex].id?.let { it1 -> syncClientSavingsAccountAndTemplate(it, it1) @@ -378,28 +379,17 @@ class SyncGroupsDialogViewModel @Inject constructor( * * @param clientId Client Id */ - private fun syncClientAccounts(clientId: Int) { - repository.syncClientAccounts(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - onAccountSyncFailed(e) - } - - override fun onNext(clientAccounts: ClientAccounts) { - mLoanAccountList = getActiveLoanAccounts( - clientAccounts - .loanAccounts, - ) - mSavingsAccountList = getSyncableSavingsAccounts( - clientAccounts - .savingsAccounts, - ) - checkAccountsSyncStatusAndSyncClientAccounts() - } - }) + private fun syncClientAccounts(clientId: Int) = viewModelScope.launch(Dispatchers.IO) { + val clientAccounts = repository.syncClientAccounts(clientId) + mLoanAccountList = getActiveLoanAccounts( + clientAccounts + .loanAccounts + ) + mSavingsAccountList = getSyncableSavingsAccounts( + clientAccounts + .savingsAccounts + ) + checkAccountsSyncStatusAndSyncClientAccounts() } /** @@ -431,6 +421,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } }) + } /** @@ -442,7 +433,7 @@ class SyncGroupsDialogViewModel @Inject constructor( */ private fun syncClientSavingsAccountAndTemplate( savingsAccountType: String, - savingsAccountId: Int, + savingsAccountId: Int ) { getSavingsAccountAndTemplate(savingsAccountType, savingsAccountId) .subscribe(object : Subscriber() { @@ -459,7 +450,7 @@ class SyncGroupsDialogViewModel @Inject constructor( mSavingsAccountList[mSavingsAndTransactionSyncIndex].id?.let { it1 -> syncClientSavingsAccountAndTemplate( it, - it1, + it1 ) } } @@ -468,6 +459,7 @@ class SyncGroupsDialogViewModel @Inject constructor( } } }) + } /** @@ -487,6 +479,7 @@ class SyncGroupsDialogViewModel @Inject constructor( mGroupSyncIndex += 1 syncGroups() } + } /** @@ -498,11 +491,11 @@ class SyncGroupsDialogViewModel @Inject constructor( private fun getLoanAndLoanRepayment(loanId: Int): Observable { return Observable.combineLatest( repository.syncLoanById(loanId), - repository.syncLoanRepaymentTemplate(loanId), + repository.syncLoanRepaymentTemplate(loanId) ) { loanWithAssociations, loanRepaymentTemplate -> LoanAndLoanRepayment( loanWithAssociations, - loanRepaymentTemplate, + loanRepaymentTemplate ) } .observeOn(AndroidSchedulers.mainThread()) @@ -517,24 +510,20 @@ class SyncGroupsDialogViewModel @Inject constructor( * @return SavingsAccountAndTransactionTemplate */ private fun getSavingsAccountAndTemplate( - savingsAccountType: String, - savingsAccountId: Int, + savingsAccountType: String, savingsAccountId: Int ): Observable { return Observable.combineLatest( repository.syncSavingsAccount( - savingsAccountType, - savingsAccountId, - Constants.TRANSACTIONS, + savingsAccountType, savingsAccountId, + Constants.TRANSACTIONS ), repository.syncSavingsAccountTransactionTemplate( savingsAccountType, - savingsAccountId, - Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT, - ), + savingsAccountId, Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT + ) ) { savingsAccountWithAssociations, savingsAccountTransactionTemplate -> SavingsAccountAndTransactionTemplate( - savingsAccountWithAssociations, - savingsAccountTransactionTemplate, + savingsAccountWithAssociations, savingsAccountTransactionTemplate ) } .observeOn(AndroidSchedulers.mainThread()) @@ -553,14 +542,14 @@ class SyncGroupsDialogViewModel @Inject constructor( } private fun checkNetworkConnection( - taskWhenOnline: () -> Unit, + taskWhenOnline: () -> Unit ) { if (networkUtilsWrapper.isNetworkConnected()) { taskWhenOnline.invoke() } else { _syncGroupsDialogUiState.value = SyncGroupsDialogUiState.Error( messageResId = R.string.feature_groups_error_not_connected_internet, - imageVector = MifosIcons.WifiOff, + imageVector = MifosIcons.WifiOff ) } } @@ -578,7 +567,7 @@ class SyncGroupsDialogViewModel @Inject constructor( Observable.from(savingsAccounts) .filter { savingsAccount -> savingsAccount.status?.active == true && - !savingsAccount.depositType!!.isRecurring + !savingsAccount.depositType!!.isRecurring } .subscribe { savingsAccount -> accounts.add(savingsAccount) } return accounts @@ -589,10 +578,10 @@ class SyncGroupsDialogViewModel @Inject constructor( Observable.from(savingsAccounts) .filter { savingsAccount -> savingsAccount.depositType?.value == "Savings" && - savingsAccount.status?.active == true && - !savingsAccount.depositType!!.isRecurring + savingsAccount.status?.active == true && + !savingsAccount.depositType!!.isRecurring } .subscribe { savingsAccount -> accounts.add(savingsAccount) } return accounts } -} +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index de98560eae..19985107f4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -51,7 +51,7 @@ dbflow = "3.1.1" dbflowProcessor = "4.2.4" espressoIdlingResource = "3.5.1" espressoIntents = "3.5.1" -fineractClientVersion = "2.0.3" +fineractClientVersion = "0.0.1" firebaseBom = "32.7.3" firebaseCrashlyticsPlugin = "2.9.9" firebasePerfPlugin = "1.4.2" @@ -86,7 +86,7 @@ material = "1.11.0" materialIconsExtended = "1.6.2" materialshowcaseview = "1.3.7" materialVersion = "1.6.7" -mifosAndroidSdkArchVersion = "1.06" +mifosAndroidSdkArchVersion = "0.0.1" mifosPasscode = "1.0.0" mockitoCore = "5.5.0" moshiVersion = '1.15.0' @@ -333,8 +333,9 @@ mockito-android = { module = "org.mockito:mockito-android", version.ref = "mocki mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockitoCore" } # Mifos SDKs -fineract-client = { module = "com.github.openMF:fineract-client", version.ref = "fineractClientVersion" } -mifos-android-sdk-arch = { module = "com.github.openMF:mifos-android-sdk-arch", version.ref = "mifosAndroidSdkArchVersion" } +fineract-client = { module = "com.github.openMF:fineract-client-cmp", version.ref = "fineractClientVersion" } +mifos-android-sdk-arch = { module = "com.github.openMF:fineract-client-sdk-cmp", version.ref = "mifosAndroidSdkArchVersion" } +mifos-passcode = { module = "com.mifos.mobile:mifos-passcode", version.ref = "mifosPasscode" } #OkHttp squareup-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttpVersion" } diff --git a/mifosng-android/build.gradle.kts b/mifosng-android/build.gradle.kts index 14761808a5..5753205358 100644 --- a/mifosng-android/build.gradle.kts +++ b/mifosng-android/build.gradle.kts @@ -1,6 +1,11 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent import org.mifos.MifosBuildType +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ + plugins { alias(libs.plugins.mifos.android.application) alias(libs.plugins.mifos.android.application.compose) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/home/HomeActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/home/HomeActivity.kt index b2b8eebde5..d1452d6920 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/home/HomeActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/home/HomeActivity.kt @@ -5,9 +5,11 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.Toast +import androidx.activity.ComponentActivity import androidx.activity.OnBackPressedCallback import androidx.annotation.VisibleForTesting import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SwitchCompat import androidx.core.view.GravityCompat import androidx.navigation.findNavController @@ -28,7 +30,7 @@ import dagger.hilt.android.AndroidEntryPoint * Created by shashankpriyadarshi on 19/06/20. */ @AndroidEntryPoint -open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSelectedListener { +open class HomeActivity : ComponentActivity(), NavigationView.OnNavigationItemSelectedListener { private lateinit var binding: ActivityHomeBinding private lateinit var navHeaderBinding: ViewNavDrawerHeaderBinding @@ -42,7 +44,7 @@ open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSe super.onCreate(savedInstanceState) binding = ActivityHomeBinding.inflate(layoutInflater) setContentView(binding.root) - setSupportActionBar(toolbar) +// setSupportActionBar(toolbar) appBarConfiguration = AppBarConfiguration.Builder() .setDrawerLayout(binding.drawer) .build() @@ -56,7 +58,7 @@ open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSe } else if (binding.navView.selectedItemId == R.id.navigation_dashboard) { doubleBackToExit() } - supportFragmentManager.popBackStackImmediate() +// supportFragmentManager.popBackStackImmediate() } }) } @@ -72,7 +74,7 @@ open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSe mDrawerLayout.closeDrawer(Gravity.LEFT); return false; }*/ - clearFragmentBackStack() +// clearFragmentBackStack() when (item.itemId) { R.id.individual_collection_sheet -> { @@ -153,23 +155,23 @@ open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSe binding.navigationView.setNavigationItemSelectedListener(this as NavigationView.OnNavigationItemSelectedListener) // setup drawer layout and sync to toolbar - val actionBarDrawerToggle: ActionBarDrawerToggle = object : ActionBarDrawerToggle( - this, - binding.drawer, toolbar, R.string.open_drawer, R.string.close_drawer - ) { - - override fun onDrawerOpened(drawerView: View) { - super.onDrawerOpened(drawerView) - setUserStatus(userStatusToggle) - hideKeyboard(binding.drawer) - } - - override fun onDrawerSlide(drawerView: View, slideOffset: Float) { - if (slideOffset != 0f) super.onDrawerSlide(drawerView, slideOffset) - } - } - binding.drawer.addDrawerListener(actionBarDrawerToggle) - actionBarDrawerToggle.syncState() +// val actionBarDrawerToggle: ActionBarDrawerToggle = object : ActionBarDrawerToggle( +// this, +// binding.drawer, toolbar, R.string.open_drawer, R.string.close_drawer +// ) { +// +// override fun onDrawerOpened(drawerView: View) { +// super.onDrawerOpened(drawerView) +// setUserStatus(userStatusToggle) +// hideKeyboard(binding.drawer) +// } +// +// override fun onDrawerSlide(drawerView: View, slideOffset: Float) { +// if (slideOffset != 0f) super.onDrawerSlide(drawerView, slideOffset) +// } +// } +// binding.drawer.addDrawerListener(actionBarDrawerToggle) +// actionBarDrawerToggle.syncState() // make an API call to fetch logged in client's details loadClientDetails() @@ -183,7 +185,7 @@ open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSe override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == R.id.logout) { - logout() +// logout() } return super.onOptionsItemSelected(item) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt index b19ac341bd..8c197dee46 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt @@ -25,7 +25,7 @@ import com.mifos.utils.PrefManager /** * @author fomenkoo */ -open class MifosBaseActivity : BaseActivityCallback, AppCompatActivity() { +open class MifosBaseActivity : AppCompatActivity(), BaseActivityCallback { var toolbar: Toolbar? = null private var progress: ProgressDialog? = null override fun setContentView(layoutResID: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt index 4e8ecf40e0..76ac6fb1f2 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt @@ -90,7 +90,7 @@ class RepositoryModule { dataManagerStaff: DataManagerStaff ): CreateNewClientRepository { return CreateNewClientRepositoryImp(dataManagerClient, dataManagerOffices, dataManagerStaff) - } + } @Provides fun providesSavingsAccountTransactionRepository(dataManagerSavings: DataManagerSavings): SavingsAccountTransactionRepository { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt index e0c9448df7..f9b62a9901 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt @@ -10,7 +10,7 @@ import rx.Observable */ interface CenterListRepository { - fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable> + suspend fun getCenters(paged: Boolean, offset: Int, limit: Int): Page
suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt index 2d757b565b..126e8c3847 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt @@ -13,7 +13,7 @@ import javax.inject.Inject class CenterListRepositoryImp @Inject constructor(private val dataManagerCenter: DataManagerCenter) : CenterListRepository { - override fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable> { + override suspend fun getCenters(paged: Boolean, offset: Int, limit: Int): Page
{ return dataManagerCenter.getCenters(paged, offset, limit) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt index fbdcc39efa..dfd8713840 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt @@ -74,37 +74,38 @@ class CenterListViewModel @Inject constructor(private val repository: CenterList */ private fun loadCenters(paged: Boolean, offset: Int, limit: Int) { _centerListUiState.value = CenterListUiState.ShowProgressbar(true) - repository.getCenters(paged, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - if (loadmore) { - _centerListUiState.value = - CenterListUiState.ShowMessage(R.string.failed_to_fetch_centers) - } else { - _centerListUiState.value = CenterListUiState.ShowFetchingError - } - } - - override fun onNext(centerPage: Page
) { - mSyncCenterList = centerPage.pageItems - if (mSyncCenterList.isEmpty() && !loadmore) { - _centerListUiState.value = - CenterListUiState.ShowEmptyCenters(R.string.center) - _centerListUiState.value = - CenterListUiState.UnregisterSwipeAndScrollListener - } else if (mSyncCenterList.isEmpty() && loadmore) { - _centerListUiState.value = - CenterListUiState.ShowMessage(R.string.no_more_centers_available) - } else { - showCenters(mSyncCenterList) - mRestApiCenterSyncStatus = true - setAlreadyCenterSyncStatus() - } - } - }) +// val response = repository.getCenters() +// repository.getCenters(paged, offset, limit) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribeOn(Schedulers.io()) +// .subscribe(object : Subscriber>() { +// override fun onCompleted() {} +// override fun onError(e: Throwable) { +// if (loadmore) { +// _centerListUiState.value = +// CenterListUiState.ShowMessage(R.string.failed_to_fetch_centers) +// } else { +// _centerListUiState.value = CenterListUiState.ShowFetchingError +// } +// } +// +// override fun onNext(centerPage: Page
) { +// mSyncCenterList = centerPage.pageItems +// if (mSyncCenterList.isEmpty() && !loadmore) { +// _centerListUiState.value = +// CenterListUiState.ShowEmptyCenters(R.string.center) +// _centerListUiState.value = +// CenterListUiState.UnregisterSwipeAndScrollListener +// } else if (mSyncCenterList.isEmpty() && loadmore) { +// _centerListUiState.value = +// CenterListUiState.ShowMessage(R.string.no_more_centers_available) +// } else { +// showCenters(mSyncCenterList) +// mRestApiCenterSyncStatus = true +// setAlreadyCenterSyncStatus() +// } +// } +// }) } fun loadCentersGroupAndMeeting(id: Int) = viewModelScope.launch(Dispatchers.IO) { diff --git a/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt b/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt index c573d8edb2..b5d904355d 100644 --- a/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt +++ b/mifosng-android/src/main/java/com/mifos/utils/PrefManager.kt @@ -4,9 +4,9 @@ import android.content.SharedPreferences import android.preference.PreferenceManager import com.mifos.application.App import com.mifos.core.objects.user.User -import org.apache.fineract.client.models.PostAuthenticationResponse import org.mifos.core.sharedpreference.Key import org.mifos.core.sharedpreference.UserPreferences +import org.openapitools.client.models.PostAuthenticationResponse /** * Created by Aditya Gupta on 19/08/23. @@ -18,7 +18,8 @@ object PrefManager : UserPreferences() { private const val AUTH_USERNAME = "auth_username" private const val AUTH_PASSWORD = "auth_password" - override val preference: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.instance?.applicationContext) + override val preference: SharedPreferences = + PreferenceManager.getDefaultSharedPreferences(App.instance?.applicationContext) override fun getUser(): User { return get(Key.Custom(USER_DETAILS))