Skip to content

Commit

Permalink
Merge pull request #2260 from Aditya-gupta99/new_sdk
Browse files Browse the repository at this point in the history
feat: Implemented fineract client sdk
  • Loading branch information
Aditya-gupta99 authored Dec 15, 2024
2 parents 72142da + c535672 commit c9854d2
Show file tree
Hide file tree
Showing 78 changed files with 971 additions and 1,458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,7 +18,7 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
override fun getRefreshKey(state: PagingState<Int, Center>): Int? {
return state.anchorPosition?.let { position ->
state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition(
position,
position
)?.nextKey?.minus(10)
}
}
Expand All @@ -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<List<Center>, Int> =
suspendCoroutine { continuation ->
try {
dataManagerCenter.getCenters(true, position, 10)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Page<Center>>() {
override fun onCompleted() {
}

override fun onError(exception: Throwable) {
continuation.resumeWithException(exception)
}

override fun onNext(center: Page<Center>) {
continuation.resume(
Pair(
center.pageItems,
center.totalFilteredRecords,
),
)
}
})
} catch (exception: Exception) {
continuation.resumeWithException(exception)
}
}
private suspend fun getCenterList(position: Int): Pair<List<Center>, Int> {
val pagedClient = dataManagerCenter.getCenters(true, position, 10)
return Pair(pagedClient.pageItems, pagedClient.totalFilteredRecords)
}

private suspend fun getCenterDbList(): List<Center> = suspendCoroutine { continuation ->
try {

dataManagerCenter.allDatabaseCenters
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
Expand All @@ -100,9 +69,10 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
}
}


private fun getCenterListWithSync(
centerList: List<Center>,
centerDbList: List<Center>,
centerDbList: List<Center>
): List<Center> {
if (centerDbList.isNotEmpty()) {
centerList.forEach { center ->
Expand All @@ -115,4 +85,4 @@ class CenterListPagingSource(private val dataManagerCenter: DataManagerCenter) :
}
return centerList
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +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.data.pagingSource

import androidx.paging.PagingSource
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
Expand All @@ -27,13 +17,13 @@ import kotlin.coroutines.suspendCoroutine
*/

class ClientListPagingSource(
private val dataManagerClient: DataManagerClient,
private val dataManagerClient: DataManagerClient
) : PagingSource<Int, Client>() {

override fun getRefreshKey(state: PagingState<Int, Client>): Int? {
return state.anchorPosition?.let { position ->
state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition(
position,
position
)?.nextKey?.minus(10)
}
}
Expand All @@ -49,31 +39,16 @@ 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)
}
}

private suspend fun getClientList(position: Int): Pair<List<Client>, Int> {
return suspendCancellableCoroutine { continuation ->
dataManagerClient.getAllClients(offset = position, 10)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Page<Client>>() {
override fun onCompleted() {
}

override fun onError(e: Throwable) {
continuation.resumeWithException(e)
}

override fun onNext(t: Page<Client>) {
continuation.resume(Pair(t.pageItems, t.totalFilteredRecords))
}
})
}
val response = dataManagerClient.getAllClients(position, 10)
return Pair(response.pageItems, response.totalFilteredRecords)
}

private suspend fun getClientDbList(): List<Client> {
Expand All @@ -98,7 +73,7 @@ class ClientListPagingSource(

private fun getClientListWithSync(
clientList: List<Client>,
clientDbList: List<Client>,
clientDbList: List<Client>
): List<Client> {
if (clientDbList.isNotEmpty()) {
clientList.forEach { client ->
Expand All @@ -111,4 +86,4 @@ class ClientListPagingSource(
}
return clientList
}
}
}
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -21,18 +12,19 @@ import rx.Observable

interface ActivateRepository {

fun activateClient(
suspend fun activateClient(
clientId: Int,
clientActivate: ActivatePayload?,
): Observable<PostClientsClientIdResponse>
clientActivate: ActivatePayload?
): PostClientsClientIdResponse

fun activateCenter(
suspend fun activateCenter(
centerId: Int,
activatePayload: ActivatePayload?,
): Observable<PostCentersCenterIdResponse>
activatePayload: ActivatePayload?
): PostCentersCenterIdResponse

fun activateGroup(
groupId: Int,
activatePayload: ActivatePayload?,
activatePayload: ActivatePayload?
): Observable<GenericResponse>
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,7 +15,8 @@ interface ClientDetailsRepository {

fun deleteClientImage(clientId: Int): Observable<ResponseBody>

fun getClientAccounts(clientId: Int): Observable<ClientAccounts>
suspend fun getClientAccounts(clientId: Int): ClientAccounts

suspend fun getClient(clientId: Int): Client

fun getClient(clientId: Int): Observable<Client>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IdentifierTemplate>
suspend fun getClientIdentifierTemplate(clientId: Int): IdentifierTemplate

suspend fun createClientIdentifier(
clientId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<Identifier>>
suspend fun getClientIdentifiers(clientId: Int): List<Identifier>

fun deleteClientIdentifier(
suspend fun deleteClientIdentifier(
clientId: Int,
identifierId: Int,
): Observable<DeleteClientsClientIdIdentifiersIdentifierIdResponse>
}
identifierId: Int
): DeleteClientsClientIdIdentifiersIdentifierIdResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ interface CreateNewClientRepository {

fun clientTemplate(): Observable<ClientsTemplate>

fun offices(): Observable<List<Office>>
suspend fun offices(): List<Office>

fun getStaffInOffice(officeId: Int): Observable<List<Staff>>
suspend fun getStaffInOffice(officeId: Int): List<Staff>

fun createClient(clientPayload: ClientPayload): Observable<Client>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import rx.Observable
*/
interface CreateNewGroupRepository {

fun offices(): Observable<List<Office>>
suspend fun offices(): List<Office>

fun createGroup(groupPayload: GroupPayload): Observable<SaveResponse>
}
Loading

0 comments on commit c9854d2

Please sign in to comment.