Skip to content

Commit 67a1f0c

Browse files
Fixes #2035 : Fineract SDK Implementation : Client, Center,DataTable services (#2039)
* Sdk implementation of client service * Implemented sdk for center client group services
1 parent 5f0ff47 commit 67a1f0c

16 files changed

+352
-39
lines changed

mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerCenter.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.mifos.api.BaseApiManager
44
import com.mifos.api.GenericResponse
55
import com.mifos.api.local.databasehelper.DatabaseHelperCenter
66
import com.mifos.mappers.centers.GetCentersResponseMapper
7+
import com.mifos.mappers.offices.GetOfficeResponseMapper
78
import com.mifos.objects.accounts.CenterAccounts
89
import com.mifos.objects.client.ActivatePayload
910
import com.mifos.objects.client.Page
@@ -13,6 +14,9 @@ import com.mifos.objects.organisation.Office
1314
import com.mifos.objects.response.SaveResponse
1415
import com.mifos.services.data.CenterPayload
1516
import com.mifos.utils.PrefManager.userStatus
17+
import org.apache.fineract.client.models.PostCentersCenterIdRequest
18+
import org.apache.fineract.client.models.PostCentersCenterIdResponse
19+
import org.apache.fineract.client.models.PostClientsClientIdRequest
1620
import rx.Observable
1721
import javax.inject.Inject
1822
import javax.inject.Singleton
@@ -139,8 +143,10 @@ class DataManagerCenter @Inject constructor(
139143
*/
140144
val allDatabaseCenters: Observable<Page<Center>>
141145
get() = mDatabaseHelperCenter.readAllCenters()
146+
142147
val offices: Observable<List<Office>>
143-
get() = mBaseApiManager.officeApi.allOffices
148+
get() = baseApiManager.getOfficeApi().retrieveOffices(null, null, null)
149+
.map(GetOfficeResponseMapper::mapFromEntityList)
144150

145151
/**
146152
* This method loading the all CenterPayloads from the Database.
@@ -181,7 +187,12 @@ class DataManagerCenter @Inject constructor(
181187
fun activateCenter(
182188
centerId: Int,
183189
activatePayload: ActivatePayload?
184-
): Observable<GenericResponse> {
185-
return mBaseApiManager.centerApi.activateCenter(centerId, activatePayload)
190+
): Observable<PostCentersCenterIdResponse> {
191+
return baseApiManager.getCenterApi().activate2(centerId.toLong(),
192+
PostCentersCenterIdRequest().apply {
193+
closureDate = activatePayload?.activationDate
194+
dateFormat = activatePayload?.dateFormat
195+
locale = activatePayload?.locale
196+
},"activate")
186197
}
187198
}

mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerClient.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import com.mifos.api.BaseApiManager
44
import com.mifos.api.GenericResponse
55
import com.mifos.api.local.databasehelper.DatabaseHelperClient
66
import com.mifos.mappers.clients.GetClientResponseMapper
7+
import com.mifos.mappers.clients.GetClientsClientIdAccountMapper
8+
import com.mifos.mappers.clients.GetIdentifiersTemplateMapper
9+
import com.mifos.mappers.clients.IdentifierMapper
710
import com.mifos.objects.accounts.ClientAccounts
811
import com.mifos.objects.client.ActivatePayload
912
import com.mifos.objects.client.Client
@@ -19,6 +22,9 @@ import com.mifos.objects.templates.clients.ClientsTemplate
1922
import com.mifos.utils.PrefManager.userStatus
2023
import okhttp3.MultipartBody
2124
import okhttp3.ResponseBody
25+
import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse
26+
import org.apache.fineract.client.models.PostClientsClientIdRequest
27+
import org.apache.fineract.client.models.PostClientsClientIdResponse
2228
import rx.Observable
2329
import javax.inject.Inject
2430
import javax.inject.Singleton
@@ -115,7 +121,9 @@ class DataManagerClient @Inject constructor(
115121
*/
116122
fun getClientAccounts(clientId: Int): Observable<ClientAccounts> {
117123
return when (userStatus) {
118-
false -> mBaseApiManager.clientsApi.getClientAccounts(clientId)
124+
false -> baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong())
125+
.map(GetClientsClientIdAccountMapper::mapFromEntity)
126+
119127
true ->
120128
/**
121129
* Return Clients from DatabaseHelperClient only one time.
@@ -133,7 +141,8 @@ class DataManagerClient @Inject constructor(
133141
* @return ClientAccounts
134142
*/
135143
fun syncClientAccounts(clientId: Int): Observable<ClientAccounts> {
136-
return mBaseApiManager.clientsApi.getClientAccounts(clientId)
144+
return baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong())
145+
.map(GetClientsClientIdAccountMapper::mapFromEntity)
137146
.concatMap { clientAccounts ->
138147
mDatabaseHelperClient.saveClientAccounts(
139148
clientAccounts,
@@ -259,7 +268,8 @@ class DataManagerClient @Inject constructor(
259268
* @return List<Identifier>
260269
</Identifier> */
261270
fun getClientIdentifiers(clientId: Int): Observable<List<Identifier>> {
262-
return mBaseApiManager.clientsApi.getClientIdentifiers(clientId)
271+
return baseApiManager.getClient().clientIdentifiers.retrieveAllClientIdentifiers(clientId.toLong())
272+
.map(IdentifierMapper::mapFromEntityList)
263273
}
264274

265275
/**
@@ -282,7 +292,8 @@ class DataManagerClient @Inject constructor(
282292
* @return IdentifierTemplate
283293
*/
284294
fun getClientIdentifierTemplate(clientId: Int): Observable<IdentifierTemplate> {
285-
return mBaseApiManager.clientsApi.getClientIdentifierTemplate(clientId)
295+
return baseApiManager.getClient().clientIdentifiers.newClientIdentifierDetails(clientId.toLong())
296+
.map(GetIdentifiersTemplateMapper::mapFromEntity)
286297
}
287298

288299
/**
@@ -292,8 +303,8 @@ class DataManagerClient @Inject constructor(
292303
* @param identifierId Identifier Id
293304
* @return GenericResponse
294305
*/
295-
fun deleteClientIdentifier(clientId: Int, identifierId: Int): Observable<GenericResponse> {
296-
return mBaseApiManager.clientsApi.deleteClientIdentifier(clientId, identifierId)
306+
fun deleteClientIdentifier(clientId: Int, identifierId: Int): Observable<DeleteClientsClientIdIdentifiersIdentifierIdResponse> {
307+
return baseApiManager.getClient().clientIdentifiers.deleteClientIdentifier(clientId.toLong(),identifierId.toLong())
297308
}
298309

299310
/**
@@ -363,7 +374,12 @@ class DataManagerClient @Inject constructor(
363374
fun activateClient(
364375
clientId: Int,
365376
clientActivate: ActivatePayload?
366-
): Observable<GenericResponse> {
367-
return mBaseApiManager.clientsApi.activateClient(clientId, clientActivate)
377+
): Observable<PostClientsClientIdResponse> {
378+
return baseApiManager.getClientsApi().activate1(clientId.toLong(),
379+
PostClientsClientIdRequest().apply {
380+
activationDate = clientActivate?.activationDate
381+
dateFormat = clientActivate?.dateFormat
382+
locale = clientActivate?.locale
383+
},"activate")
368384
}
369385
}

mifosng-android/src/main/java/com/mifos/api/datamanager/DataManagerDataTable.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import com.google.gson.JsonArray
44
import com.mifos.api.BaseApiManager
55
import com.mifos.api.GenericResponse
66
import com.mifos.api.local.databasehelper.DatabaseHelperDataTable
7+
import com.mifos.mappers.dataTable.GetDataTablesResponseMapper
78
import com.mifos.objects.noncore.DataTable
89
import com.mifos.objects.user.UserLocation
10+
import org.apache.fineract.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse
11+
import org.apache.fineract.client.models.GetDataTablesResponse
912
import rx.Observable
1013
import javax.inject.Inject
1114
import javax.inject.Singleton
@@ -19,7 +22,8 @@ import javax.inject.Singleton
1922
@Singleton
2023
class DataManagerDataTable @Inject constructor(
2124
val mBaseApiManager: BaseApiManager,
22-
val mDatabaseHelperDataTable: DatabaseHelperDataTable
25+
val mDatabaseHelperDataTable: DatabaseHelperDataTable,
26+
private val baseApiManager: org.mifos.core.apimanager.BaseApiManager
2327
) {
2428
/**
2529
* This Method Request the REST API of Datatable and In response give the List of DataTable
@@ -31,7 +35,8 @@ class DataManagerDataTable @Inject constructor(
3135
* @return List<DataTable>
3236
</DataTable> */
3337
fun getDataTable(tableName: String?): Observable<List<DataTable>> {
34-
return mBaseApiManager.dataTableApi.getTableOf(tableName)
38+
return baseApiManager.getDataTableApi().getDatatables(tableName).map(
39+
GetDataTablesResponseMapper::mapFromEntityList)
3540
}
3641

3742
fun getDataTableInfo(table: String?, entityId: Int): Observable<JsonArray> {
@@ -45,10 +50,8 @@ class DataManagerDataTable @Inject constructor(
4550
.createEntryInDataTable(table, entityId, payload)
4651
}
4752

48-
fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int): Observable<GenericResponse> {
49-
return mBaseApiManager.dataTableApi.deleteEntryOfDataTableManyToMany(
50-
table, entity, rowId
51-
)
53+
fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int): Observable<DeleteDataTablesDatatableAppTableIdDatatableIdResponse> {
54+
return baseApiManager.getDataTableApi().deleteDatatableEntries1(table,entity.toLong(),rowId.toLong())
5255
}
5356

5457
/**
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package com.mifos.mappers.clients
2+
3+
import com.mifos.objects.accounts.ClientAccounts
4+
import com.mifos.objects.accounts.loan.LoanAccount
5+
import com.mifos.objects.accounts.loan.LoanType
6+
import com.mifos.objects.accounts.savings.Currency
7+
import com.mifos.objects.accounts.savings.DepositType
8+
import com.mifos.objects.accounts.savings.SavingsAccount
9+
import com.mifos.objects.accounts.savings.Status
10+
import org.apache.fineract.client.models.GetClientsClientIdAccountsResponse
11+
import org.apache.fineract.client.models.GetClientsLoanAccounts
12+
import org.apache.fineract.client.models.GetClientsLoanAccountsStatus
13+
import org.apache.fineract.client.models.GetClientsLoanAccountsType
14+
import org.apache.fineract.client.models.GetClientsSavingsAccounts
15+
import org.apache.fineract.client.models.GetClientsSavingsAccountsCurrency
16+
import org.apache.fineract.client.models.GetClientsSavingsAccountsStatus
17+
import org.mifos.core.data.AbstractMapper
18+
19+
/**
20+
* Created by Aditya Gupta on 30/08/23.
21+
*/
22+
23+
object GetClientsClientIdAccountMapper :
24+
AbstractMapper<GetClientsClientIdAccountsResponse, ClientAccounts>() {
25+
26+
override fun mapFromEntity(entity: GetClientsClientIdAccountsResponse): ClientAccounts {
27+
return ClientAccounts().apply {
28+
savingsAccounts = entity.savingsAccounts?.map {
29+
SavingsAccount().apply {
30+
id = it.id
31+
accountNo = it.accountNo
32+
productId = it.productId
33+
productName = it.productName
34+
depositType = DepositType().apply {
35+
id = it.depositType!!.id
36+
code = it.depositType!!.code
37+
value = it.depositType!!.value
38+
}
39+
status = Status().apply {
40+
id = it.status?.id
41+
code = it.status?.code
42+
value = it.status?.value
43+
submittedAndPendingApproval = it.status?.submittedAndPendingApproval
44+
approved = it.status?.approved
45+
rejected = it.status?.rejected
46+
withdrawnByApplicant = it.status?.withdrawnByApplicant
47+
active = it.status?.active
48+
closed = it.status?.closed
49+
}
50+
currency = Currency().apply {
51+
code = it.currency!!.code
52+
name = it.currency!!.name
53+
nameCode = it.currency!!.nameCode
54+
decimalPlaces = it.currency!!.decimalPlaces
55+
displaySymbol = it.currency!!.displaySymbol
56+
displayLabel = it.currency!!.displayLabel
57+
}
58+
}
59+
}!!
60+
loanAccounts = entity.loanAccounts?.map {
61+
LoanAccount().apply {
62+
id = it.id
63+
accountNo = it.accountNo
64+
externalId = it.externalId.toString()
65+
productId = it.productId
66+
productName = it.productName
67+
status = com.mifos.objects.accounts.loan.Status().apply {
68+
id = it.status?.id
69+
code = it.status?.code
70+
value = it.status?.description
71+
pendingApproval = it.status?.pendingApproval
72+
waitingForDisbursal = it.status?.waitingForDisbursal
73+
active = it.status?.active
74+
closedObligationsMet = it.status?.closedObligationsMet
75+
closedWrittenOff = it.status?.closedWrittenOff
76+
closedRescheduled = it.status?.closedRescheduled
77+
closed = it.status?.closed
78+
overpaid = it.status?.overpaid
79+
}
80+
loanType = LoanType().apply {
81+
id = it.loanType?.id
82+
code = it.loanType?.code
83+
value = it.loanType?.description
84+
}
85+
loanCycle = it.loanCycle
86+
}
87+
}!!
88+
}
89+
}
90+
91+
override fun mapToEntity(domainModel: ClientAccounts): GetClientsClientIdAccountsResponse {
92+
return GetClientsClientIdAccountsResponse().apply {
93+
savingsAccounts = domainModel.savingsAccounts.map {
94+
GetClientsSavingsAccounts().apply {
95+
id = it.id
96+
accountNo = it.accountNo
97+
productId = it.productId
98+
productName = it.productName
99+
status = GetClientsSavingsAccountsStatus().apply {
100+
id = it.status?.id
101+
code = it.status?.code
102+
value = it.status?.value
103+
submittedAndPendingApproval = it.status?.submittedAndPendingApproval
104+
approved = it.status?.approved
105+
rejected = it.status?.rejected
106+
withdrawnByApplicant = it.status?.withdrawnByApplicant
107+
active = it.status?.active
108+
closed = it.status?.closed
109+
}
110+
currency = GetClientsSavingsAccountsCurrency().apply {
111+
code = it.currency!!.code
112+
name = it.currency!!.name
113+
nameCode = it.currency!!.nameCode
114+
decimalPlaces = it.currency!!.decimalPlaces
115+
displaySymbol = it.currency!!.displaySymbol
116+
displayLabel = it.currency!!.displayLabel
117+
}
118+
}
119+
}
120+
loanAccounts = domainModel.loanAccounts.map {
121+
GetClientsLoanAccounts().apply {
122+
id = it.id
123+
accountNo = it.accountNo
124+
externalId = it.externalId?.toInt()
125+
productId = it.productId
126+
productName = it.productName
127+
status = GetClientsLoanAccountsStatus().apply {
128+
id = it.status?.id
129+
code = it.status?.code
130+
description = it.status?.value
131+
pendingApproval = it.status?.pendingApproval
132+
waitingForDisbursal = it.status?.waitingForDisbursal
133+
active = it.status?.active
134+
closedObligationsMet = it.status?.closedObligationsMet
135+
closedWrittenOff = it.status?.closedWrittenOff
136+
closedRescheduled = it.status?.closedRescheduled
137+
closed = it.status?.closed
138+
overpaid = it.status?.overpaid
139+
}
140+
loanType = GetClientsLoanAccountsType().apply {
141+
id = it.loanType?.id
142+
code = it.loanType?.code
143+
description = it.loanType?.value
144+
}
145+
loanCycle = it.loanCycle
146+
}
147+
}
148+
}
149+
}
150+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.mifos.mappers.clients
2+
3+
import com.mifos.objects.noncore.DocumentType
4+
import com.mifos.objects.noncore.IdentifierTemplate
5+
import org.apache.fineract.client.models.GetClientsAllowedDocumentTypes
6+
import org.apache.fineract.client.models.GetClientsClientIdIdentifiersTemplateResponse
7+
import org.mifos.core.data.AbstractMapper
8+
9+
/**
10+
* Created by Aditya Gupta on 30/08/23.
11+
*/
12+
13+
object GetIdentifiersTemplateMapper :
14+
AbstractMapper<GetClientsClientIdIdentifiersTemplateResponse, IdentifierTemplate>() {
15+
16+
override fun mapFromEntity(entity: GetClientsClientIdIdentifiersTemplateResponse): IdentifierTemplate {
17+
return IdentifierTemplate().apply {
18+
allowedDocumentTypes = entity.allowedDocumentTypes?.map {
19+
DocumentType().apply {
20+
id = it.id
21+
name = it.name
22+
position = it.position
23+
}
24+
}
25+
}
26+
}
27+
28+
override fun mapToEntity(domainModel: IdentifierTemplate): GetClientsClientIdIdentifiersTemplateResponse {
29+
return GetClientsClientIdIdentifiersTemplateResponse().apply {
30+
allowedDocumentTypes = domainModel.allowedDocumentTypes?.map {
31+
GetClientsAllowedDocumentTypes().apply {
32+
id = it.id
33+
name = it.name
34+
position = it.position
35+
}
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)