Skip to content

Commit

Permalink
Fixes openMF#2035 : Fineract SDK Implementation : Client, Center,Data…
Browse files Browse the repository at this point in the history
…Table services (openMF#2039)

* Sdk implementation of client service

* Implemented sdk for center client group services
  • Loading branch information
Aditya-gupta99 authored Aug 31, 2023
1 parent 5f0ff47 commit 67a1f0c
Show file tree
Hide file tree
Showing 16 changed files with 352 additions and 39 deletions.
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.DatabaseHelperCenter
import com.mifos.mappers.centers.GetCentersResponseMapper
import com.mifos.mappers.offices.GetOfficeResponseMapper
import com.mifos.objects.accounts.CenterAccounts
import com.mifos.objects.client.ActivatePayload
import com.mifos.objects.client.Page
Expand All @@ -13,6 +14,9 @@ import com.mifos.objects.organisation.Office
import com.mifos.objects.response.SaveResponse
import com.mifos.services.data.CenterPayload
import com.mifos.utils.PrefManager.userStatus
import org.apache.fineract.client.models.PostCentersCenterIdRequest
import org.apache.fineract.client.models.PostCentersCenterIdResponse
import org.apache.fineract.client.models.PostClientsClientIdRequest
import rx.Observable
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -139,8 +143,10 @@ class DataManagerCenter @Inject constructor(
*/
val allDatabaseCenters: Observable<Page<Center>>
get() = mDatabaseHelperCenter.readAllCenters()

val offices: Observable<List<Office>>
get() = mBaseApiManager.officeApi.allOffices
get() = baseApiManager.getOfficeApi().retrieveOffices(null, null, null)
.map(GetOfficeResponseMapper::mapFromEntityList)

/**
* This method loading the all CenterPayloads from the Database.
Expand Down Expand Up @@ -181,7 +187,12 @@ class DataManagerCenter @Inject constructor(
fun activateCenter(
centerId: Int,
activatePayload: ActivatePayload?
): Observable<GenericResponse> {
return mBaseApiManager.centerApi.activateCenter(centerId, activatePayload)
): Observable<PostCentersCenterIdResponse> {
return baseApiManager.getCenterApi().activate2(centerId.toLong(),
PostCentersCenterIdRequest().apply {
closureDate = activatePayload?.activationDate
dateFormat = activatePayload?.dateFormat
locale = activatePayload?.locale
},"activate")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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.mappers.clients.GetClientsClientIdAccountMapper
import com.mifos.mappers.clients.GetIdentifiersTemplateMapper
import com.mifos.mappers.clients.IdentifierMapper
import com.mifos.objects.accounts.ClientAccounts
import com.mifos.objects.client.ActivatePayload
import com.mifos.objects.client.Client
Expand All @@ -19,6 +22,9 @@ import com.mifos.objects.templates.clients.ClientsTemplate
import com.mifos.utils.PrefManager.userStatus
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 rx.Observable
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -115,7 +121,9 @@ class DataManagerClient @Inject constructor(
*/
fun getClientAccounts(clientId: Int): Observable<ClientAccounts> {
return when (userStatus) {
false -> mBaseApiManager.clientsApi.getClientAccounts(clientId)
false -> baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong())
.map(GetClientsClientIdAccountMapper::mapFromEntity)

true ->
/**
* Return Clients from DatabaseHelperClient only one time.
Expand All @@ -133,7 +141,8 @@ class DataManagerClient @Inject constructor(
* @return ClientAccounts
*/
fun syncClientAccounts(clientId: Int): Observable<ClientAccounts> {
return mBaseApiManager.clientsApi.getClientAccounts(clientId)
return baseApiManager.getClientsApi().retrieveAssociatedAccounts(clientId.toLong())
.map(GetClientsClientIdAccountMapper::mapFromEntity)
.concatMap { clientAccounts ->
mDatabaseHelperClient.saveClientAccounts(
clientAccounts,
Expand Down Expand Up @@ -259,7 +268,8 @@ class DataManagerClient @Inject constructor(
* @return List<Identifier>
</Identifier> */
fun getClientIdentifiers(clientId: Int): Observable<List<Identifier>> {
return mBaseApiManager.clientsApi.getClientIdentifiers(clientId)
return baseApiManager.getClient().clientIdentifiers.retrieveAllClientIdentifiers(clientId.toLong())
.map(IdentifierMapper::mapFromEntityList)
}

/**
Expand All @@ -282,7 +292,8 @@ class DataManagerClient @Inject constructor(
* @return IdentifierTemplate
*/
fun getClientIdentifierTemplate(clientId: Int): Observable<IdentifierTemplate> {
return mBaseApiManager.clientsApi.getClientIdentifierTemplate(clientId)
return baseApiManager.getClient().clientIdentifiers.newClientIdentifierDetails(clientId.toLong())
.map(GetIdentifiersTemplateMapper::mapFromEntity)
}

/**
Expand All @@ -292,8 +303,8 @@ class DataManagerClient @Inject constructor(
* @param identifierId Identifier Id
* @return GenericResponse
*/
fun deleteClientIdentifier(clientId: Int, identifierId: Int): Observable<GenericResponse> {
return mBaseApiManager.clientsApi.deleteClientIdentifier(clientId, identifierId)
fun deleteClientIdentifier(clientId: Int, identifierId: Int): Observable<DeleteClientsClientIdIdentifiersIdentifierIdResponse> {
return baseApiManager.getClient().clientIdentifiers.deleteClientIdentifier(clientId.toLong(),identifierId.toLong())
}

/**
Expand Down Expand Up @@ -363,7 +374,12 @@ class DataManagerClient @Inject constructor(
fun activateClient(
clientId: Int,
clientActivate: ActivatePayload?
): Observable<GenericResponse> {
return mBaseApiManager.clientsApi.activateClient(clientId, clientActivate)
): Observable<PostClientsClientIdResponse> {
return baseApiManager.getClientsApi().activate1(clientId.toLong(),
PostClientsClientIdRequest().apply {
activationDate = clientActivate?.activationDate
dateFormat = clientActivate?.dateFormat
locale = clientActivate?.locale
},"activate")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import com.google.gson.JsonArray
import com.mifos.api.BaseApiManager
import com.mifos.api.GenericResponse
import com.mifos.api.local.databasehelper.DatabaseHelperDataTable
import com.mifos.mappers.dataTable.GetDataTablesResponseMapper
import com.mifos.objects.noncore.DataTable
import com.mifos.objects.user.UserLocation
import org.apache.fineract.client.models.DeleteDataTablesDatatableAppTableIdDatatableIdResponse
import org.apache.fineract.client.models.GetDataTablesResponse
import rx.Observable
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -19,7 +22,8 @@ import javax.inject.Singleton
@Singleton
class DataManagerDataTable @Inject constructor(
val mBaseApiManager: BaseApiManager,
val mDatabaseHelperDataTable: DatabaseHelperDataTable
val mDatabaseHelperDataTable: DatabaseHelperDataTable,
private val baseApiManager: org.mifos.core.apimanager.BaseApiManager
) {
/**
* This Method Request the REST API of Datatable and In response give the List of DataTable
Expand All @@ -31,7 +35,8 @@ class DataManagerDataTable @Inject constructor(
* @return List<DataTable>
</DataTable> */
fun getDataTable(tableName: String?): Observable<List<DataTable>> {
return mBaseApiManager.dataTableApi.getTableOf(tableName)
return baseApiManager.getDataTableApi().getDatatables(tableName).map(
GetDataTablesResponseMapper::mapFromEntityList)
}

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

fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int): Observable<GenericResponse> {
return mBaseApiManager.dataTableApi.deleteEntryOfDataTableManyToMany(
table, entity, rowId
)
fun deleteDataTableEntry(table: String?, entity: Int, rowId: Int): Observable<DeleteDataTablesDatatableAppTableIdDatatableIdResponse> {
return baseApiManager.getDataTableApi().deleteDatatableEntries1(table,entity.toLong(),rowId.toLong())
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.mifos.mappers.clients

import com.mifos.objects.accounts.ClientAccounts
import com.mifos.objects.accounts.loan.LoanAccount
import com.mifos.objects.accounts.loan.LoanType
import com.mifos.objects.accounts.savings.Currency
import com.mifos.objects.accounts.savings.DepositType
import com.mifos.objects.accounts.savings.SavingsAccount
import com.mifos.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

/**
* Created by Aditya Gupta on 30/08/23.
*/

object GetClientsClientIdAccountMapper :
AbstractMapper<GetClientsClientIdAccountsResponse, ClientAccounts>() {

override fun mapFromEntity(entity: GetClientsClientIdAccountsResponse): ClientAccounts {
return ClientAccounts().apply {
savingsAccounts = entity.savingsAccounts?.map {
SavingsAccount().apply {
id = it.id
accountNo = it.accountNo
productId = it.productId
productName = it.productName
depositType = DepositType().apply {
id = it.depositType!!.id
code = it.depositType!!.code
value = it.depositType!!.value
}
status = Status().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
closed = it.status?.closed
}
currency = Currency().apply {
code = it.currency!!.code
name = it.currency!!.name
nameCode = it.currency!!.nameCode
decimalPlaces = it.currency!!.decimalPlaces
displaySymbol = it.currency!!.displaySymbol
displayLabel = it.currency!!.displayLabel
}
}
}!!
loanAccounts = entity.loanAccounts?.map {
LoanAccount().apply {
id = it.id
accountNo = it.accountNo
externalId = it.externalId.toString()
productId = it.productId
productName = it.productName
status = com.mifos.objects.accounts.loan.Status().apply {
id = it.status?.id
code = it.status?.code
value = it.status?.description
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 = LoanType().apply {
id = it.loanType?.id
code = it.loanType?.code
value = it.loanType?.description
}
loanCycle = it.loanCycle
}
}!!
}
}

override fun mapToEntity(domainModel: ClientAccounts): GetClientsClientIdAccountsResponse {
return GetClientsClientIdAccountsResponse().apply {
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
closed = it.status?.closed
}
currency = GetClientsSavingsAccountsCurrency().apply {
code = it.currency!!.code
name = it.currency!!.name
nameCode = it.currency!!.nameCode
decimalPlaces = it.currency!!.decimalPlaces
displaySymbol = it.currency!!.displaySymbol
displayLabel = it.currency!!.displayLabel
}
}
}
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
description = it.loanType?.value
}
loanCycle = it.loanCycle
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mifos.mappers.clients

import com.mifos.objects.noncore.DocumentType
import com.mifos.objects.noncore.IdentifierTemplate
import org.apache.fineract.client.models.GetClientsAllowedDocumentTypes
import org.apache.fineract.client.models.GetClientsClientIdIdentifiersTemplateResponse
import org.mifos.core.data.AbstractMapper

/**
* Created by Aditya Gupta on 30/08/23.
*/

object GetIdentifiersTemplateMapper :
AbstractMapper<GetClientsClientIdIdentifiersTemplateResponse, IdentifierTemplate>() {

override fun mapFromEntity(entity: GetClientsClientIdIdentifiersTemplateResponse): IdentifierTemplate {
return IdentifierTemplate().apply {
allowedDocumentTypes = entity.allowedDocumentTypes?.map {
DocumentType().apply {
id = it.id
name = it.name
position = it.position
}
}
}
}

override fun mapToEntity(domainModel: IdentifierTemplate): GetClientsClientIdIdentifiersTemplateResponse {
return GetClientsClientIdIdentifiersTemplateResponse().apply {
allowedDocumentTypes = domainModel.allowedDocumentTypes?.map {
GetClientsAllowedDocumentTypes().apply {
id = it.id
name = it.name
position = it.position
}
}
}
}
}
Loading

0 comments on commit 67a1f0c

Please sign in to comment.