Skip to content

Commit

Permalink
Fixes #2035 : Fineract SDK Implementation : client, center, group list (
Browse files Browse the repository at this point in the history
#2037)

* Implemented client, center,group list using sdk

* Unit test for viewmodels, staff and offlice sdk implementation
  • Loading branch information
Aditya-gupta99 authored Aug 29, 2023
1 parent beece85 commit 5f0ff47
Show file tree
Hide file tree
Showing 23 changed files with 698 additions and 22 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ext {
jUnitVersion = '4.13.2'

// mockito version
mockitoVersion = '5.4.0'
mockitoVersion = '5.5.0'

//jsr version
jsrVersion = '1.0'
Expand Down Expand Up @@ -129,4 +129,7 @@ ext {

// sdk client
clientVersion = '2.0.3'

// arch core testing
archCoreVersion = '2.2.0'
}
1 change: 1 addition & 0 deletions mifosng-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ dependencies {
androidTestImplementation "org.mockito:mockito-core:$rootProject.mockitoVersion"
androidTestImplementation "org.mockito:mockito-android:$rootProject.mockitoVersion"
testImplementation "org.junit.jupiter:junit-jupiter:$rootProject.junitJupiterVersion"
testImplementation "androidx.arch.core:core-testing:$rootProject.archCoreVersion"

//Android-Jobs
implementation "com.evernote:android-job:$rootProject.androidJobVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mifos.api.datamanager
import com.mifos.api.BaseApiManager
import com.mifos.api.GenericResponse
import com.mifos.api.local.databasehelper.DatabaseHelperCenter
import com.mifos.mappers.centers.GetCentersResponseMapper
import com.mifos.objects.accounts.CenterAccounts
import com.mifos.objects.client.ActivatePayload
import com.mifos.objects.client.Page
Expand All @@ -25,7 +26,8 @@ import javax.inject.Singleton
@Singleton
class DataManagerCenter @Inject constructor(
val mBaseApiManager: BaseApiManager,
val mDatabaseHelperCenter: DatabaseHelperCenter
private val mDatabaseHelperCenter: DatabaseHelperCenter,
private val baseApiManager : org.mifos.core.apimanager.BaseApiManager
) {
/**
* This Method sending the Request to REST API if UserStatus is 0 and
Expand All @@ -45,7 +47,11 @@ class DataManagerCenter @Inject constructor(
*/
fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable<Page<Center>> {
return when (userStatus) {
false -> mBaseApiManager.centerApi.getCenters(paged, offset, limit)
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mifos.api.datamanager
import com.mifos.api.BaseApiManager
import com.mifos.api.GenericResponse
import com.mifos.api.local.databasehelper.DatabaseHelperClient
import com.mifos.mappers.clients.GetClientResponseMapper
import com.mifos.objects.accounts.ClientAccounts
import com.mifos.objects.client.ActivatePayload
import com.mifos.objects.client.Client
Expand Down Expand Up @@ -30,7 +31,7 @@ import javax.inject.Singleton
@Singleton
class DataManagerClient @Inject constructor(
val mBaseApiManager: BaseApiManager,
val mDatabaseHelperClient: DatabaseHelperClient,
private val mDatabaseHelperClient: DatabaseHelperClient,
private val baseApiManager: org.mifos.core.apimanager.BaseApiManager
) {
/**
Expand All @@ -51,8 +52,12 @@ class DataManagerClient @Inject constructor(
*/
fun getAllClients(paged: Boolean, offset: Int, limit: Int): Observable<Page<Client>> {
return when (userStatus) {
false -> mBaseApiManager.clientsApi.getAllClients(paged, offset, limit)
.concatMap { clientPage -> Observable.just(clientPage) }
false -> baseApiManager.getClientsApi().retrieveAll21(
null, null, null,
null, null, null,
null, null, offset,
limit, null, null, null
).map(GetClientResponseMapper::mapFromEntity)

true -> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.mifos.api.BaseApiManager
import com.mifos.api.GenericResponse
import com.mifos.api.local.databasehelper.DatabaseHelperClient
import com.mifos.api.local.databasehelper.DatabaseHelperGroups
import com.mifos.mappers.groups.GetGroupsResponseMapper
import com.mifos.objects.accounts.GroupAccounts
import com.mifos.objects.client.ActivatePayload
import com.mifos.objects.client.Page
Expand All @@ -26,7 +27,8 @@ import javax.inject.Singleton
class DataManagerGroups @Inject constructor(
val mBaseApiManager: BaseApiManager,
private val mDatabaseHelperGroups: DatabaseHelperGroups,
private val mDatabaseHelperClient: DatabaseHelperClient
private val mDatabaseHelperClient: DatabaseHelperClient,
private val baseApiManager: org.mifos.core.apimanager.BaseApiManager
) {
/**
* This Method sending the Request to REST API if UserStatus is 0 and
Expand All @@ -46,7 +48,20 @@ class DataManagerGroups @Inject constructor(
*/
fun getGroups(paged: Boolean, offset: Int, limit: Int): Observable<Page<Group>> {
return when (userStatus) {
false -> mBaseApiManager.groupApi.getGroups(paged, offset, limit)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mifos.api.datamanager

import com.mifos.api.BaseApiManager
import com.mifos.api.local.databasehelper.DatabaseHelperOffices
import com.mifos.mappers.offices.GetOfficeResponseMapper
import com.mifos.objects.organisation.Office
import com.mifos.utils.PrefManager.userStatus
import rx.Observable
Expand All @@ -18,18 +19,16 @@ import javax.inject.Singleton
@Singleton
class DataManagerOffices @Inject constructor(
val mBaseApiManager: BaseApiManager,
val mDatabaseHelperOffices: DatabaseHelperOffices
private val mDatabaseHelperOffices: DatabaseHelperOffices,
private val baseApiManager: org.mifos.core.apimanager.BaseApiManager
) {
/**
* return all List of Offices from DatabaseHelperOffices
*/
val offices: Observable<List<Office>>
get() = when (userStatus) {
false -> mBaseApiManager.officeApi.allOffices
.concatMap { offices ->
mDatabaseHelperOffices.saveAllOffices(offices)
Observable.just(offices)
}
false -> baseApiManager.getOfficeApi().retrieveOffices(null, null, null)
.map(GetOfficeResponseMapper::mapFromEntityList)

true ->
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.mifos.api.datamanager

import com.mifos.api.BaseApiManager
import com.mifos.api.local.databasehelper.DatabaseHelperStaff
import com.mifos.mappers.staffs.StaffMapper
import com.mifos.objects.organisation.Staff
import com.mifos.utils.PrefManager.userStatus
import rx.Observable
import rx.functions.Func1
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -15,19 +15,17 @@ import javax.inject.Singleton
@Singleton
class DataManagerStaff @Inject constructor(
val mBaseApiManager: BaseApiManager,
private val mDatabaseHelperStaff: DatabaseHelperStaff
private val mDatabaseHelperStaff: DatabaseHelperStaff,
private val baseApiManager: org.mifos.core.apimanager.BaseApiManager
) {
/**
* @param officeId
* @return
*/
fun getStaffInOffice(officeId: Int): Observable<List<Staff>> {
return when (userStatus) {
false -> mBaseApiManager.staffApi.getStaffForOffice(officeId)
.concatMap { staffs ->
mDatabaseHelperStaff.saveAllStaffOfOffices(staffs)
Observable.just(staffs)
}
false -> baseApiManager.getStaffApi().retrieveAll16(officeId.toLong(), null, null, null)
.map(StaffMapper::mapFromEntityList)

true ->
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mifos.mappers.centers

import com.mifos.objects.client.Status
import com.mifos.objects.group.Center
import org.apache.fineract.client.models.GetCentersPageItems
import org.apache.fineract.client.models.GetCentersStatus
import org.mifos.core.data.AbstractMapper

object CenterMapper : AbstractMapper<GetCentersPageItems, Center>() {

override fun mapFromEntity(entity: GetCentersPageItems): Center {
return Center().apply {
id = entity.id
active = entity.active
name = entity.name
officeName = entity.officeName
officeId = entity.officeId
hierarchy = entity.hierarchy
status = Status().apply {
id = entity.status?.id!!
code = entity.status?.code
value = entity.status?.description
}
}
}

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
description = domainModel.status?.value
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mifos.mappers.centers

import com.mifos.objects.client.Page
import com.mifos.objects.group.Center
import org.apache.fineract.client.models.GetCentersResponse
import org.mifos.core.data.AbstractMapper

object GetCentersResponseMapper : AbstractMapper<GetCentersResponse, Page<Center>>() {

override fun mapFromEntity(entity: GetCentersResponse): Page<Center> {
return Page<Center>().apply {
totalFilteredRecords = entity.totalFilteredRecords!!
pageItems = CenterMapper.mapFromEntityList(entity.pageItems!!)
}
}

override fun mapToEntity(domainModel: Page<Center>): GetCentersResponse {
return GetCentersResponse().apply {
totalFilteredRecords = domainModel.totalFilteredRecords
pageItems = CenterMapper.mapToEntityList(domainModel.pageItems)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.mifos.mappers.clients

import com.mifos.objects.client.Client
import com.mifos.objects.client.Status
import org.apache.fineract.client.models.GetClientStatus
import org.apache.fineract.client.models.GetClientsPageItemsResponse
import org.mifos.core.data.AbstractMapper

object ClientMapper : AbstractMapper<GetClientsPageItemsResponse, Client>() {

override fun mapFromEntity(entity: GetClientsPageItemsResponse): Client {
return Client().apply {
id = entity.id!!
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!!
officeName = entity.officeName
active = entity.active!!
status = Status().apply {
id = entity.status?.id!!
code = entity.status?.code
value = entity.status?.description
}
}
}

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
description = domainModel.status?.value
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mifos.mappers.clients

import com.mifos.objects.client.Client
import com.mifos.objects.client.Page
import org.apache.fineract.client.models.GetClientsResponse
import org.mifos.core.data.AbstractMapper

object GetClientResponseMapper : AbstractMapper<GetClientsResponse, Page<Client>>() {

override fun mapFromEntity(entity: GetClientsResponse): Page<Client> {
return Page<Client>().apply {
totalFilteredRecords = entity.totalFilteredRecords!!
pageItems = ClientMapper.mapFromEntityList(entity.pageItems!!)
}
}

override fun mapToEntity(domainModel: Page<Client>): GetClientsResponse {
return GetClientsResponse().apply {
totalFilteredRecords = domainModel.totalFilteredRecords
pageItems = ClientMapper.mapToEntityList(domainModel.pageItems)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mifos.mappers.groups

import com.mifos.objects.client.Page
import com.mifos.objects.group.Group
import org.apache.fineract.client.models.GetGroupsResponse
import org.mifos.core.data.AbstractMapper

object GetGroupsResponseMapper : AbstractMapper<GetGroupsResponse, Page<Group>>() {

override fun mapFromEntity(entity: GetGroupsResponse): Page<Group> {
return Page<Group>().apply {
totalFilteredRecords = entity.totalFilteredRecords!!
pageItems = GroupMapper.mapFromEntityList(entity.pageItems!!)
}
}

override fun mapToEntity(domainModel: Page<Group>): GetGroupsResponse {
return GetGroupsResponse().apply {
totalFilteredRecords = domainModel.totalFilteredRecords
pageItems = GroupMapper.mapToEntityList(domainModel.pageItems)
}
}
}
Loading

0 comments on commit 5f0ff47

Please sign in to comment.