MIFOSX-97: continue tidy up of serialization.

This commit is contained in:
Keith Woodlock
2012-12-04 18:02:31 +00:00
parent bb6ef42b41
commit 26470d026d
15 changed files with 235 additions and 365 deletions
@@ -0,0 +1 @@
ALTER TABLE `m_portfolio_command_source` CHANGE COLUMN `api_resource` `api_resource` VARCHAR(100) NOT NULL;
@@ -1,6 +1,8 @@
package org.mifosplatform.commands.api; package org.mifosplatform.commands.api;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@@ -19,10 +21,11 @@ import org.apache.commons.lang.StringUtils;
import org.mifosplatform.commands.data.CommandSourceData; import org.mifosplatform.commands.data.CommandSourceData;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService; import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@@ -33,40 +36,45 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class CommandsApiResource { public class CommandsApiResource {
@Autowired private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "taskName", "madeOnDate"));
private PortfolioCommandsReadPlatformService readPlatformService; private final String resourceNameForPermissions = "MAKERCHECKER";
private final PlatformSecurityContext context;
private final PortfolioCommandsReadPlatformService readPlatformService;
private final DefaultToApiJsonSerializer<CommandSourceData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService writePlatformService;
@Autowired @Autowired
private PortfolioCommandSourceWritePlatformService writePlatformService; public CommandsApiResource(final PlatformSecurityContext context, final PortfolioCommandsReadPlatformService readPlatformService,
final DefaultToApiJsonSerializer<CommandSourceData> toApiJsonSerializer,
@Autowired final ApiRequestParameterHelper apiRequestParameterHelper,
private PortfolioApiJsonSerializerService apiJsonSerializerService; final PortfolioCommandSourceWritePlatformService writePlatformService) {
this.context = context;
private final String entityType = "MAKERCHECKER"; this.readPlatformService = readPlatformService;
@Autowired this.toApiJsonSerializer = toApiJsonSerializer;
private PlatformSecurityContext context; this.apiRequestParameterHelper = apiRequestParameterHelper;
this.writePlatformService = writePlatformService;
}
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveCodes(@Context final UriInfo uriInfo) { public String retrieveCodes(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<CommandSourceData> entries = this.readPlatformService.retrieveAllEntriesToBeChecked(); final Collection<CommandSourceData> entries = this.readPlatformService.retrieveAllEntriesToBeChecked();
return this.apiJsonSerializerService.serializeMakerCheckerDataToJson(prettyPrint, responseParameters, entries); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, entries, RESPONSE_DATA_PARAMETERS);
} }
@POST @POST
@Path("{commandId}") @Path("{commandId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String approveMakerCheckerEntry(@PathParam("commandId") final Long commandId, public String approveMakerCheckerEntry(@PathParam("commandId") final Long commandId, @QueryParam("command") final String commandParam) {
@QueryParam("command") final String commandParam) {
EntityIdentifier result = null; EntityIdentifier result = null;
if (is(commandParam, "approve")) { if (is(commandParam, "approve")) {
@@ -75,7 +83,7 @@ public class CommandsApiResource {
throw new UnrecognizedQueryParamException("command", commandParam); throw new UnrecognizedQueryParamException("command", commandParam);
} }
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
private boolean is(final String commandParam, final String commandValue) { private boolean is(final String commandParam, final String commandValue) {
@@ -90,6 +98,6 @@ public class CommandsApiResource {
final Long id = this.writePlatformService.deleteEntry(commandId); final Long id = this.writePlatformService.deleteEntry(commandId);
return this.apiJsonSerializerService.serializeEntityIdentifier(EntityIdentifier.makerChecker(id)); return this.toApiJsonSerializer.serialize(EntityIdentifier.makerChecker(id));
} }
} }
@@ -1,8 +1,8 @@
package org.mifosplatform.commands.service; package org.mifosplatform.commands.service;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer; import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.portfolio.client.command.ClientCommand; import org.mifosplatform.portfolio.client.command.ClientCommand;
import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
@@ -13,19 +13,17 @@ import org.springframework.stereotype.Service;
public class ChangeDetectionServiceJdbc implements ChangeDetectionService { public class ChangeDetectionServiceJdbc implements ChangeDetectionService {
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final ClientReadPlatformService clientReadPlatformService; private final ClientReadPlatformService clientReadPlatformService;
private final CommandSerializer commandSerializerService; private final CommandSerializer commandSerializerService;
private final DefaultToApiJsonSerializer<ClientData> toApiJsonSerializer;
@Autowired @Autowired
public ChangeDetectionServiceJdbc( public ChangeDetectionServiceJdbc(final DefaultToApiJsonSerializer<ClientData> toApiJsonSerializer,
final PortfolioApiDataConversionService apiDataConversionService, final PortfolioApiDataConversionService apiDataConversionService, final CommandSerializer commandSerializerService,
final CommandSerializer commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
final ClientReadPlatformService clientReadPlatformService) { final ClientReadPlatformService clientReadPlatformService) {
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService; this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService;
this.clientReadPlatformService = clientReadPlatformService; this.clientReadPlatformService = clientReadPlatformService;
} }
@@ -36,16 +34,17 @@ public class ChangeDetectionServiceJdbc implements ChangeDetectionService {
if ("clients".equalsIgnoreCase(resourceName)) { if ("clients".equalsIgnoreCase(resourceName)) {
// FIXME - KW/JW - this change detection code for update of clients // FIXME - KW/JW - this change detection code for update of clients
// using ClientCommand can re placed when more suitable sql version is // using ClientCommand can re placed when more suitable sql version
// is
// implemented. // implemented.
final ClientData originalClient = this.clientReadPlatformService.retrieveIndividualClient(resourceId); final ClientData originalClient = this.clientReadPlatformService.retrieveIndividualClient(resourceId);
final ClientData changedClient = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(resourceId, final ClientData changedClient = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(resourceId,
commandSerializedAsJson); commandSerializedAsJson);
final String baseJson = this.apiJsonSerializerService.serializeClientDataToJson(originalClient); final String baseJson = this.toApiJsonSerializer.serialize(originalClient);
final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient); final String workingJson = this.toApiJsonSerializer.serialize(changedClient);
final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson); final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson);
changesOnlyJson = this.commandSerializerService.serializeCommandToJson(changesOnly); changesOnlyJson = this.commandSerializerService.serializeCommandToJson(changesOnly);
} else { } else {
changesOnlyJson = commandSerializedAsJson; changesOnlyJson = commandSerializedAsJson;
@@ -5,8 +5,6 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.mifosplatform.commands.data.CommandSourceData;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.serialization.GoogleGsonSerializerHelper; import org.mifosplatform.infrastructure.core.serialization.GoogleGsonSerializerHelper;
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData; import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData; import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
@@ -14,19 +12,14 @@ import org.mifosplatform.infrastructure.documentmanagement.data.DocumentData;
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData; import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData; import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData;
import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.organisation.staff.data.StaffData;
import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData; import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.data.ClientIdentifierData;
import org.mifosplatform.portfolio.client.data.NoteData; import org.mifosplatform.portfolio.client.data.NoteData;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
import org.mifosplatform.portfolio.group.data.GroupData; import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData;
import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData; import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData;
import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData; import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData;
import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData;
import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductData;
import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData; import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData;
import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData; import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData;
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData; import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData;
@@ -46,13 +39,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
private static final Set<String> STAFF_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "firstname", "lastname", private static final Set<String> STAFF_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "firstname", "lastname",
"displayName", "officeId", "officeName", "loanOfficerFlag", "allowedOffices")); "displayName", "officeId", "officeName", "loanOfficerFlag", "allowedOffices"));
private static final Set<String> LOAN_PRODUCT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
"fundId", "fundName", "transactionProcessingStrategyId", "transactionProcessingStrategyName", "principal",
"inArrearsTolerance", "numberOfRepayments", "repaymentEvery", "interestRatePerPeriod", "annualInterestRate",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
"charges", "createdOn", "lastModifedOn", "currencyOptions", "amortizationTypeOptions", "interestTypeOptions",
"interestCalculationPeriodTypeOptions", "repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions",
"transactionProcessingStrategyOptions", "chargeOptions"));
private static final Set<String> SAVINGS_PRODUCT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("currencyOptions", "id", private static final Set<String> SAVINGS_PRODUCT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("currencyOptions", "id",
"createdOn", "lastModifedOn", "locale", "name", "description", "currencyCode", "digitsAfterDecimal", "interstRate", "createdOn", "lastModifedOn", "locale", "name", "description", "currencyCode", "digitsAfterDecimal", "interstRate",
@@ -76,12 +62,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
"interestCompoundingAllowed", "availableInterestForWithdrawal", "availableWithdrawalAmount", "todaysDate", "interestCompoundingAllowed", "availableInterestForWithdrawal", "availableWithdrawalAmount", "todaysDate",
"isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType")); "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType"));
private static final Set<String> CLIENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName",
"externalId", "firstname", "lastname", "joinedDate", "displayName", "clientOrBusinessName", "allowedOffices", "imagePresent"));
private static final Set<String> CLIENT_IDENTIFIER_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "clientId",
"documentTypeId", "documentKey", "description", "documentTypeName", "allowedDocumentTypes"));
private static final Set<String> DOCUMENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "parentEntityType", private static final Set<String> DOCUMENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "parentEntityType",
"parentEntityId", "name", "fileName", "type", "size", "description")); "parentEntityId", "name", "fileName", "type", "size", "description"));
@@ -106,31 +86,14 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
private static final Set<String> LOAN_SCHEDULE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("periods", private static final Set<String> LOAN_SCHEDULE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("periods",
"cumulativePrincipalDisbursed")); "cumulativePrincipalDisbursed"));
private static final Set<String> LOAN_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "externalId", "clientId", "groupId",
"clientName", "groupName", "fundId", "fundName", "loanProductId", "loanProductName", "loanProductDescription", "currency",
"principal", "inArrearsTolerance", "numberOfRepayments", "repaymentEvery", "interestRatePerPeriod", "annualInterestRate",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
"submittedOnDate", "approvedOnDate", "expectedDisbursementDate", "actualDisbursementDate", "expectedFirstRepaymentOnDate",
"interestChargedFromDate", "closedOnDate", "expectedMaturityDate", "status", "lifeCycleStatusDate", "repaymentSchedule",
"transactions", "permissions", "convenienceData", "charges", "productOptions", "amortizationTypeOptions",
"interestTypeOptions", "interestCalculationPeriodTypeOptions", "repaymentFrequencyTypeOptions",
"interestRateFrequencyTypeOptions", "fundOptions", "repaymentStrategyOptions", "chargeOptions", "loanOfficerId",
"loanOfficerName", "loanOfficerOptions", "chargeTemplate"));
private static final Set<String> LOAN_TRANSACTION_NEW_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "type", "date", private static final Set<String> LOAN_TRANSACTION_NEW_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "type", "date",
"currency", "amount")); "currency", "amount"));
private static final Set<String> LOAN_REASSIGNMENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("officeId", "fromLoanOfficerId", private static final Set<String> LOAN_REASSIGNMENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("officeId", "fromLoanOfficerId",
"assignmentDate", "officeOptions", "loanOfficerOptions", "accountSummaryCollection")); "assignmentDate", "officeOptions", "loanOfficerOptions", "accountSummaryCollection"));
private static final Set<String> CHARGES_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "amount", "currency",
"penalty", "active", "chargeAppliesTo", "chargeTimeType", "chargeCalculationType", "chargeCalculationTypeOptions",
"chargeAppliesToOptions", "chargeTimeTypeOptions", "currencyOptions"));
private static final Set<String> LOAN_CHARGES_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("chargeOptions")); private static final Set<String> LOAN_CHARGES_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("chargeOptions"));
private static final Set<String> MAKER_CHECKER_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "taskName", "madeOnDate"));
private static final Set<String> SAVINGS_ACCOUNTS_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "status", "externalId", private static final Set<String> SAVINGS_ACCOUNTS_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "status", "externalId",
"clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod", "clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod",
"savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType", "savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType",
@@ -143,9 +106,8 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
private static final Set<String> GUARANTOR_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId", private static final Set<String> GUARANTOR_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("externalGuarantor", "existingClientId",
"firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber", "firstname", "lastname", "addressLine1", "addressLine2", "city", "state", "zip", "country", "mobileNumber", "housePhoneNumber",
"comment", "dob")); "comment", "dob"));
private static final Set<String> SAVING_SCHEDULE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("periods", private static final Set<String> SAVING_SCHEDULE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("periods", "cumulativeDepositDue"));
"cumulativeDepositDue"));
private final GoogleGsonSerializerHelper helper; private final GoogleGsonSerializerHelper helper;
@@ -172,22 +134,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, datatables.toArray(new DatatableData[datatables.size()])); return helper.serializedJsonFrom(gsonDeserializer, datatables.toArray(new DatatableData[datatables.size()]));
} }
@Override
public String serializeLoanProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final Collection<LoanProductData> products) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(LOAN_PRODUCT_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, products.toArray(new LoanProductData[products.size()]));
}
@Override
public String serializeLoanProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final LoanProductData product) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(LOAN_PRODUCT_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, product);
}
@Override @Override
public String serializeSavingProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters, public String serializeSavingProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final Collection<SavingProductData> products) { final Collection<SavingProductData> products) {
@@ -236,26 +182,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, account); return helper.serializedJsonFrom(gsonDeserializer, account);
} }
@Override
public String serializeClientDataToJson(final ClientData client) {
return serializeClientDataToJson(false, new HashSet<String>(), client);
}
@Override
public String serializeClientDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final ClientData client) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(CLIENT_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, client);
}
@Override
public String serializeClientDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final Collection<ClientData> clients) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(CLIENT_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, clients.toArray(new ClientData[clients.size()]));
}
@Override @Override
public String serializeClientAccountSummaryCollectionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, public String serializeClientAccountSummaryCollectionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final ClientAccountSummaryCollectionData clientAccount) { final ClientAccountSummaryCollectionData clientAccount) {
@@ -309,14 +235,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, loanSchedule); return helper.serializedJsonFrom(gsonDeserializer, loanSchedule);
} }
@Override
public String serializeLoanAccountDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final LoanAccountData loanAccount) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(LOAN_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, loanAccount);
}
@Override @Override
public String serializeLoanTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, public String serializeLoanTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final LoanTransactionData transaction) { final LoanTransactionData transaction) {
@@ -333,21 +251,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, loanReassignmentData); return helper.serializedJsonFrom(gsonDeserializer, loanReassignmentData);
} }
@Override
public String serializeChargeDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final Collection<ChargeData> charges) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(CHARGES_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, charges.toArray(new ChargeData[charges.size()]));
}
@Override
public String serializeChargeDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final ChargeData charge) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(CHARGES_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, charge);
}
@Override @Override
public String serializeLoanChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanChargeData charge) { public String serializeLoanChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanChargeData charge) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(LOAN_CHARGES_DATA_PARAMETERS, final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(LOAN_CHARGES_DATA_PARAMETERS,
@@ -369,31 +272,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, staff.toArray(new StaffData[staff.size()])); return helper.serializedJsonFrom(gsonDeserializer, staff.toArray(new StaffData[staff.size()]));
} }
@Deprecated
@Override
public String serializeEntityIdentifier(final EntityIdentifier identifier) {
final Set<String> DATA_PARAMETERS = new HashSet<String>(Arrays.asList("entityId"));
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(DATA_PARAMETERS, false,
DATA_PARAMETERS);
return helper.serializedJsonFrom(gsonDeserializer, identifier);
}
@Override
public String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters,
Collection<ClientIdentifierData> clientIdentifiers) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(
CLIENT_IDENTIFIER_DATA_PARAMETERS, prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, clientIdentifiers.toArray(new ClientIdentifierData[clientIdentifiers.size()]));
}
@Override
public String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters,
ClientIdentifierData clientIdentifierData) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(
CLIENT_IDENTIFIER_DATA_PARAMETERS, prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, clientIdentifierData);
}
@Override @Override
public String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DocumentData> documentDatas) { public String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DocumentData> documentDatas) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(DOCUMENT_DATA_PARAMETERS, final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(DOCUMENT_DATA_PARAMETERS,
@@ -408,14 +286,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, documentData); return helper.serializedJsonFrom(gsonDeserializer, documentData);
} }
@Override
public String serializeMakerCheckerDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
final Collection<CommandSourceData> entries) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(MAKER_CHECKER_DATA_PARAMETERS,
prettyPrint, responseParameters);
return helper.serializedJsonFrom(gsonDeserializer, entries.toArray(new CommandSourceData[entries.size()]));
}
@Override @Override
public String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingAccountData account) { public String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingAccountData account) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVINGS_ACCOUNTS_DATA_PARAMETERS, final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVINGS_ACCOUNTS_DATA_PARAMETERS,
@@ -438,10 +308,11 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
return helper.serializedJsonFrom(gsonDeserializer, guarantorData); return helper.serializedJsonFrom(gsonDeserializer, guarantorData);
} }
@Override @Override
public String serializeSavingScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingScheduleData savingScheduleData) { public String serializeSavingScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters,
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVING_SCHEDULE_DATA_PARAMETERS, SavingScheduleData savingScheduleData) {
prettyPrint, responseParameters); final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVING_SCHEDULE_DATA_PARAMETERS,
return helper.serializedJsonFrom(gsonDeserializer, savingScheduleData); prettyPrint, responseParameters);
} return helper.serializedJsonFrom(gsonDeserializer, savingScheduleData);
}
} }
@@ -3,28 +3,20 @@ package org.mifosplatform.infrastructure.core.api;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import org.mifosplatform.commands.data.CommandSourceData;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData; import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData; import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
import org.mifosplatform.infrastructure.documentmanagement.data.DocumentData; import org.mifosplatform.infrastructure.documentmanagement.data.DocumentData;
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData; import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData; import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData;
import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.organisation.staff.data.StaffData;
import org.mifosplatform.portfolio.charge.data.ChargeData;
import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData; import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionData;
import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.data.ClientIdentifierData;
import org.mifosplatform.portfolio.client.data.NoteData; import org.mifosplatform.portfolio.client.data.NoteData;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
import org.mifosplatform.portfolio.group.data.GroupData; import org.mifosplatform.portfolio.group.data.GroupData;
import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData;
import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData; import org.mifosplatform.portfolio.loanaccount.data.LoanChargeData;
import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData; import org.mifosplatform.portfolio.loanaccount.data.LoanTransactionData;
import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData;
import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData; import org.mifosplatform.portfolio.loanaccount.loanschedule.data.LoanScheduleData;
import org.mifosplatform.portfolio.loanproduct.data.LoanProductData;
import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData; import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData;
import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData; import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData;
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData; import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData;
@@ -39,10 +31,6 @@ public interface PortfolioApiJsonSerializerService {
String serializeDatatableDataToJson(boolean prettyPrint, Collection<DatatableData> result); String serializeDatatableDataToJson(boolean prettyPrint, Collection<DatatableData> result);
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<LoanProductData> products);
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanProductData loanProduct);
String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingProductData> products); String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingProductData> products);
String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingProductData savingProduct); String serializeSavingProductDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingProductData savingProduct);
@@ -55,12 +43,6 @@ public interface PortfolioApiJsonSerializerService {
String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData account); String serializeDepositAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, DepositAccountData account);
String serializeClientDataToJson(ClientData clientData);
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientData clientData);
String serializeClientDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ClientData> clients);
String serializeClientAccountSummaryCollectionDataToJson(boolean prettyPrint, Set<String> responseParameters, String serializeClientAccountSummaryCollectionDataToJson(boolean prettyPrint, Set<String> responseParameters,
ClientAccountSummaryCollectionData clientAccount); ClientAccountSummaryCollectionData clientAccount);
@@ -77,49 +59,27 @@ public interface PortfolioApiJsonSerializerService {
String serializeLoanScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanScheduleData loanSchedule); String serializeLoanScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanScheduleData loanSchedule);
String serializeLoanAccountDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanAccountData loanAccount);
String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData newTransactionData); String serializeLoanTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanTransactionData newTransactionData);
String serializeLoanReassignmentDataToJson(boolean prettyPrint, Set<String> responseParameters, String serializeLoanReassignmentDataToJson(boolean prettyPrint, Set<String> responseParameters,
BulkTransferLoanOfficerData loanReassignmentData); BulkTransferLoanOfficerData loanReassignmentData);
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<ChargeData> charges);
String serializeChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, ChargeData charge);
String serializeLoanChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanChargeData charge); String serializeLoanChargeDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanChargeData charge);
String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, StaffData staff); String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, StaffData staff);
String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<StaffData> staff); String serializeStaffDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<StaffData> staff);
/**
* @deprecated see
* {@link CodesToApiJsonSerializer#serialize(EntityIdentifier)}
* for example for what to use now.
*/
@Deprecated
String serializeEntityIdentifier(EntityIdentifier identifier);
String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters,
Collection<ClientIdentifierData> clientIdentifiers);
String serializeClientIdentifierDataToJson(boolean prettyPrint, Set<String> responseParameters,
ClientIdentifierData clientIdentifierData);
String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DocumentData> documentDatas); String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<DocumentData> documentDatas);
String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, DocumentData documentData); String serializeDocumentDataToJson(boolean prettyPrint, Set<String> responseParameters, DocumentData documentData);
String serializeMakerCheckerDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<CommandSourceData> entries);
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingAccountData account); String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingAccountData account);
String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingAccountData> accounts); String serializeSavingAccountsDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<SavingAccountData> accounts);
String serializeGuarantorDataToJson(boolean prettyPrint, Set<String> responseParameters, GuarantorData guarantorData); String serializeGuarantorDataToJson(boolean prettyPrint, Set<String> responseParameters, GuarantorData guarantorData);
String serializeSavingScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingScheduleData savingScheduleData); String serializeSavingScheduleDataToJson(boolean prettyPrint, Set<String> responseParameters, SavingScheduleData savingScheduleData);
} }
@@ -152,7 +152,7 @@ public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCo
Long actualClientId = clientId; Long actualClientId = clientId;
final Long clientIdInternal = helper.extractLongNamed("clientId", element, parametersPassedInRequest); final Long clientIdInternal = helper.extractLongNamed("clientId", element, parametersPassedInRequest);
if (clientId != null) { if (clientIdInternal != null) {
actualClientId = clientIdInternal; actualClientId = clientIdInternal;
} }
final Long documentTypeId = helper.extractLongNamed("documentTypeId", element, parametersPassedInRequest); final Long documentTypeId = helper.extractLongNamed("documentTypeId", element, parametersPassedInRequest);
@@ -2,6 +2,7 @@ package org.mifosplatform.portfolio.charge.api;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -18,11 +19,12 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer; import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand; import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.data.ChargeData;
@@ -36,27 +38,35 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class ChargesApiResource { public class ChargesApiResource {
private final Set<String> CHARGES_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "amount", "currency",
"penalty", "active", "chargeAppliesTo", "chargeTimeType", "chargeCalculationType", "chargeCalculationTypeOptions",
"chargeAppliesToOptions", "chargeTimeTypeOptions", "currencyOptions"));
private final String resourceNameForPermissions = "CHARGE"; private final String resourceNameForPermissions = "CHARGE";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ChargeReadPlatformService readPlatformService; private final ChargeReadPlatformService readPlatformService;
private final DefaultToApiJsonSerializer<ChargeData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final CommandSerializer commandSerializerService; private final CommandSerializer commandSerializerService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
public ChargesApiResource(final PlatformSecurityContext context, public ChargesApiResource(final PlatformSecurityContext context,
final ChargeReadPlatformService readPlatformService, final ChargeReadPlatformService readPlatformService,
final DefaultToApiJsonSerializer<ChargeData> toApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioApiDataConversionService apiDataConversionService, final PortfolioApiDataConversionService apiDataConversionService,
final CommandSerializer commandSerializerService, final CommandSerializer commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context; this.context = context;
this.readPlatformService = readPlatformService; this.readPlatformService = readPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService; this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
} }
@@ -67,12 +77,10 @@ public class ChargesApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<ChargeData> charges = this.readPlatformService.retrieveAllCharges(); final Collection<ChargeData> charges = this.readPlatformService.retrieveAllCharges();
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charges); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, charges, CHARGES_DATA_PARAMETERS);
} }
@GET @GET
@@ -83,18 +91,15 @@ public class ChargesApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
ChargeData charge = this.readPlatformService.retrieveCharge(chargeId); ChargeData charge = this.readPlatformService.retrieveCharge(chargeId);
if (template) { if (settings.isTemplate()) {
ChargeData templateData = this.readPlatformService.retrieveNewChargeDetails(); ChargeData templateData = this.readPlatformService.retrieveNewChargeDetails();
charge = new ChargeData(charge, templateData); charge = new ChargeData(charge, templateData);
} }
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charge); return this.toApiJsonSerializer.serialize(settings, charge, CHARGES_DATA_PARAMETERS);
} }
@GET @GET
@@ -105,13 +110,10 @@ public class ChargesApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final ChargeData charge = this.readPlatformService.retrieveNewChargeDetails();
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, charge, CHARGES_DATA_PARAMETERS);
final ChargeData chargeData = this.readPlatformService.retrieveNewChargeDetails();
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, chargeData);
} }
@POST @POST
@@ -127,7 +129,7 @@ public class ChargesApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "charges", null, commandSerializedAsJson); final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "charges", null, commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
@PUT @PUT
@@ -144,7 +146,7 @@ public class ChargesApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "charges", chargeId, commandSerializedAsJson); final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "charges", chargeId, commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
@DELETE @DELETE
@@ -158,6 +160,6 @@ public class ChargesApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "charges", chargeId, "{}"); final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "charges", chargeId, "{}");
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
} }
@@ -2,6 +2,7 @@ package org.mifosplatform.portfolio.client.api;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -20,11 +21,12 @@ import javax.ws.rs.core.UriInfo;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService; import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer; import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.client.command.ClientIdentifierCommand; import org.mifosplatform.portfolio.client.command.ClientIdentifierCommand;
import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.data.ClientData;
@@ -40,29 +42,34 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class ClientIdentifiersApiResource { public class ClientIdentifiersApiResource {
private final String entityType = "CLIENTIDENTIFIER"; private static final Set<String> CLIENT_IDENTIFIER_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "clientId",
"documentTypeId", "documentKey", "description", "documentTypeName", "allowedDocumentTypes"));
private final String resourceNameForPermissions = "CLIENTIDENTIFIER";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ClientReadPlatformService clientReadPlatformService; private final ClientReadPlatformService clientReadPlatformService;
private final CodeValueReadPlatformService codeValueReadPlatformService; private final CodeValueReadPlatformService codeValueReadPlatformService;
private final DefaultToApiJsonSerializer<ClientIdentifierData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final CommandSerializer commandSerializerService; private final CommandSerializer commandSerializerService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired @Autowired
public ClientIdentifiersApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService, public ClientIdentifiersApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService,
final CodeValueReadPlatformService codeValueReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService,
final PortfolioApiDataConversionService apiDataConversionService, final DefaultToApiJsonSerializer<ClientIdentifierData> toApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioApiDataConversionService apiDataConversionService,
final CommandSerializer commandSerializerService, final CommandSerializer commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context; this.context = context;
this.clientReadPlatformService = readPlatformService; this.clientReadPlatformService = readPlatformService;
this.codeValueReadPlatformService = codeValueReadPlatformService; this.codeValueReadPlatformService = codeValueReadPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService; this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
} }
@@ -71,14 +78,12 @@ public class ClientIdentifiersApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllClientIdentifiers(@Context final UriInfo uriInfo, @PathParam("clientId") final Long clientId) { public String retrieveAllClientIdentifiers(@Context final UriInfo uriInfo, @PathParam("clientId") final Long clientId) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<ClientIdentifierData> clientIdentifiers = this.clientReadPlatformService.retrieveClientIdentifiers(clientId); final Collection<ClientIdentifierData> clientIdentifiers = this.clientReadPlatformService.retrieveClientIdentifiers(clientId);
return this.apiJsonSerializerService.serializeClientIdentifierDataToJson(prettyPrint, responseParameters, clientIdentifiers); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, clientIdentifiers, CLIENT_IDENTIFIER_DATA_PARAMETERS);
} }
@GET @GET
@@ -87,15 +92,13 @@ public class ClientIdentifiersApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String newClientDetails(@Context final UriInfo uriInfo) { public String newClientDetails(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues(); Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues();
ClientIdentifierData clientIdentifierData = ClientIdentifierData.template(codeValues); ClientIdentifierData clientIdentifierData = ClientIdentifierData.template(codeValues);
return this.apiJsonSerializerService.serializeClientIdentifierDataToJson(prettyPrint, responseParameters, clientIdentifierData); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, clientIdentifierData, CLIENT_IDENTIFIER_DATA_PARAMETERS);
} }
@POST @POST
@@ -116,7 +119,7 @@ public class ClientIdentifiersApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", resourceUrl, null, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", resourceUrl, null,
commandSerializedAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} catch (DuplicateClientIdentifierException e) { } catch (DuplicateClientIdentifierException e) {
DuplicateClientIdentifierException rethrowas = e; DuplicateClientIdentifierException rethrowas = e;
if (e.getDocumentTypeId() != null) { if (e.getDocumentTypeId() != null) {
@@ -137,19 +140,17 @@ public class ClientIdentifiersApiResource {
public String getClientIdentifier(@PathParam("clientId") final Long clientId, @PathParam("identifierId") final Long clientIdentifierId, public String getClientIdentifier(@PathParam("clientId") final Long clientId, @PathParam("identifierId") final Long clientIdentifierId,
@Context final UriInfo uriInfo) { @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(entityType); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId); ClientIdentifierData clientIdentifierData = this.clientReadPlatformService.retrieveClientIdentifier(clientId, clientIdentifierId);
if (template) { if (settings.isTemplate()) {
final Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues(); final Collection<CodeValueData> codeValues = codeValueReadPlatformService.retrieveCustomIdentifierCodeValues();
clientIdentifierData = ClientIdentifierData.template(clientIdentifierData, codeValues); clientIdentifierData = ClientIdentifierData.template(clientIdentifierData, codeValues);
} }
return this.apiJsonSerializerService.serializeClientIdentifierDataToJson(prettyPrint, responseParameters, clientIdentifierData); return this.toApiJsonSerializer.serialize(settings, clientIdentifierData, CLIENT_IDENTIFIER_DATA_PARAMETERS);
} }
@PUT @PUT
@@ -172,7 +173,7 @@ public class ClientIdentifiersApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", resourceUrl, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", resourceUrl,
clientIdentifierId, commandSerializedAsJson); clientIdentifierId, commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} catch (DuplicateClientIdentifierException e) { } catch (DuplicateClientIdentifierException e) {
DuplicateClientIdentifierException reThrowAs = e; DuplicateClientIdentifierException reThrowAs = e;
if (e.getDocumentTypeId() != null) { if (e.getDocumentTypeId() != null) {
@@ -200,6 +201,6 @@ public class ClientIdentifiersApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", resourceUrl, clientIdentifierId, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", resourceUrl, clientIdentifierId,
"{}"); "{}");
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
} }
@@ -4,6 +4,7 @@ import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -19,7 +20,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@@ -28,11 +28,14 @@ import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformSer
import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService; import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiConstants; import org.mifosplatform.infrastructure.core.api.ApiConstants;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.domain.Base64EncodedImage; import org.mifosplatform.infrastructure.core.domain.Base64EncodedImage;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer; import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.core.service.FileUtils; import org.mifosplatform.infrastructure.core.service.FileUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.office.data.OfficeLookup; import org.mifosplatform.organisation.office.data.OfficeLookup;
@@ -63,10 +66,15 @@ public class ClientsApiResource {
private final static Logger logger = LoggerFactory.getLogger(ClientsApiResource.class); private final static Logger logger = LoggerFactory.getLogger(ClientsApiResource.class);
private final Set<String> CLIENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "externalId",
"firstname", "lastname", "joinedDate", "displayName", "clientOrBusinessName", "allowedOffices", "imagePresent"));
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ClientReadPlatformService clientReadPlatformService; private final ClientReadPlatformService clientReadPlatformService;
private final ClientWritePlatformService clientWritePlatformService; private final ClientWritePlatformService clientWritePlatformService;
private final OfficeReadPlatformService officeReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService;
private final DefaultToApiJsonSerializer<ClientData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final CommandSerializer commandSerializerService; private final CommandSerializer commandSerializerService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService; private final PortfolioApiJsonSerializerService apiJsonSerializerService;
@@ -76,8 +84,8 @@ public class ClientsApiResource {
@Autowired @Autowired
public ClientsApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService, public ClientsApiResource(final PlatformSecurityContext context, final ClientReadPlatformService readPlatformService,
final ClientWritePlatformService clientWritePlatformService, final OfficeReadPlatformService officeReadPlatformService, final ClientWritePlatformService clientWritePlatformService, final OfficeReadPlatformService officeReadPlatformService,
final PortfolioApiDataConversionService apiDataConversionService, final DefaultToApiJsonSerializer<ClientData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
final CommandSerializer commandSerializerService, final PortfolioApiDataConversionService apiDataConversionService, final CommandSerializer commandSerializerService,
final PortfolioApiJsonSerializerService apiJsonSerializerService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
final PortfolioCommandsReadPlatformService commandsReadPlatformService, final PortfolioCommandsReadPlatformService commandsReadPlatformService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
@@ -85,6 +93,8 @@ public class ClientsApiResource {
this.clientReadPlatformService = readPlatformService; this.clientReadPlatformService = readPlatformService;
this.clientWritePlatformService = clientWritePlatformService; this.clientWritePlatformService = clientWritePlatformService;
this.officeReadPlatformService = officeReadPlatformService; this.officeReadPlatformService = officeReadPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService; this.commandSerializerService = commandSerializerService;
this.apiJsonSerializerService = apiJsonSerializerService; this.apiJsonSerializerService = apiJsonSerializerService;
@@ -104,12 +114,10 @@ public class ClientsApiResource {
final String extraCriteria = getClientCriteria(sqlSearch, officeId, externalId, displayName, firstName, lastName, hierarchy); final String extraCriteria = getClientCriteria(sqlSearch, officeId, externalId, displayName, firstName, lastName, hierarchy);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<ClientData> clients = this.clientReadPlatformService.retrieveAllIndividualClients(extraCriteria); final Collection<ClientData> clients = this.clientReadPlatformService.retrieveAllIndividualClients(extraCriteria);
return this.apiJsonSerializerService.serializeClientDataToJson(prettyPrint, responseParameters, clients); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, clients, CLIENT_DATA_PARAMETERS);
} }
private String getClientCriteria(String sqlSearch, Integer officeId, String externalId, String displayName, String firstName, private String getClientCriteria(String sqlSearch, Integer officeId, String externalId, String displayName, String firstName,
@@ -163,18 +171,15 @@ public class ClientsApiResource {
context.authenticatedUser().validateHasReadPermission("CLIENT"); context.authenticatedUser().validateHasReadPermission("CLIENT");
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
final Long commandId = ApiParameterHelper.commandId(uriInfo.getQueryParameters());
ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId); ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId);
if (template) { if (settings.isTemplate()) {
final List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup()); final List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
clientData = ClientData.templateOnTop(clientData, allowedOffices); clientData = ClientData.templateOnTop(clientData, allowedOffices);
} }
if (commandId != null) { if (settings.isCommandIdPassed()) {
clientData = handleRequestToIntegrateProposedChangesFromCommand(clientId, commandId, clientData); clientData = handleRequestToIntegrateProposedChangesFromCommand(clientId, settings.getCommandId(), clientData);
} }
// pick up possibility of changes by default - might push down a layer // pick up possibility of changes by default - might push down a layer
@@ -182,7 +187,7 @@ public class ClientsApiResource {
final Collection<ClientData> dataChanges = retrieveAllUnprocessedDataChanges(clientId); final Collection<ClientData> dataChanges = retrieveAllUnprocessedDataChanges(clientId);
clientData = ClientData.integrateChanges(clientData, clientData.currentChange(), dataChanges); clientData = ClientData.integrateChanges(clientData, clientData.currentChange(), dataChanges);
return this.apiJsonSerializerService.serializeClientDataToJson(prettyPrint, responseParameters, clientData); return this.toApiJsonSerializer.serialize(settings, clientData, CLIENT_DATA_PARAMETERS);
} }
private ClientData handleRequestToIntegrateProposedChangesFromCommand(final Long clientId, final Long commandId, private ClientData handleRequestToIntegrateProposedChangesFromCommand(final Long clientId, final Long commandId,
@@ -220,16 +225,14 @@ public class ClientsApiResource {
context.authenticatedUser().validateHasReadPermission("CLIENT"); context.authenticatedUser().validateHasReadPermission("CLIENT");
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Long makerCheckerId = ApiParameterHelper.commandId(uriInfo.getQueryParameters());
ClientData clientData = this.clientReadPlatformService.retrieveNewClientDetails(); ClientData clientData = this.clientReadPlatformService.retrieveNewClientDetails();
if (makerCheckerId != null) { if (settings.isCommandIdPassed()) {
clientData = handleRequestToIntegrateProposedChangesFromCommand(null, makerCheckerId, clientData); clientData = handleRequestToIntegrateProposedChangesFromCommand(null, settings.getCommandId(), clientData);
} }
return this.apiJsonSerializerService.serializeClientDataToJson(prettyPrint, responseParameters, clientData); return this.toApiJsonSerializer.serialize(settings, clientData, CLIENT_DATA_PARAMETERS);
} }
@POST @POST
@@ -246,7 +249,7 @@ public class ClientsApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "clients", null, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "clients", null,
commandSerializedAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
@PUT @PUT
@@ -264,7 +267,7 @@ public class ClientsApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "clients", clientId, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "clients", clientId,
commandSerializedAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
@DELETE @DELETE
@@ -278,7 +281,7 @@ public class ClientsApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "clients", clientId, "{}"); final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "clients", clientId, "{}");
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
@GET @GET
@@ -318,13 +321,13 @@ public class ClientsApiResource {
@Path("{clientId}/notes") @Path("{clientId}/notes")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response addNewClientNote(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public String addNewClientNote(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
final NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(null, clientId, jsonRequestBody); final NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(null, clientId, jsonRequestBody);
final EntityIdentifier identifier = this.clientWritePlatformService.addClientNote(command); final EntityIdentifier result = this.clientWritePlatformService.addClientNote(command);
return Response.ok().entity(identifier).build(); return this.toApiJsonSerializer.serialize(result);
} }
@GET @GET
@@ -348,14 +351,14 @@ public class ClientsApiResource {
@Path("{clientId}/notes/{noteId}") @Path("{clientId}/notes/{noteId}")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId, public String updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId,
final String jsonRequestBody) { final String jsonRequestBody) {
final NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(noteId, clientId, jsonRequestBody); final NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(noteId, clientId, jsonRequestBody);
final EntityIdentifier identifier = this.clientWritePlatformService.updateNote(command); final EntityIdentifier result = this.clientWritePlatformService.updateNote(command);
return Response.ok().entity(identifier).build(); return this.toApiJsonSerializer.serialize(result);
} }
/** /**
@@ -365,7 +368,7 @@ public class ClientsApiResource {
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response addNewClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize, public String addNewClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize,
@FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails, @FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails,
@FormDataParam("file") FormDataBodyPart bodyPart) { @FormDataParam("file") FormDataBodyPart bodyPart) {
@@ -378,10 +381,10 @@ public class ClientsApiResource {
// logger.debug(bodyPart.getMediaType().toString()); // logger.debug(bodyPart.getMediaType().toString());
final EntityIdentifier entityIdentifier = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, final EntityIdentifier result = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, fileDetails.getFileName(),
fileDetails.getFileName(), inputStream); inputStream);
return Response.ok().entity(entityIdentifier).build(); return this.toApiJsonSerializer.serialize(result);
} }
/** /**
@@ -391,13 +394,13 @@ public class ClientsApiResource {
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response addNewClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public String addNewClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
final Base64EncodedImage base64EncodedImage = FileUtils.extractImageFromDataURL(jsonRequestBody); final Base64EncodedImage base64EncodedImage = FileUtils.extractImageFromDataURL(jsonRequestBody);
final EntityIdentifier entityIdentifier = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, base64EncodedImage); final EntityIdentifier result = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, base64EncodedImage);
return Response.ok().entity(entityIdentifier).build(); return this.toApiJsonSerializer.serialize(result);
} }
/** /**
@@ -407,14 +410,15 @@ public class ClientsApiResource {
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response retrieveClientImage(@PathParam("clientId") final Long clientId) { public String retrieveClientImage(@PathParam("clientId") final Long clientId) {
context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE"); context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");
final ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId); final ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId);
if (clientData.imageKeyDoesNotExist()) { throw new ImageNotFoundException("clients", clientId); } if (clientData.imageKeyDoesNotExist()) { throw new ImageNotFoundException("clients", clientId); }
return Response.ok().entity(Base64.encodeFromFile(clientData.imageKey())).build();
return Base64.encodeFromFile(clientData.imageKey());
} }
/** /**
@@ -425,9 +429,10 @@ public class ClientsApiResource {
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response updateClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize, public String updateClientImage(@PathParam("clientId") final Long clientId, @HeaderParam("Content-Length") Long fileSize,
@FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails, @FormDataParam("file") InputStream inputStream, @FormDataParam("file") FormDataContentDisposition fileDetails,
@FormDataParam("file") FormDataBodyPart bodyPart) { @FormDataParam("file") FormDataBodyPart bodyPart) {
return addNewClientImage(clientId, fileSize, inputStream, fileDetails, bodyPart); return addNewClientImage(clientId, fileSize, inputStream, fileDetails, bodyPart);
} }
@@ -435,9 +440,10 @@ public class ClientsApiResource {
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response deleteClientImage(@PathParam("clientId") final Long clientId) { public String deleteClientImage(@PathParam("clientId") final Long clientId) {
this.clientWritePlatformService.deleteClientImage(clientId); this.clientWritePlatformService.deleteClientImage(clientId);
return Response.ok(new EntityIdentifier(clientId)).build();
return this.toApiJsonSerializer.serialize(new EntityIdentifier(clientId));
} }
/** /**
@@ -450,7 +456,7 @@ public class ClientsApiResource {
@Path("{clientId}/image") @Path("{clientId}/image")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public Response updateClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) { public String updateClientImage(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
return addNewClientImage(clientId, jsonRequestBody); return addNewClientImage(clientId, jsonRequestBody);
} }
} }
@@ -2,6 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.api;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@@ -20,14 +21,15 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.organisation.monetary.domain.Money;
@@ -75,6 +77,17 @@ import org.springframework.util.CollectionUtils;
@Scope("singleton") @Scope("singleton")
public class LoansApiResource { public class LoansApiResource {
private final Set<String> LOAN_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "externalId", "clientId", "groupId",
"clientName", "groupName", "fundId", "fundName", "loanProductId", "loanProductName", "loanProductDescription", "currency",
"principal", "inArrearsTolerance", "numberOfRepayments", "repaymentEvery", "interestRatePerPeriod", "annualInterestRate",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
"submittedOnDate", "approvedOnDate", "expectedDisbursementDate", "actualDisbursementDate", "expectedFirstRepaymentOnDate",
"interestChargedFromDate", "closedOnDate", "expectedMaturityDate", "status", "lifeCycleStatusDate", "repaymentSchedule",
"transactions", "permissions", "convenienceData", "charges", "productOptions", "amortizationTypeOptions",
"interestTypeOptions", "interestCalculationPeriodTypeOptions", "repaymentFrequencyTypeOptions",
"interestRateFrequencyTypeOptions", "fundOptions", "repaymentStrategyOptions", "chargeOptions", "loanOfficerId",
"loanOfficerName", "loanOfficerOptions", "chargeTemplate"));
// private final String resourceNameForPermissions = "OFFICE"; // private final String resourceNameForPermissions = "OFFICE";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
@@ -90,8 +103,8 @@ public class LoansApiResource {
private final GuarantorReadPlatformService guarantorReadPlatformService; private final GuarantorReadPlatformService guarantorReadPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService; private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final CommandSerializer commandSerializerService; private final DefaultToApiJsonSerializer<LoanAccountData> toApiJsonSerializer;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final ApiRequestParameterHelper apiRequestParameterHelper;
@Autowired @Autowired
public LoansApiResource(final PlatformSecurityContext context, final LoanReadPlatformService loanReadPlatformService, public LoansApiResource(final PlatformSecurityContext context, final LoanReadPlatformService loanReadPlatformService,
@@ -100,10 +113,9 @@ public class LoansApiResource {
final ChargeReadPlatformService chargeReadPlatformService, final CalculationPlatformService calculationPlatformService, final ChargeReadPlatformService chargeReadPlatformService, final CalculationPlatformService calculationPlatformService,
final StaffReadPlatformService staffReadPlatformService, final OfficeReadPlatformService officeReadPlatformService, final StaffReadPlatformService staffReadPlatformService, final OfficeReadPlatformService officeReadPlatformService,
final GuarantorReadPlatformService guarantorReadPlatformService, final GuarantorReadPlatformService guarantorReadPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService, final DefaultToApiJsonSerializer<LoanAccountData> toApiJsonSerializer,
final PortfolioApiDataConversionService apiDataConversionService, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioApiJsonSerializerService apiJsonSerializerService,
final CommandSerializer commandSerializerService, final PortfolioApiDataConversionService apiDataConversionService) {
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context; this.context = context;
this.loanReadPlatformService = loanReadPlatformService; this.loanReadPlatformService = loanReadPlatformService;
this.loanWritePlatformService = loanWritePlatformService; this.loanWritePlatformService = loanWritePlatformService;
@@ -115,10 +127,10 @@ public class LoansApiResource {
this.staffReadPlatformService = staffReadPlatformService; this.staffReadPlatformService = staffReadPlatformService;
this.officeReadPlatformService = officeReadPlatformService; this.officeReadPlatformService = officeReadPlatformService;
this.guarantorReadPlatformService = guarantorReadPlatformService; this.guarantorReadPlatformService = guarantorReadPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiJsonSerializerService = apiJsonSerializerService; this.apiJsonSerializerService = apiJsonSerializerService;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
} }
@GET @GET
@@ -130,9 +142,6 @@ public class LoansApiResource {
context.authenticatedUser().validateHasReadPermission("LOAN"); context.authenticatedUser().validateHasReadPermission("LOAN");
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
// tempate related // tempate related
Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(); Collection<LoanProductData> productOptions = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup();
Collection<EnumOptionData> loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions(); Collection<EnumOptionData> loanTermFrequencyTypeOptions = dropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
@@ -174,7 +183,8 @@ public class LoansApiResource {
interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, interestCalculationPeriodTypeOptions,
fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, null); fundOptions, chargeOptions, chargeTemplate, allowedLoanOfficers, null);
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, newLoanAccount); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, newLoanAccount, LOAN_DATA_PARAMETERS);
} }
@GET @GET
@@ -185,9 +195,6 @@ public class LoansApiResource {
context.authenticatedUser().validateHasReadPermission("LOAN"); context.authenticatedUser().validateHasReadPermission("LOAN");
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId); final LoanBasicDetailsData loanBasicDetails = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
int loanRepaymentsCount = 0; int loanRepaymentsCount = 0;
@@ -290,7 +297,8 @@ public class LoansApiResource {
repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions, repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions,
interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, null, guarantorData); interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, chargeTemplate, null, guarantorData);
return this.apiJsonSerializerService.serializeLoanAccountDataToJson(prettyPrint, responseParameters, loanAccount); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, loanAccount, LOAN_DATA_PARAMETERS);
} }
private int retrieveNonDisbursementTransactions(final Collection<LoanTransactionData> loanRepayments) { private int retrieveNonDisbursementTransactions(final Collection<LoanTransactionData> loanRepayments) {
@@ -323,7 +331,7 @@ public class LoansApiResource {
final EntityIdentifier identifier = this.loanWritePlatformService.submitLoanApplication(command); final EntityIdentifier identifier = this.loanWritePlatformService.submitLoanApplication(command);
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier); return this.toApiJsonSerializer.serialize(identifier);
} }
private String calculateLoanSchedule(final UriInfo uriInfo, final CalculateLoanScheduleCommand command) { private String calculateLoanSchedule(final UriInfo uriInfo, final CalculateLoanScheduleCommand command) {
@@ -347,7 +355,7 @@ public class LoansApiResource {
final EntityIdentifier identifier = this.loanWritePlatformService.modifyLoanApplication(command); final EntityIdentifier identifier = this.loanWritePlatformService.modifyLoanApplication(command);
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier); return this.toApiJsonSerializer.serialize(identifier);
} }
@DELETE @DELETE
@@ -554,7 +562,7 @@ public class LoansApiResource {
final EntityIdentifier identifier = this.loanWritePlatformService.updateLoanCharge(command); final EntityIdentifier identifier = this.loanWritePlatformService.updateLoanCharge(command);
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier); return this.toApiJsonSerializer.serialize(identifier);
} }
@POST @POST
@@ -569,7 +577,7 @@ public class LoansApiResource {
String json = ""; String json = "";
if (is(commandParam, "waive")) { if (is(commandParam, "waive")) {
final EntityIdentifier identifier = this.loanWritePlatformService.waiveLoanCharge(command); final EntityIdentifier identifier = this.loanWritePlatformService.waiveLoanCharge(command);
json = this.apiJsonSerializerService.serializeEntityIdentifier(identifier); json = this.toApiJsonSerializer.serialize(identifier);
} else { } else {
throw new UnrecognizedQueryParamException("command", commandParam); throw new UnrecognizedQueryParamException("command", commandParam);
} }
@@ -584,7 +592,7 @@ public class LoansApiResource {
public String deleteLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId) { public String deleteLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId) {
final EntityIdentifier identifier = this.loanWritePlatformService.deleteLoanCharge(loanId, loanChargeId); final EntityIdentifier identifier = this.loanWritePlatformService.deleteLoanCharge(loanId, loanChargeId);
return this.apiJsonSerializerService.serializeEntityIdentifier(identifier); return this.toApiJsonSerializer.serialize(identifier);
} }
@POST @POST
@@ -2,6 +2,7 @@ package org.mifosplatform.portfolio.loanproduct.api;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -17,12 +18,13 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer; import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.data.CurrencyData;
import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService; import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService;
@@ -44,6 +46,14 @@ import org.springframework.stereotype.Component;
@Scope("singleton") @Scope("singleton")
public class LoanProductsApiResource { public class LoanProductsApiResource {
private final Set<String> LOAN_PRODUCT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description", "fundId",
"fundName", "transactionProcessingStrategyId", "transactionProcessingStrategyName", "principal", "inArrearsTolerance",
"numberOfRepayments", "repaymentEvery", "interestRatePerPeriod", "annualInterestRate", "repaymentFrequencyType",
"interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType", "charges", "createdOn",
"lastModifedOn", "currencyOptions", "amortizationTypeOptions", "interestTypeOptions", "interestCalculationPeriodTypeOptions",
"repaymentFrequencyTypeOptions", "interestRateFrequencyTypeOptions", "fundOptions", "transactionProcessingStrategyOptions",
"chargeOptions"));
private final String resourceNameForPermissions = "LOANPRODUCT"; private final String resourceNameForPermissions = "LOANPRODUCT";
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
@@ -51,8 +61,9 @@ public class LoanProductsApiResource {
private final ChargeReadPlatformService chargeReadPlatformService; private final ChargeReadPlatformService chargeReadPlatformService;
private final CurrencyReadPlatformService currencyReadPlatformService; private final CurrencyReadPlatformService currencyReadPlatformService;
private final FundReadPlatformService fundReadPlatformService; private final FundReadPlatformService fundReadPlatformService;
private final DefaultToApiJsonSerializer<LoanProductData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final LoanDropdownReadPlatformService dropdownReadPlatformService; private final LoanDropdownReadPlatformService dropdownReadPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioApiDataConversionService apiDataConversionService; private final PortfolioApiDataConversionService apiDataConversionService;
private final CommandSerializer commandSerializerService; private final CommandSerializer commandSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@@ -61,8 +72,8 @@ public class LoanProductsApiResource {
public LoanProductsApiResource(final PlatformSecurityContext context, final LoanProductReadPlatformService readPlatformService, public LoanProductsApiResource(final PlatformSecurityContext context, final LoanProductReadPlatformService readPlatformService,
final ChargeReadPlatformService chargeReadPlatformService, final CurrencyReadPlatformService currencyReadPlatformService, final ChargeReadPlatformService chargeReadPlatformService, final CurrencyReadPlatformService currencyReadPlatformService,
final FundReadPlatformService fundReadPlatformService, final LoanDropdownReadPlatformService dropdownReadPlatformService, final FundReadPlatformService fundReadPlatformService, final LoanDropdownReadPlatformService dropdownReadPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService, final DefaultToApiJsonSerializer<LoanProductData> toApiJsonSerializer,
final PortfolioApiDataConversionService apiDataConversionService, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioApiDataConversionService apiDataConversionService,
final CommandSerializer commandSerializerService, final CommandSerializer commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) { final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context; this.context = context;
@@ -71,7 +82,8 @@ public class LoanProductsApiResource {
this.currencyReadPlatformService = currencyReadPlatformService; this.currencyReadPlatformService = currencyReadPlatformService;
this.fundReadPlatformService = fundReadPlatformService; this.fundReadPlatformService = fundReadPlatformService;
this.dropdownReadPlatformService = dropdownReadPlatformService; this.dropdownReadPlatformService = dropdownReadPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService; this.toApiJsonSerializer = toApiJsonSerializer;
this.apiRequestParameterHelper = apiRequestParameterHelper;
this.apiDataConversionService = apiDataConversionService; this.apiDataConversionService = apiDataConversionService;
this.commandSerializerService = commandSerializerService; this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
@@ -93,7 +105,7 @@ public class LoanProductsApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "loanproducts", null, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "loanproducts", null,
commandSerializedAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
@GET @GET
@@ -103,12 +115,10 @@ public class LoanProductsApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final Collection<LoanProductData> products = this.loanProductReadPlatformService.retrieveAllLoanProducts(); final Collection<LoanProductData> products = this.loanProductReadPlatformService.retrieveAllLoanProducts();
return this.apiJsonSerializerService.serializeLoanProductDataToJson(prettyPrint, responseParameters, products); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, products, LOAN_PRODUCT_DATA_PARAMETERS);
} }
@GET @GET
@@ -119,13 +129,11 @@ public class LoanProductsApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveNewLoanProductDetails(); LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveNewLoanProductDetails();
loanProduct = handleTemplate(loanProduct); loanProduct = handleTemplate(loanProduct);
return this.apiJsonSerializerService.serializeLoanProductDataToJson(prettyPrint, responseParameters, loanProduct); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, loanProduct, LOAN_PRODUCT_DATA_PARAMETERS);
} }
@GET @GET
@@ -136,16 +144,14 @@ public class LoanProductsApiResource {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions); context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId); LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId);
if (template) { if (settings.isTemplate()) {
loanProduct = handleTemplate(loanProduct); loanProduct = handleTemplate(loanProduct);
} }
return this.apiJsonSerializerService.serializeLoanProductDataToJson(prettyPrint, responseParameters, loanProduct); return this.toApiJsonSerializer.serialize(settings, loanProduct, LOAN_PRODUCT_DATA_PARAMETERS);
} }
@PUT @PUT
@@ -165,7 +171,7 @@ public class LoanProductsApiResource {
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "loanproducts", null, final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "loanproducts", null,
commandSerializedAsJson); commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result); return this.toApiJsonSerializer.serialize(result);
} }
private LoanProductData handleTemplate(final LoanProductData productData) { private LoanProductData handleTemplate(final LoanProductData productData) {
@@ -23,6 +23,7 @@ import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
import org.mifosplatform.infrastructure.core.data.EntityIdentifier; import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.savingsaccount.command.CalculateSavingScheduleCommand; import org.mifosplatform.portfolio.savingsaccount.command.CalculateSavingScheduleCommand;
import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand; import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand;
@@ -60,6 +61,9 @@ public class SavingsAccountApiResource {
@Autowired @Autowired
private CalculateSavingSchedule calculateSavingSchedule; private CalculateSavingSchedule calculateSavingSchedule;
@Autowired
private ToApiJsonSerializer<SavingAccountData> toApiJsonSerializer;
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "status", "externalId", private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "status", "externalId",
"clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod", "clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod",
"savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType", "savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType",
@@ -83,7 +87,7 @@ public class SavingsAccountApiResource {
EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.createSavingAccount(command); EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.createSavingAccount(command);
return this.apiJsonSerializerService.serializeEntityIdentifier(entityIdentifier); return this.toApiJsonSerializer.serialize(entityIdentifier);
} }
private String calculateSavingSchedule(final UriInfo uriInfo, final CalculateSavingScheduleCommand command) { private String calculateSavingSchedule(final UriInfo uriInfo, final CalculateSavingScheduleCommand command) {
@@ -18,27 +18,34 @@ import org.mifosplatform.useradministration.domain.AppUser;
@Table(name = "m_saving_schedule") @Table(name = "m_saving_schedule")
public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser, Long> { public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser, Long> {
@SuppressWarnings("unused")
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "saving_account_id", nullable = false) @JoinColumn(name = "saving_account_id", nullable = false)
private SavingAccount savingAccount; private SavingAccount savingAccount;
@SuppressWarnings("unused")
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
@Column(name = "duedate", nullable = false) @Column(name = "duedate", nullable = false)
private final Date dueDate; private final Date dueDate;
@SuppressWarnings("unused")
@Column(name = "installment", nullable = false) @Column(name = "installment", nullable = false)
private final Integer installmentNumber; private final Integer installmentNumber;
@SuppressWarnings("unused")
@Column(name = "deposit", scale = 6, precision = 19, nullable = false) @Column(name = "deposit", scale = 6, precision = 19, nullable = false)
private BigDecimal deposit; private BigDecimal deposit;
@SuppressWarnings("unused")
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
@Column(name = "payment_date", nullable = true) @Column(name = "payment_date", nullable = true)
private final Date paymentDate; private final Date paymentDate;
@SuppressWarnings("unused")
@Column(name = "deposit_paid", scale = 6, precision = 19, nullable = true) @Column(name = "deposit_paid", scale = 6, precision = 19, nullable = true)
private BigDecimal depositPaid; private BigDecimal depositPaid;
@SuppressWarnings("unused")
@Column(name = "completed_derived", nullable = false) @Column(name = "completed_derived", nullable = false)
private boolean completed; private boolean completed;
@@ -55,5 +62,4 @@ public class SavingScheduleInstallments extends AbstractAuditableCustom<AppUser,
public void updateAccount(SavingAccount account) { public void updateAccount(SavingAccount account) {
this.savingAccount = account; this.savingAccount = account;
} }
}
}
@@ -1,9 +1,5 @@
package org.mifosplatform.portfolio.savingsaccount.service; package org.mifosplatform.portfolio.savingsaccount.service;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.portfolio.savingsaccount.command.CalculateSavingScheduleCommand; import org.mifosplatform.portfolio.savingsaccount.command.CalculateSavingScheduleCommand;
import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProduct; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProduct;
import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProductRelatedDetail; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProductRelatedDetail;
@@ -22,17 +18,18 @@ public class SavingProductRelatedDetailAssembler {
this.savingProductRepository = savingProductRepository; this.savingProductRepository = savingProductRepository;
} }
public SavingProductRelatedDetail assembleFrom(CalculateSavingScheduleCommand command) { public SavingProductRelatedDetail assembleFrom(final CalculateSavingScheduleCommand command) {
// final BigDecimal depositAmountForPeriod = command.getDeposit();
// final BigDecimal depositInterestRate = command.getInterestRate();
// final LocalDate installmentDate = command.getPaymentsStartingFromDate();
// final Integer payEvery = command.getPayEvery();
// final Integer paymentFrequencyType = command.getPaymentFrequencyType();
final BigDecimal depositAmountForPeriod = command.getDeposit();
final BigDecimal depositInterestRate = command.getInterestRate();
final LocalDate installmentDate = command.getPaymentsStartingFromDate();
final Integer payEvery = command.getPayEvery();
final Integer paymentFrequencyType = command.getPaymentFrequencyType();
final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId()); final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId());
if (savingProduct == null) { throw new SavingProductNotFoundException(command.getProductId()); } if (savingProduct == null) { throw new SavingProductNotFoundException(command.getProductId()); }
final MonetaryCurrency currency = savingProduct.getCurrency(); // final MonetaryCurrency currency = savingProduct.getCurrency();
return null; return null;
} }
@@ -752,6 +752,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
// add transaction entry for each interest posting // add transaction entry for each interest posting
DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null, DepositAccountTransaction depositaccountTransaction = DepositAccountTransaction.postInterest(null,
nextInterestPostingDate, futureValueOnMaturity.minus(deposit)); nextInterestPostingDate, futureValueOnMaturity.minus(deposit));
depositaccountTransaction.updateAccount(this); depositaccountTransaction.updateAccount(this);
this.depositaccountTransactions.add(depositaccountTransaction); this.depositaccountTransactions.add(depositaccountTransaction);
} else { } else {