update commands around client and loan functionality to use json conversion service

This commit is contained in:
Keith Woodlock
2012-07-18 02:01:41 +01:00
parent d492d41800
commit bf659d4fe4
30 changed files with 705 additions and 1053 deletions
@@ -17,7 +17,6 @@ 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;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.ClientCommand; import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.NoteCommand; import org.mifosng.platform.api.commands.NoteCommand;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
@@ -64,9 +63,9 @@ public class ClientApiResource {
private ApiJSONFormattingService jsonFormattingService; private ApiJSONFormattingService jsonFormattingService;
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveAllIndividualClients(@Context UriInfo uriInfo, public String retrieveAllIndividualClients(@Context final UriInfo uriInfo,
@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("officeId") final Integer officeId, @QueryParam("officeId") final Integer officeId,
@QueryParam("externalId") final String externalId, @QueryParam("externalId") final String externalId,
@@ -126,11 +125,11 @@ public class ClientApiResource {
@GET @GET
@Path("{clientId}") @Path("{clientId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveClientData( public String retrieveClientData(
@PathParam("clientId") final Long clientId, @PathParam("clientId") final Long clientId,
@QueryParam("template") String template, @Context UriInfo uriInfo) { @QueryParam("template") final String template, @Context final UriInfo uriInfo) {
ClientData clientData = this.clientReadPlatformService ClientData clientData = this.clientReadPlatformService
.retrieveIndividualClient(clientId); .retrieveIndividualClient(clientId);
@@ -148,8 +147,8 @@ public class ClientApiResource {
@GET @GET
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String newClientDetails(@Context UriInfo uriInfo) { public String newClientDetails(@Context UriInfo uriInfo) {
ClientData clientData = this.clientReadPlatformService ClientData clientData = this.clientReadPlatformService
@@ -162,15 +161,12 @@ public class ClientApiResource {
} }
@POST @POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response enrollClient(final ClientCommand command) { public Response enrollClient(final String jsonRequestBody) {
LocalDate joiningLocalDate = apiDataConversionService.convertFrom(
command.getJoiningDate(), "joiningDate",
command.getDateFormat());
command.setJoiningLocalDate(joiningLocalDate);
ClientCommand command = this.apiDataConversionService.convertJsonToClientCommand(null, jsonRequestBody);
Long clientId = this.clientWritePlatformService.enrollClient(command); Long clientId = this.clientWritePlatformService.enrollClient(command);
return Response.ok().entity(new EntityIdentifier(clientId)).build(); return Response.ok().entity(new EntityIdentifier(clientId)).build();
@@ -178,29 +174,23 @@ public class ClientApiResource {
@PUT @PUT
@Path("{clientId}") @Path("{clientId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response updateClient(@PathParam("clientId") final Long clientId, public Response updateClient(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
final ClientCommand command) {
LocalDate joiningLocalDate = apiDataConversionService.convertFrom( ClientCommand command = this.apiDataConversionService.convertJsonToClientCommand(clientId, jsonRequestBody);
command.getJoiningDate(), "joiningDate",
command.getDateFormat());
command.setJoiningLocalDate(joiningLocalDate);
command.setId(clientId);
EntityIdentifier identifier = this.clientWritePlatformService EntityIdentifier identifier = this.clientWritePlatformService.updateClientDetails(command);
.updateClientDetails(command);
return Response.ok().entity(identifier).build(); return Response.ok().entity(identifier).build();
} }
@GET @GET
@Path("{clientId}/loans") @Path("{clientId}/loans")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveClientAccount( public String retrieveClientAccount(
@PathParam("clientId") final Long clientId, @Context UriInfo uriInfo) { @PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
ClientLoanAccountSummaryCollectionData clientAccount = this.clientReadPlatformService ClientLoanAccountSummaryCollectionData clientAccount = this.clientReadPlatformService
.retrieveClientAccountDetails(clientId); .retrieveClientAccountDetails(clientId);
@@ -213,10 +203,9 @@ public class ClientApiResource {
@GET @GET
@Path("{clientId}/notes") @Path("{clientId}/notes")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveAllClientNotes( public String retrieveAllClientNotes(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {
@PathParam("clientId") final Long clientId, @Context UriInfo uriInfo) {
Collection<NoteData> notes = this.clientReadPlatformService Collection<NoteData> notes = this.clientReadPlatformService
.retrieveAllClientNotes(clientId); .retrieveAllClientNotes(clientId);
@@ -228,11 +217,9 @@ public class ClientApiResource {
@POST @POST
@Path("{clientId}/notes") @Path("{clientId}/notes")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response addNewClientNote( public Response addNewClientNote(@PathParam("clientId") final Long clientId, final NoteCommand command) {
@PathParam("clientId") final Long clientId,
final NoteCommand command) {
command.setClientId(clientId); command.setClientId(clientId);
@@ -244,11 +231,11 @@ public class ClientApiResource {
@GET @GET
@Path("{clientId}/notes/{noteId}") @Path("{clientId}/notes/{noteId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveClientNote( public String retrieveClientNote(
@PathParam("clientId") final Long clientId, @PathParam("clientId") final Long clientId,
@PathParam("noteId") final Long noteId, @Context UriInfo uriInfo) { @PathParam("noteId") final Long noteId, @Context final UriInfo uriInfo) {
NoteData note = this.clientReadPlatformService.retrieveClientNote( NoteData note = this.clientReadPlatformService.retrieveClientNote(
clientId, noteId); clientId, noteId);
@@ -260,8 +247,8 @@ public class ClientApiResource {
@PUT @PUT
@Path("{clientId}/notes/{noteId}") @Path("{clientId}/notes/{noteId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response updateClientNote( public Response updateClientNote(
@PathParam("clientId") final Long clientId, @PathParam("clientId") final Long clientId,
@PathParam("noteId") final Long noteId, final NoteCommand command) { @PathParam("noteId") final Long noteId, final NoteCommand command) {
@@ -48,7 +48,7 @@ public class FundsApiResource {
@GET @GET
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public String retrieveFunds(@Context UriInfo uriInfo) { public String retrieveFunds(@Context final UriInfo uriInfo) {
Collection<FundData> funds = this.readPlatformService.retrieveAllFunds(); Collection<FundData> funds = this.readPlatformService.retrieveAllFunds();
String selectedFields = ""; String selectedFields = "";
@@ -1,8 +1,5 @@
package org.mifosng.platform.api; package org.mifosng.platform.api;
import java.math.BigDecimal;
import java.util.Locale;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@@ -17,7 +14,6 @@ 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;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand; import org.mifosng.platform.api.commands.CalculateLoanScheduleCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand; import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
@@ -69,15 +65,14 @@ public class LoansApiResource {
@GET @GET
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveDetailsForNewLoanApplicationStepOne( public String retrieveDetailsForNewLoanApplicationStepOne(
@QueryParam("clientId") final Long clientId, @QueryParam("clientId") final Long clientId,
@QueryParam("productId") final Long productId, @QueryParam("productId") final Long productId,
@Context UriInfo uriInfo) { @Context final UriInfo uriInfo) {
NewLoanData workflowData = this.loanReadPlatformService NewLoanData workflowData = this.loanReadPlatformService.retrieveClientAndProductDetails(clientId, productId);
.retrieveClientAndProductDetails(clientId, productId);
String selectedFields = ""; String selectedFields = "";
return this.jsonFormattingService.convertRequest(workflowData, return this.jsonFormattingService.convertRequest(workflowData,
@@ -87,13 +82,12 @@ public class LoansApiResource {
@GET @GET
@Path("{loanId}") @Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveLoanAccountDetails( public String retrieveLoanAccountDetails(
@PathParam("loanId") final Long loanId, @Context UriInfo uriInfo) { @PathParam("loanId") final Long loanId, @Context final UriInfo uriInfo) {
LoanAccountData loanAccount = this.loanReadPlatformService LoanAccountData loanAccount = this.loanReadPlatformService.retrieveLoanAccountDetails(loanId);
.retrieveLoanAccountDetails(loanId);
String selectedFields = ""; String selectedFields = "";
String associatedFields = "summary,repaymentSchedule,loanRepayments,permissions,convenienceData"; String associatedFields = "summary,repaymentSchedule,loanRepayments,permissions,convenienceData";
@@ -103,102 +97,50 @@ public class LoansApiResource {
} }
@POST @POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response calculateLoanScheduleOrSubmitLoanApplication( public Response calculateLoanScheduleOrSubmitLoanApplication(
@QueryParam("command") final String commandParam, @QueryParam("command") final String commandParam,
final SubmitLoanApplicationCommand command) { final String jsonRequestBody) {
LocalDate expectedDisbursementLocalDate = apiDataConversionService SubmitLoanApplicationCommand command = this.apiDataConversionService.convertJsonToSubmitLoanApplicationCommand(jsonRequestBody);
.convertFrom(command.getExpectedDisbursementDate(),
"expectedDisbursementDate", command.getDateFormat()); CalculateLoanScheduleCommand calculateLoanScheduleCommand = command.toCalculateLoanScheduleCommand();
LocalDate repaymentsStartingFromLocalDate = apiDataConversionService LoanSchedule loanSchedule = this.calculationPlatformService.calculateLoanSchedule(calculateLoanScheduleCommand);
.convertFrom(command.getRepaymentsStartingFromDate(),
"repaymentsStartingFromDate", command.getDateFormat());
LocalDate interestChargedFromLocalDate = apiDataConversionService
.convertFrom(command.getInterestChargedFromDate(),
"interestChargedFromDate", command.getDateFormat());
LocalDate submittedOnLocalDate = apiDataConversionService.convertFrom(
command.getSubmittedOnDate(), "submittedOnDate",
command.getDateFormat());
command.setExpectedDisbursementLocalDate(expectedDisbursementLocalDate);
command.setRepaymentsStartingFromLocalDate(repaymentsStartingFromLocalDate);
command.setInterestChargedFromLocalDate(interestChargedFromLocalDate);
command.setSubmittedOnLocalDate(submittedOnLocalDate);
Locale clientApplicationLocale = this.apiDataConversionService
.localeFromString(command.getLocale());
BigDecimal principalValue = this.apiDataConversionService.convertFrom(
command.getPrincipal(), "principal", clientApplicationLocale);
BigDecimal inArrearsToleranceValue = this.apiDataConversionService
.convertFrom(command.getInArrearsTolerance(),
"inArrearsTolerance", clientApplicationLocale);
BigDecimal interestRatePerPeriodValue = this.apiDataConversionService
.convertFrom(command.getInterestRatePerPeriod(),
"interestRatePerPeriod", clientApplicationLocale);
Integer repaymentEveryValue = this.apiDataConversionService
.convertToInteger(command.getRepaymentEvery(),
"repaymentEvery", clientApplicationLocale);
Integer numberOfRepaymentsValue = this.apiDataConversionService
.convertToInteger(command.getNumberOfRepayments(),
"numberOfRepayments", clientApplicationLocale);
command.setPrincipalValue(principalValue);
command.setInArrearsToleranceValue(inArrearsToleranceValue);
command.setInterestRatePerPeriodValue(interestRatePerPeriodValue);
command.setRepaymentEveryValue(repaymentEveryValue);
command.setNumberOfRepaymentsValue(numberOfRepaymentsValue);
CalculateLoanScheduleCommand calculateLoanScheduleCommand = command
.toCalculateLoanScheduleCommand();
LoanSchedule loanSchedule = this.calculationPlatformService
.calculateLoanSchedule(calculateLoanScheduleCommand);
// for now just auto generating the loan schedule and setting support // for now just auto generating the loan schedule and setting support
// for 'manual' loan schedule creation later. // for 'manual' loan schedule creation later.
command.setLoanSchedule(loanSchedule); command.setLoanSchedule(loanSchedule);
if (StringUtils.isNotBlank(commandParam) if (is(commandParam, "calculateLoanSchedule")) {
&& commandParam.trim()
.equalsIgnoreCase("calculateLoanSchedule")) {
return Response.ok().entity(loanSchedule).build(); return Response.ok().entity(loanSchedule).build();
} }
EntityIdentifier identifier = this.loanWritePlatformService EntityIdentifier identifier = this.loanWritePlatformService.submitLoanApplication(command);
.submitLoanApplication(command);
return Response.ok().entity(identifier).build(); return Response.ok().entity(identifier).build();
} }
@DELETE @DELETE
@Path("{loanId}") @Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response deleteLoanApplication(@PathParam("loanId") final Long loanId) { public Response deleteLoanApplication(@PathParam("loanId") final Long loanId) {
EntityIdentifier identifier = this.loanWritePlatformService EntityIdentifier identifier = this.loanWritePlatformService.deleteLoan(loanId);
.deleteLoan(loanId);
return Response.ok().entity(identifier).build(); return Response.ok().entity(identifier).build();
} }
@POST @POST
@Path("{loanId}") @Path("{loanId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response stateTransitions(@PathParam("loanId") final Long loanId, public Response stateTransitions(@PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam, @QueryParam("command") final String commandParam, final String jsonRequestBody) {
final LoanStateTransitionCommand command) {
LocalDate eventLocalDate = this.apiDataConversionService.convertFrom(
command.getEventDate(), "eventDate", command.getDateFormat());
command.setLoanId(loanId);
command.setEventLocalDate(eventLocalDate);
LoanStateTransitionCommand command = this.apiDataConversionService.convertJsonToLoanStateTransitionCommand(loanId, jsonRequestBody);
Response response = null; Response response = null;
if (is(commandParam, "reject")) { if (is(commandParam, "reject")) {
@@ -219,8 +161,8 @@ public class LoansApiResource {
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
} }
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand( UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(loanId, command.getNote());
loanId, command.getNote());
if (is(commandParam, "undoapproval")) { if (is(commandParam, "undoapproval")) {
EntityIdentifier identifier = this.loanWritePlatformService EntityIdentifier identifier = this.loanWritePlatformService
.undoLoanApproval(undoCommand); .undoLoanApproval(undoCommand);
@@ -245,36 +187,21 @@ public class LoansApiResource {
@POST @POST
@Path("{loanId}/transactions") @Path("{loanId}/transactions")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response executeLoanTransaction( public Response executeLoanTransaction(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam, @QueryParam("command") final String commandParam, final String jsonRequestBody) {
final LoanTransactionCommand command) {
final LoanTransactionCommand command = this.apiDataConversionService.convertJsonToLoanTransactionCommand(loanId, jsonRequestBody);
Response response = null; Response response = null;
command.setLoanId(loanId);
Locale clientLocale = this.apiDataConversionService
.localeFromString(command.getLocale());
LocalDate transactionLocalDate = apiDataConversionService.convertFrom(
command.getTransactionDate(), "transactionDate",
command.getDateFormat());
command.setTransactionLocalDate(transactionLocalDate);
BigDecimal transactionAmountValue = apiDataConversionService
.convertFrom(command.getTransactionAmount(),
"transactionAmount", clientLocale);
command.setTransactionAmountValue(transactionAmountValue);
if (is(commandParam, "repayment")) { if (is(commandParam, "repayment")) {
EntityIdentifier identifier = this.loanWritePlatformService EntityIdentifier identifier = this.loanWritePlatformService.makeLoanRepayment(command);
.makeLoanRepayment(command);
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
} else if (is(commandParam, "waiver")) { } else if (is(commandParam, "waiver")) {
EntityIdentifier identifier = this.loanWritePlatformService EntityIdentifier identifier = this.loanWritePlatformService.waiveLoanAmount(command);
.waiveLoanAmount(command);
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
} }
@@ -287,12 +214,12 @@ public class LoansApiResource {
@GET @GET
@Path("{loanId}/transactions/template") @Path("{loanId}/transactions/template")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveNewRepaymentDetails( public String retrieveNewRepaymentDetails(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@QueryParam("command") final String commandParam, @QueryParam("command") final String commandParam,
@Context UriInfo uriInfo) { @Context final UriInfo uriInfo) {
String json = ""; String json = "";
String selectedFields = loanRepaymentDefaultFieldList; String selectedFields = loanRepaymentDefaultFieldList;
@@ -319,11 +246,11 @@ public class LoansApiResource {
@GET @GET
@Path("{loanId}/transactions/{transactionId}") @Path("{loanId}/transactions/{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveTransaction(@PathParam("loanId") final Long loanId, public String retrieveTransaction(@PathParam("loanId") final Long loanId,
@PathParam("transactionId") final Long transactionId, @PathParam("transactionId") final Long transactionId,
@Context UriInfo uriInfo) { @Context final UriInfo uriInfo) {
LoanTransactionData loanRepaymentData = this.loanReadPlatformService LoanTransactionData loanRepaymentData = this.loanReadPlatformService
.retrieveLoanTransactionDetails(loanId, transactionId); .retrieveLoanTransactionDetails(loanId, transactionId);
@@ -336,31 +263,15 @@ public class LoansApiResource {
@POST @POST
@Path("{loanId}/transactions/{transactionId}") @Path("{loanId}/transactions/{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response adjustLoanTransaction( public Response adjustLoanTransaction(
@PathParam("loanId") final Long loanId, @PathParam("loanId") final Long loanId,
@PathParam("transactionId") final Long transactionId, @PathParam("transactionId") final Long transactionId, final String jsonRequestBody) {
final AdjustLoanTransactionCommand command) {
command.setLoanId(loanId); final AdjustLoanTransactionCommand command = this.apiDataConversionService.convertJsonToAdjustLoanTransactionCommand(loanId, transactionId, jsonRequestBody);
command.setTransactionId(transactionId);
EntityIdentifier identifier = this.loanWritePlatformService.adjustLoanTransaction(command);
Locale clientLocale = this.apiDataConversionService
.localeFromString(command.getLocale());
LocalDate transactionLocalDate = apiDataConversionService.convertFrom(
command.getTransactionDate(), "transactionDate",
command.getDateFormat());
command.setTransactionLocalDate(transactionLocalDate);
BigDecimal transactionAmountValue = apiDataConversionService
.convertFrom(command.getTransactionAmount(),
"transactionAmount", clientLocale);
command.setTransactionAmountValue(transactionAmountValue);
EntityIdentifier identifier = this.loanWritePlatformService
.adjustLoanTransaction(command);
return Response.ok().entity(identifier).build(); return Response.ok().entity(identifier).build();
} }
@@ -1,8 +1,5 @@
package org.mifosng.platform.api; package org.mifosng.platform.api;
import java.math.BigDecimal;
import java.util.Locale;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
@@ -13,7 +10,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand; import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.OfficeTransactionData; import org.mifosng.platform.api.data.OfficeTransactionData;
@@ -44,9 +40,9 @@ public class OfficeTransactionsApiResource {
@GET @GET
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String newOfficeTransactionDetails(@Context UriInfo uriInfo) { public String newOfficeTransactionDetails(@Context final UriInfo uriInfo) {
OfficeTransactionData officeTransactionData = this.readPlatformService OfficeTransactionData officeTransactionData = this.readPlatformService
.retrieveNewOfficeTransactionDetails(); .retrieveNewOfficeTransactionDetails();
@@ -63,15 +59,9 @@ public class OfficeTransactionsApiResource {
@POST @POST
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response transferMoneyFrom(final BranchMoneyTransferCommand command) { public Response transferMoneyFrom(final String jsonRequestBody) {
LocalDate transactionLocalDate = apiDataConversionService.convertFrom(command.getTransactionDate(), "transactionDate", command.getDateFormat()); BranchMoneyTransferCommand command = this.apiDataConversionService.convertJsonToBranchMoneyTransferCommand(jsonRequestBody);
command.setTransactionLocalDate(transactionLocalDate);
Locale clientLocale = this.apiDataConversionService.localeFromString(command.getLocale());
BigDecimal transactionAmountValue = apiDataConversionService.convertFrom(command.getTransactionAmount(), "transactionAmount", clientLocale);
command.setTransactionAmountValue(transactionAmountValue);
Long id = this.writePlatformService.externalBranchMoneyTransfer(command); Long id = this.writePlatformService.externalBranchMoneyTransfer(command);
return Response.ok().entity(new EntityIdentifier(id)).build(); return Response.ok().entity(new EntityIdentifier(id)).build();
@@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
@Path("/reports") @Path("/reports")
@Component @Component
@Scope("singleton") @Scope("singleton")
public class ReportingApiResource { public class ReportsApiResource {
private String allowedFieldList = ""; private String allowedFieldList = "";
private String filterName = "myFilter"; private String filterName = "myFilter";
@@ -38,9 +38,9 @@ public class ReportingApiResource {
private ApiJSONFormattingService jsonFormattingService; private ApiJSONFormattingService jsonFormattingService;
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload" }) @Produces({MediaType.APPLICATION_JSON, "application/x-msdownload" })
public Response retrieveReportList(@Context UriInfo uriInfo) { public Response retrieveReportList(@Context final UriInfo uriInfo) {
MultivaluedMap<String, String> queryParams = uriInfo MultivaluedMap<String, String> queryParams = uriInfo
.getQueryParameters(); .getQueryParameters();
@@ -70,12 +70,12 @@ public class ReportingApiResource {
@GET @GET
@Path("{reportName}") @Path("{reportName}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON, "application/x-msdownload", @Produces({MediaType.APPLICATION_JSON, "application/x-msdownload",
"application/vnd.ms-excel", "application/pdf", "text/html" }) "application/vnd.ms-excel", "application/pdf", "text/html" })
public Response retrieveReport( public Response retrieveReport(
@PathParam("reportName") final String reportName, @PathParam("reportName") final String reportName,
@Context UriInfo uriInfo) { @Context final UriInfo uriInfo) {
MultivaluedMap<String, String> queryParams = uriInfo MultivaluedMap<String, String> queryParams = uriInfo
.getQueryParameters(); .getQueryParameters();
@@ -18,6 +18,7 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.UserCommand; import org.mifosng.platform.api.commands.UserCommand;
import org.mifosng.platform.api.data.AppUserData; import org.mifosng.platform.api.data.AppUserData;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.user.service.AppUserReadPlatformService; import org.mifosng.platform.user.service.AppUserReadPlatformService;
import org.mifosng.platform.user.service.AppUserWritePlatformService; import org.mifosng.platform.user.service.AppUserWritePlatformService;
@@ -28,7 +29,7 @@ import org.springframework.stereotype.Component;
@Path("/users") @Path("/users")
@Component @Component
@Scope("singleton") @Scope("singleton")
public class UserApiResource { public class UsersApiResource {
private String allowedFieldList = "allowedOffices,availableRoles"; private String allowedFieldList = "allowedOffices,availableRoles";
private String filterName = "userFilter"; private String filterName = "userFilter";
@@ -39,16 +40,18 @@ public class UserApiResource {
@Autowired @Autowired
private AppUserWritePlatformService appUserWritePlatformService; private AppUserWritePlatformService appUserWritePlatformService;
@Autowired
private ApiDataConversionService apiDataConversionService;
@Autowired @Autowired
private ApiJSONFormattingService jsonFormattingService; private ApiJSONFormattingService jsonFormattingService;
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveUsers(@Context UriInfo uriInfo) { public String retrieveUsers(@Context final UriInfo uriInfo) {
Collection<AppUserData> users = this.appUserReadPlatformService Collection<AppUserData> users = this.appUserReadPlatformService.retrieveAllUsers();
.retrieveAllUsers();
String selectedFields = "id,officeId,officeName,username,firstname,lastname,email"; String selectedFields = "id,officeId,officeName,username,firstname,lastname,email";
return this.jsonFormattingService.convertRequest(users, filterName, return this.jsonFormattingService.convertRequest(users, filterName,
@@ -57,10 +60,9 @@ public class UserApiResource {
@GET @GET
@Path("{userId}") @Path("{userId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveUser(@PathParam("userId") final Long userId, public String retrieveUser(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) {
@Context UriInfo uriInfo) {
AppUserData user = this.appUserReadPlatformService.retrieveUser(userId); AppUserData user = this.appUserReadPlatformService.retrieveUser(userId);
@@ -71,9 +73,9 @@ public class UserApiResource {
@GET @GET
@Path("template") @Path("template")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String newUserDetails(@Context UriInfo uriInfo) { public String newUserDetails(@Context final UriInfo uriInfo) {
AppUserData newUser = this.appUserReadPlatformService AppUserData newUser = this.appUserReadPlatformService
.retrieveNewUserDetails(); .retrieveNewUserDetails();
@@ -84,18 +86,20 @@ public class UserApiResource {
} }
@POST @POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response createUser(UserCommand command) { public Response createUser(final String jsonRequestBody) {
UserCommand command = this.apiDataConversionService.convertJsonToUserCommand(null, jsonRequestBody);
Long userId = this.appUserWritePlatformService.createUser(command); Long userId = this.appUserWritePlatformService.createUser(command);
return Response.ok().entity(new EntityIdentifier(userId)).build(); return Response.ok().entity(new EntityIdentifier(userId)).build();
} }
@DELETE @DELETE
@Path("{userId}") @Path("{userId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response deleteUser(@PathParam("userId") final Long userId) { public Response deleteUser(@PathParam("userId") final Long userId) {
this.appUserWritePlatformService.deleteUser(userId); this.appUserWritePlatformService.deleteUser(userId);
@@ -105,12 +109,11 @@ public class UserApiResource {
@PUT @PUT
@Path("{userId}") @Path("{userId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response updateUser(@PathParam("userId") final Long userId, public Response updateUser(@PathParam("userId") final Long userId, final String jsonRequestBody) {
UserCommand command) {
command.setId(userId); UserCommand command = this.apiDataConversionService.convertJsonToUserCommand(userId, jsonRequestBody);
this.appUserWritePlatformService.updateUser(command); this.appUserWritePlatformService.updateUser(command);
@@ -2,106 +2,46 @@ package org.mifosng.platform.api.commands;
import java.math.BigDecimal; import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
@XmlRootElement /**
* Immutable command for adjusting loan transactions.
*/
public class AdjustLoanTransactionCommand { public class AdjustLoanTransactionCommand {
private Long loanId; private final Long loanId;
private Long transactionId; private final Long transactionId;
private String locale; private final LocalDate transactionDate;
private String dateFormat; private final BigDecimal transactionAmount;
private String transactionDate; private final String note;
private LocalDate transactionLocalDate;
private String note;
private String transactionAmount;
private BigDecimal transactionAmountValue;
protected AdjustLoanTransactionCommand() {
//
}
public AdjustLoanTransactionCommand(final Long loanId, final Long transactionId, public AdjustLoanTransactionCommand(final Long loanId, final Long transactionId,
final LocalDate transactionLocalDate, final String note, final LocalDate transactionLocalDate, final String note,
final BigDecimal transactionAmountValue) { final BigDecimal transactionAmountValue) {
this.loanId = loanId; this.loanId = loanId;
this.transactionId = transactionId; this.transactionId = transactionId;
this.transactionLocalDate = transactionLocalDate; this.transactionDate = transactionLocalDate;
this.transactionAmount = transactionAmountValue;
this.note = note; this.note = note;
this.transactionAmountValue = transactionAmountValue;
} }
public Long getLoanId() { public Long getLoanId() {
return this.loanId; return loanId;
}
public void setLoanId(final Long loanId) {
this.loanId = loanId;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
} }
public Long getTransactionId() { public Long getTransactionId() {
return transactionId; return transactionId;
} }
public void setTransactionId(Long transactionId) { public LocalDate getTransactionDate() {
this.transactionId = transactionId;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public String getTransactionDate() {
return transactionDate; return transactionDate;
} }
public void setTransactionDate(String transactionDate) { public BigDecimal getTransactionAmount() {
this.transactionDate = transactionDate; return transactionAmount;
}
public LocalDate getTransactionLocalDate() {
return transactionLocalDate;
}
public void setTransactionLocalDate(LocalDate transactionLocalDate) {
this.transactionLocalDate = transactionLocalDate;
} }
public String getNote() { public String getNote() {
return note; return note;
} }
public void setNote(String note) {
this.note = note;
}
public String getTransactionAmount() {
return transactionAmount;
}
public void setTransactionAmount(String transactionAmount) {
this.transactionAmount = transactionAmount;
}
public BigDecimal getTransactionAmountValue() {
return transactionAmountValue;
}
public void setTransactionAmountValue(BigDecimal transactionAmountValue) {
this.transactionAmountValue = transactionAmountValue;
}
} }
@@ -1,121 +1,60 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
/** /**
* Command used for transfering money between two branches. * Immutable command for transfering money between two branches.
*/ */
@XmlRootElement
public class BranchMoneyTransferCommand { public class BranchMoneyTransferCommand {
private Long id; private final Long fromOfficeId;
private Long fromOfficeId; private final Long toOfficeId;
private Long toOfficeId; private final LocalDate transactionDate;
private final String currencyCode;
private final BigDecimal transactionAmount;
private final String description;
private String dateFormat; private final Set<String> modifiedParameters;
private String transactionDate;
private LocalDate transactionLocalDate;
private String locale; public BranchMoneyTransferCommand(final Set<String> modifiedParameters, final Long fromOfficeId, final Long toOfficeId,
private String currencyCode; final LocalDate transactionDate, final String currencyCode, final BigDecimal transactionAmount, final String description) {
private String transactionAmount; this.modifiedParameters = modifiedParameters;
private BigDecimal transactionAmountValue; this.fromOfficeId = fromOfficeId;
this.toOfficeId = toOfficeId;
private String description; this.transactionDate = transactionDate;
this.currencyCode = currencyCode;
protected BranchMoneyTransferCommand() { this.transactionAmount = transactionAmount;
// this.description = description;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
} }
public Long getFromOfficeId() { public Long getFromOfficeId() {
return fromOfficeId; return fromOfficeId;
} }
public void setFromOfficeId(Long fromOfficeId) {
this.fromOfficeId = fromOfficeId;
}
public Long getToOfficeId() { public Long getToOfficeId() {
return toOfficeId; return toOfficeId;
} }
public void setToOfficeId(Long toOfficeId) { public LocalDate getTransactionDate() {
this.toOfficeId = toOfficeId;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public String getTransactionDate() {
return transactionDate; return transactionDate;
} }
public void setTransactionDate(String transactionDate) {
this.transactionDate = transactionDate;
}
public LocalDate getTransactionLocalDate() {
return transactionLocalDate;
}
public void setTransactionLocalDate(LocalDate transactionLocalDate) {
this.transactionLocalDate = transactionLocalDate;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public String getTransactionAmount() {
return transactionAmount;
}
public void setTransactionAmount(String transactionAmount) {
this.transactionAmount = transactionAmount;
}
public BigDecimal getTransactionAmountValue() {
return transactionAmountValue;
}
public void setTransactionAmountValue(BigDecimal transactionAmountValue) {
this.transactionAmountValue = transactionAmountValue;
}
public String getCurrencyCode() { public String getCurrencyCode() {
return currencyCode; return currencyCode;
} }
public void setCurrencyCode(String currencyCode) { public BigDecimal getTransactionAmount() {
this.currencyCode = currencyCode; return transactionAmount;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public boolean isFromOfficeIdChanged() {
this.description = description; return this.modifiedParameters.contains("fromOfficeId");
} }
} }
@@ -7,98 +7,50 @@ import org.joda.time.LocalDate;
@XmlRootElement @XmlRootElement
public class ClientCommand { public class ClientCommand {
private Long id; private final Long id;
private String firstname; private final String externalId;
private String lastname; private final String firstname;
private String clientOrBusinessName; private final String lastname;
private Long officeId; private final String clientOrBusinessName;
private String externalId; private final Long officeId;
private final LocalDate joiningDate;
private String dateFormat;
private String joiningDate;
private LocalDate joiningLocalDate;
protected ClientCommand() { public ClientCommand(final Long id, final String externalId, final String firstname, final String lastname, final String clientOrBusinessName,
// final Long officeId, final LocalDate joiningDate) {
} this.id = id;
this.externalId = externalId;
public ClientCommand(final String firstname, final String lastname, final String clientOrBusinessName, final Long officeId, final LocalDate joiningDate) {
this.firstname = firstname; this.firstname = firstname;
this.lastname = lastname; this.lastname = lastname;
this.clientOrBusinessName = clientOrBusinessName; this.clientOrBusinessName = clientOrBusinessName;
this.officeId = officeId; this.officeId = officeId;
this.joiningLocalDate = joiningDate; this.joiningDate = joiningDate;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(final String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return this.lastname;
}
public void setLastname(final String lastname) {
this.lastname = lastname;
}
public Long getOfficeId() {
return this.officeId;
}
public void setOfficeId(final Long officeId) {
this.officeId = officeId;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
} }
public Long getId() { public Long getId() {
return id; return id;
} }
public void setId(Long id) { public String getExternalId() {
this.id = id; return externalId;
} }
public String getJoiningDate() { public String getFirstname() {
return joiningDate; return firstname;
} }
public void setJoiningDate(String joiningDate) { public String getLastname() {
this.joiningDate = joiningDate; return lastname;
}
public LocalDate getJoiningLocalDate() {
return joiningLocalDate;
}
public void setJoiningLocalDate(LocalDate joiningLocalDate) {
this.joiningLocalDate = joiningLocalDate;
} }
public String getClientOrBusinessName() { public String getClientOrBusinessName() {
return clientOrBusinessName; return clientOrBusinessName;
} }
public void setClientOrBusinessName(String clientOrBusinessName) { public Long getOfficeId() {
this.clientOrBusinessName = clientOrBusinessName; return officeId;
}
public LocalDate getJoiningDate() {
return joiningDate;
} }
} }
@@ -1,68 +1,31 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
/** /**
* Use for any of the loan state transitions eg. reject, withdrawn by client, approve, disburse * Immutable command for any of the loan state transitions eg. reject, withdrawn by client, approve, disburse
*/ */
@XmlRootElement
public class LoanStateTransitionCommand { public class LoanStateTransitionCommand {
private Long loanId; private final Long loanId;
private String dateFormat; private final LocalDate eventDate;
private String eventDate; private final String note;
private LocalDate eventLocalDate;
private String note;
protected LoanStateTransitionCommand() { public LoanStateTransitionCommand(final Long loanId, final LocalDate eventDate, final String note) {
//
}
public LoanStateTransitionCommand(final Long loanId, final LocalDate eventDate, final String comment) {
this.loanId = loanId; this.loanId = loanId;
this.eventLocalDate = eventDate; this.eventDate = eventDate;
this.note = comment; this.note = note;
} }
public Long getLoanId() { public Long getLoanId() {
return this.loanId; return loanId;
} }
public void setLoanId(final Long loanId) { public LocalDate getEventDate() {
this.loanId = loanId;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public String getEventDate() {
return eventDate; return eventDate;
} }
public void setEventDate(String eventDate) {
this.eventDate = eventDate;
}
public LocalDate getEventLocalDate() {
return eventLocalDate;
}
public void setEventLocalDate(LocalDate eventLocalDate) {
this.eventLocalDate = eventLocalDate;
}
public String getNote() { public String getNote() {
return note; return note;
} }
public void setNote(String note) {
this.note = note;
}
} }
@@ -2,96 +2,38 @@ package org.mifosng.platform.api.commands;
import java.math.BigDecimal; import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
@XmlRootElement /**
* Immutable command for loan transactions.
*/
public class LoanTransactionCommand { public class LoanTransactionCommand {
private Long loanId; private final Long loanId;
private String locale; private final LocalDate transactionDate;
private String dateFormat; private final BigDecimal transactionAmount;
private String transactionDate; private final String note;
private LocalDate transactionLocalDate;
private String note;
private String transactionAmount;
private BigDecimal transactionAmountValue;
protected LoanTransactionCommand() { public LoanTransactionCommand(final Long loanId, final LocalDate paymentDate, final BigDecimal paymentAmount,final String note) {
//
}
public LoanTransactionCommand(final Long loanId,
final LocalDate paymentDate, final String note,
final BigDecimal paymentAmount) {
this.loanId = loanId; this.loanId = loanId;
this.transactionLocalDate = paymentDate; this.transactionDate = paymentDate;
this.transactionAmount = paymentAmount;
this.note = note; this.note = note;
this.transactionAmountValue = paymentAmount;
} }
public Long getLoanId() { public Long getLoanId() {
return this.loanId; return loanId;
} }
public void setLoanId(final Long loanId) { public LocalDate getTransactionDate() {
this.loanId = loanId;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public String getTransactionDate() {
return transactionDate; return transactionDate;
} }
public void setTransactionDate(String transactionDate) { public BigDecimal getTransactionAmount() {
this.transactionDate = transactionDate; return transactionAmount;
}
public LocalDate getTransactionLocalDate() {
return transactionLocalDate;
}
public void setTransactionLocalDate(LocalDate transactionLocalDate) {
this.transactionLocalDate = transactionLocalDate;
} }
public String getNote() { public String getNote() {
return note; return note;
} }
public void setNote(String note) {
this.note = note;
}
public String getTransactionAmount() {
return transactionAmount;
}
public void setTransactionAmount(String transactionAmount) {
this.transactionAmount = transactionAmount;
}
public BigDecimal getTransactionAmountValue() {
return transactionAmountValue;
}
public void setTransactionAmountValue(BigDecimal transactionAmountValue) {
this.transactionAmountValue = transactionAmountValue;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
} }
@@ -38,7 +38,15 @@ public class RoleCommand {
return permissions; return permissions;
} }
public Set<String> getModifiedParameters() { public boolean isNameChanged() {
return modifiedParameters; return this.modifiedParameters.contains("name");
}
public boolean isDescriptionChanged() {
return this.modifiedParameters.contains("description");
}
public boolean isPermissionsChanged() {
return this.modifiedParameters.contains("permissions");
} }
} }
@@ -2,346 +2,166 @@ package org.mifosng.platform.api.commands;
import java.math.BigDecimal; import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.platform.api.data.LoanSchedule; import org.mifosng.platform.api.data.LoanSchedule;
@XmlRootElement /**
* Immutable command for submitting new loan application.
*/
public class SubmitLoanApplicationCommand { public class SubmitLoanApplicationCommand {
private Long clientId; private final Long clientId;
private Long productId; private final Long productId;
private final String externalId;
// product private final Long fundId;
private Long fundId;
private String locale; private final BigDecimal principal;
private BigDecimal principalValue; private final BigDecimal inArrearsTolerance;
private String principal;
private BigDecimal inArrearsToleranceValue;
private String inArrearsTolerance;
private String numberOfRepayments; private final Integer numberOfRepayments;
private Integer numberOfRepaymentsValue; private final Integer repaymentEvery;
private String repaymentEvery;
private Integer repaymentEveryValue;
private String interestRatePerPeriod; private final BigDecimal interestRatePerPeriod;
private BigDecimal interestRatePerPeriodValue;
private Integer repaymentFrequencyType; private final Integer repaymentFrequencyType;
private Integer interestRateFrequencyType; private final Integer interestRateFrequencyType;
private Integer amortizationType; private final Integer amortizationType;
private Integer interestType; private final Integer interestType;
private Integer interestCalculationPeriodType; private final Integer interestCalculationPeriodType;
// end of product related fields
private String expectedDisbursementDate; private final LocalDate expectedDisbursementDate;
private String repaymentsStartingFromDate; private final LocalDate repaymentsStartingFromDate;
private String interestChargedFromDate; private final LocalDate interestChargedFromDate;
private LocalDate expectedDisbursementLocalDate; private final LocalDate submittedOnDate;
private LocalDate repaymentsStartingFromLocalDate; private final String submittedOnNote;
private LocalDate interestChargedFromLocalDate;
private String dateFormat;
private String submittedOnDate;
private LocalDate submittedOnLocalDate;
private String submittedOnNote;
private String externalId;
private LoanSchedule loanSchedule; private LoanSchedule loanSchedule;
protected SubmitLoanApplicationCommand() { public SubmitLoanApplicationCommand(
// final Long clientId, final Long productId, final String externalId, final Long fundId,
} final LocalDate submittedOnDate, final String submittedOnNote,
public SubmitLoanApplicationCommand(final Long clientId,
final Long productId, final LocalDate submittedOnDate,
final String submittedOnNote,
final LocalDate expectedDisbursementDate, final LocalDate expectedDisbursementDate,
final LocalDate repaymentsStartingFromDate, final LocalDate repaymentsStartingFromDate,
final LocalDate interestChargedFromLocalDate, final LocalDate interestChargedFromLocalDate,
final LoanSchedule loanSchedule, final BigDecimal principal,
final Number principal, final BigDecimal interestRatePerPeriod,
final Number interestRatePerPeriod, Integer interestRateFrequencyMethod, final Integer interestMethod, final Integer interestCalculationPeriodMethod, final Integer interestRateFrequencyMethod,
final Integer repaymentEvery, final Integer repaymentFrequency, final Integer numberOfRepayments, Integer amortizationMethod, final Number toleranceAmount) { final Integer interestMethod,
final Integer interestCalculationPeriodMethod,
final Integer repaymentEvery, final Integer repaymentFrequency, final Integer numberOfRepayments, Integer amortizationMethod,
final BigDecimal toleranceAmount) {
this.clientId = clientId; this.clientId = clientId;
this.productId = productId; this.productId = productId;
this.submittedOnLocalDate = submittedOnDate; this.externalId = externalId;
this.submittedOnNote = submittedOnNote; this.fundId = fundId;
this.expectedDisbursementLocalDate = expectedDisbursementDate;
this.repaymentsStartingFromLocalDate = repaymentsStartingFromDate;
this.interestChargedFromLocalDate = interestChargedFromLocalDate;
this.loanSchedule = loanSchedule;
this.inArrearsToleranceValue = BigDecimal.valueOf(toleranceAmount.doubleValue());
this.principalValue = BigDecimal.valueOf(principal.doubleValue()); this.submittedOnDate = submittedOnDate;
this.interestRatePerPeriodValue = BigDecimal.valueOf(interestRatePerPeriod.doubleValue()); this.submittedOnNote = submittedOnNote;
this.expectedDisbursementDate = expectedDisbursementDate;
this.repaymentsStartingFromDate = repaymentsStartingFromDate;
this.interestChargedFromDate = interestChargedFromLocalDate;
this.principal = principal;
this.inArrearsTolerance = toleranceAmount;
this.interestRatePerPeriod = interestRatePerPeriod;
this.interestRateFrequencyType = interestRateFrequencyMethod; this.interestRateFrequencyType = interestRateFrequencyMethod;
this.interestType = interestMethod; this.interestType = interestMethod;
this.interestCalculationPeriodType = interestCalculationPeriodMethod; this.interestCalculationPeriodType = interestCalculationPeriodMethod;
this.repaymentEveryValue = repaymentEvery; this.repaymentEvery = repaymentEvery;
this.repaymentFrequencyType = repaymentFrequency; this.repaymentFrequencyType = repaymentFrequency;
this.numberOfRepaymentsValue = numberOfRepayments; this.numberOfRepayments = numberOfRepayments;
this.amortizationType = amortizationMethod; this.amortizationType = amortizationMethod;
} }
public CalculateLoanScheduleCommand toCalculateLoanScheduleCommand() { public CalculateLoanScheduleCommand toCalculateLoanScheduleCommand() {
return new CalculateLoanScheduleCommand(productId, return new CalculateLoanScheduleCommand(productId,
principalValue, interestRatePerPeriodValue, interestRateFrequencyType, interestType, interestCalculationPeriodType, repaymentEveryValue, repaymentFrequencyType, numberOfRepaymentsValue, amortizationType, principal, interestRatePerPeriod, interestRateFrequencyType, interestType, interestCalculationPeriodType, repaymentEvery, repaymentFrequencyType, numberOfRepayments, amortizationType,
expectedDisbursementLocalDate, repaymentsStartingFromLocalDate, interestChargedFromLocalDate); expectedDisbursementDate, repaymentsStartingFromDate, interestChargedFromDate);
}
public Long getProductId() {
return this.productId;
}
public void setProductId(final Long productId) {
this.productId = productId;
}
public String getSubmittedOnNote() {
return this.submittedOnNote;
}
public void setSubmittedOnNote(final String submittedOnNote) {
this.submittedOnNote = submittedOnNote;
} }
public LoanSchedule getLoanSchedule() { public LoanSchedule getLoanSchedule() {
return this.loanSchedule; return loanSchedule;
} }
public void setLoanSchedule(final LoanSchedule loanSchedule) { public void setLoanSchedule(LoanSchedule loanSchedule) {
this.loanSchedule = loanSchedule; this.loanSchedule = loanSchedule;
} }
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public Long getClientId() { public Long getClientId() {
return clientId; return clientId;
} }
public void setClientId(Long clientId) { public Long getProductId() {
this.clientId = clientId; return productId;
} }
public String getLocale() { public String getExternalId() {
return locale; return externalId;
}
public void setLocale(String locale) {
this.locale = locale;
}
public BigDecimal getPrincipalValue() {
return principalValue;
}
public void setPrincipalValue(BigDecimal principalValue) {
this.principalValue = principalValue;
}
public String getPrincipal() {
return principal;
}
public void setPrincipal(String principal) {
this.principal = principal;
}
public BigDecimal getInArrearsToleranceValue() {
return inArrearsToleranceValue;
}
public void setInArrearsToleranceValue(BigDecimal inArrearsToleranceValue) {
this.inArrearsToleranceValue = inArrearsToleranceValue;
}
public String getInArrearsTolerance() {
return inArrearsTolerance;
}
public void setInArrearsTolerance(String inArrearsTolerance) {
this.inArrearsTolerance = inArrearsTolerance;
}
public String getNumberOfRepayments() {
return numberOfRepayments;
}
public void setNumberOfRepayments(String numberOfRepayments) {
this.numberOfRepayments = numberOfRepayments;
}
public Integer getNumberOfRepaymentsValue() {
return numberOfRepaymentsValue;
}
public void setNumberOfRepaymentsValue(Integer numberOfRepaymentsValue) {
this.numberOfRepaymentsValue = numberOfRepaymentsValue;
}
public String getRepaymentEvery() {
return repaymentEvery;
}
public void setRepaymentEvery(String repaymentEvery) {
this.repaymentEvery = repaymentEvery;
}
public Integer getRepaymentEveryValue() {
return repaymentEveryValue;
}
public void setRepaymentEveryValue(Integer repaymentEveryValue) {
this.repaymentEveryValue = repaymentEveryValue;
}
public String getInterestRatePerPeriod() {
return interestRatePerPeriod;
}
public void setInterestRatePerPeriod(String interestRatePerPeriod) {
this.interestRatePerPeriod = interestRatePerPeriod;
}
public BigDecimal getInterestRatePerPeriodValue() {
return interestRatePerPeriodValue;
}
public void setInterestRatePerPeriodValue(BigDecimal interestRatePerPeriodValue) {
this.interestRatePerPeriodValue = interestRatePerPeriodValue;
}
public Integer getRepaymentFrequencyType() {
return repaymentFrequencyType;
}
public void setRepaymentFrequencyType(Integer repaymentFrequencyType) {
this.repaymentFrequencyType = repaymentFrequencyType;
}
public Integer getInterestRateFrequencyType() {
return interestRateFrequencyType;
}
public void setInterestRateFrequencyType(Integer interestRateFrequencyType) {
this.interestRateFrequencyType = interestRateFrequencyType;
}
public Integer getAmortizationType() {
return amortizationType;
}
public void setAmortizationType(Integer amortizationType) {
this.amortizationType = amortizationType;
}
public Integer getInterestType() {
return interestType;
}
public void setInterestType(Integer interestType) {
this.interestType = interestType;
}
public Integer getInterestCalculationPeriodType() {
return interestCalculationPeriodType;
}
public void setInterestCalculationPeriodType(
Integer interestCalculationPeriodType) {
this.interestCalculationPeriodType = interestCalculationPeriodType;
}
public String getExpectedDisbursementDate() {
return expectedDisbursementDate;
}
public void setExpectedDisbursementDate(String expectedDisbursementDate) {
this.expectedDisbursementDate = expectedDisbursementDate;
}
public String getRepaymentsStartingFromDate() {
return repaymentsStartingFromDate;
}
public void setRepaymentsStartingFromDate(String repaymentsStartingFromDate) {
this.repaymentsStartingFromDate = repaymentsStartingFromDate;
}
public LocalDate getExpectedDisbursementLocalDate() {
return expectedDisbursementLocalDate;
}
public void setExpectedDisbursementLocalDate(
LocalDate expectedDisbursementLocalDate) {
this.expectedDisbursementLocalDate = expectedDisbursementLocalDate;
}
public LocalDate getRepaymentsStartingFromLocalDate() {
return repaymentsStartingFromLocalDate;
}
public void setRepaymentsStartingFromLocalDate(
LocalDate repaymentsStartingFromLocalDate) {
this.repaymentsStartingFromLocalDate = repaymentsStartingFromLocalDate;
}
public LocalDate getInterestChargedFromLocalDate() {
return interestChargedFromLocalDate;
}
public void setInterestChargedFromLocalDate(
LocalDate interestChargedFromLocalDate) {
this.interestChargedFromLocalDate = interestChargedFromLocalDate;
}
public String getSubmittedOnDate() {
return submittedOnDate;
}
public void setSubmittedOnDate(String submittedOnDate) {
this.submittedOnDate = submittedOnDate;
}
public LocalDate getSubmittedOnLocalDate() {
return submittedOnLocalDate;
}
public void setSubmittedOnLocalDate(LocalDate submittedOnLocalDate) {
this.submittedOnLocalDate = submittedOnLocalDate;
}
public String getInterestChargedFromDate() {
return interestChargedFromDate;
}
public void setInterestChargedFromDate(String interestChargedFromDate) {
this.interestChargedFromDate = interestChargedFromDate;
} }
public Long getFundId() { public Long getFundId() {
return fundId; return fundId;
} }
public void setFundId(Long fundId) { public BigDecimal getPrincipal() {
this.fundId = fundId; return principal;
}
public BigDecimal getInArrearsTolerance() {
return inArrearsTolerance;
}
public Integer getNumberOfRepayments() {
return numberOfRepayments;
}
public Integer getRepaymentEvery() {
return repaymentEvery;
}
public BigDecimal getInterestRatePerPeriod() {
return interestRatePerPeriod;
}
public Integer getRepaymentFrequencyType() {
return repaymentFrequencyType;
}
public Integer getInterestRateFrequencyType() {
return interestRateFrequencyType;
}
public Integer getAmortizationType() {
return amortizationType;
}
public Integer getInterestType() {
return interestType;
}
public Integer getInterestCalculationPeriodType() {
return interestCalculationPeriodType;
}
public LocalDate getExpectedDisbursementDate() {
return expectedDisbursementDate;
}
public LocalDate getRepaymentsStartingFromDate() {
return repaymentsStartingFromDate;
}
public LocalDate getInterestChargedFromDate() {
return interestChargedFromDate;
}
public LocalDate getSubmittedOnDate() {
return submittedOnDate;
}
public String getSubmittedOnNote() {
return submittedOnNote;
} }
} }
@@ -1,13 +1,12 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
/**
* Immutable command for undo'ing a state transition.
*/
public class UndoStateTransitionCommand { public class UndoStateTransitionCommand {
private Long loanId; private final Long loanId;
private String note; private final String note;
protected UndoStateTransitionCommand() {
//
}
public UndoStateTransitionCommand(final Long loanId, final String note) { public UndoStateTransitionCommand(final Long loanId, final String note) {
this.loanId = loanId; this.loanId = loanId;
@@ -18,15 +17,7 @@ public class UndoStateTransitionCommand {
return this.loanId; return this.loanId;
} }
public void setLoanId(final Long loanId) {
this.loanId = loanId;
}
public String getNote() { public String getNote() {
return note; return note;
} }
public void setNote(String note) {
this.note = note;
}
} }
@@ -1,112 +1,89 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
/** /**
* create or update user details command. * Immutable command for creating or updating details of a User.
*/ */
@XmlRootElement
public class UserCommand implements Serializable { public class UserCommand implements Serializable {
private Long id; private final Long id;
private String username; private final String username;
private String firstname; private final String firstname;
private String lastname; private final String lastname;
private String password; private final String password;
private String repeatPassword; private final String repeatPassword;
private String email; private final String email;
private Long officeId; private final Long officeId;
private String[] notSelectedRoles; private final String[] notSelectedRoles;
private String[] roles; private final String[] roles;
private final Set<String> modifiedParameters;
public UserCommand() { public UserCommand(final Set<String> modifiedParameters, final Long id,
// final String username, final String firstname, final String lastname,
final String password, final String repeatPassword, final String email,
final Long officeId, final String[] notSelectedRoles, final String[] roles) {
this.modifiedParameters = modifiedParameters;
this.id = id;
this.username = username;
this.firstname = firstname;
this.lastname = lastname;
this.password = password;
this.repeatPassword = repeatPassword;
this.email = email;
this.officeId = officeId;
this.notSelectedRoles = notSelectedRoles;
this.roles = roles;
} }
public String getDisplayName() { public String getDisplayName() {
return new StringBuilder(this.lastname).append(", ").append(this.firstname).toString(); return new StringBuilder(this.lastname).append(", ").append(this.firstname).toString();
} }
public Long getId() {
return id;
}
public String getUsername() { public String getUsername() {
return this.username; return username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(final String password) {
this.password = password;
}
public String getEmail() {
return this.email;
}
public void setEmail(final String email) {
this.email = email;
}
public Long getOfficeId() {
return this.officeId;
}
public void setOfficeId(final Long officeId) {
this.officeId = officeId;
} }
public String getFirstname() { public String getFirstname() {
return firstname; return firstname;
} }
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() { public String getLastname() {
return lastname; return lastname;
} }
public void setLastname(String lastname) { public String getPassword() {
this.lastname = lastname; return password;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String[] getNotSelectedRoles() {
return notSelectedRoles;
}
public void setNotSelectedRoles(String... notSelectedRoles) {
this.notSelectedRoles = notSelectedRoles;
}
public String[] getRoles() {
return roles;
}
public void setRoles(String... roles) {
this.roles = roles;
} }
public String getRepeatPassword() { public String getRepeatPassword() {
return repeatPassword; return repeatPassword;
} }
public void setRepeatPassword(String repeatPassword) { public String getEmail() {
this.repeatPassword = repeatPassword; return email;
}
public Long getOfficeId() {
return officeId;
}
public String[] getNotSelectedRoles() {
return notSelectedRoles;
}
public String[] getRoles() {
return roles;
}
public boolean isUsernameChanged() {
return this.modifiedParameters.contains("username");
} }
} }
@@ -1,28 +1,19 @@
package org.mifosng.platform.api.infrastructure; package org.mifosng.platform.api.infrastructure;
import java.math.BigDecimal; import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import java.util.Locale; import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
import org.mifosng.platform.api.commands.ClientCommand;
import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.FundCommand; import org.mifosng.platform.api.commands.FundCommand;
import org.mifosng.platform.api.commands.LoanProductCommand; import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.OfficeCommand; import org.mifosng.platform.api.commands.OfficeCommand;
import org.mifosng.platform.api.commands.RoleCommand; import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.platform.api.commands.UserCommand;
public interface ApiDataConversionService { public interface ApiDataConversionService {
LocalDate convertFrom(String dateAsString, String parameterName,
String dateFormat);
Integer convertToInteger(String digitsAfterDecimal, String string, Locale clientApplicationLocale);
BigDecimal convertFrom(String principalFormatted, String parameterName,
Locale clientApplicationLocale);
Locale localeFromString(String locale);
Locale localeFrom(String languageCode, String courntryCode, String variantCode);
LoanProductCommand convertJsonToLoanProductCommand(Long resourceIdentifier, String json); LoanProductCommand convertJsonToLoanProductCommand(Long resourceIdentifier, String json);
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json); FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
@@ -30,4 +21,19 @@ public interface ApiDataConversionService {
OfficeCommand convertJsonToOfficeCommand(Long resourceIdentifier, String json); OfficeCommand convertJsonToOfficeCommand(Long resourceIdentifier, String json);
RoleCommand convertJsonToRoleCommand(Long resourceIdentifier, String json); RoleCommand convertJsonToRoleCommand(Long resourceIdentifier, String json);
UserCommand convertJsonToUserCommand(Long resourceIdentifier, String json);
BranchMoneyTransferCommand convertJsonToBranchMoneyTransferCommand(String jsonRequestBody);
ClientCommand convertJsonToClientCommand(Long resourceIdentifier, String jsonRequestBody);
SubmitLoanApplicationCommand convertJsonToSubmitLoanApplicationCommand(String jsonRequestBody);
LoanStateTransitionCommand convertJsonToLoanStateTransitionCommand(Long resourceIdentifier, String jsonRequestBody);
LoanTransactionCommand convertJsonToLoanTransactionCommand(Long resourceIdentifier, String jsonRequestBody);
AdjustLoanTransactionCommand convertJsonToAdjustLoanTransactionCommand(
Long loanId, Long transactionId, String jsonRequestBody);
} }
@@ -17,10 +17,17 @@ import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
import org.mifosng.platform.api.commands.ClientCommand;
import org.mifosng.platform.api.commands.FundCommand; import org.mifosng.platform.api.commands.FundCommand;
import org.mifosng.platform.api.commands.LoanProductCommand; import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.OfficeCommand; import org.mifosng.platform.api.commands.OfficeCommand;
import org.mifosng.platform.api.commands.RoleCommand; import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.platform.api.commands.UserCommand;
import org.mifosng.platform.api.data.ApiParameterError; import org.mifosng.platform.api.data.ApiParameterError;
import org.mifosng.platform.api.errorhandling.InvalidJsonException; import org.mifosng.platform.api.errorhandling.InvalidJsonException;
import org.mifosng.platform.api.errorhandling.UnsupportedParameterException; import org.mifosng.platform.api.errorhandling.UnsupportedParameterException;
@@ -45,8 +52,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
gsonConverter = new Gson(); gsonConverter = new Gson();
} }
@Override private LocalDate convertFrom(final String dateAsString, final String parameterName, final String dateFormat) {
public LocalDate convertFrom(final String dateAsString, final String parameterName, final String dateFormat) {
if (StringUtils.isBlank(dateFormat)) { if (StringUtils.isBlank(dateFormat)) {
@@ -88,8 +94,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
return eventLocalDate; return eventLocalDate;
} }
@Override private Integer convertToInteger(String numericalValueFormatted, String parameterName, Locale clientApplicationLocale) {
public Integer convertToInteger(String numericalValueFormatted, String parameterName, Locale clientApplicationLocale) {
try { try {
Integer number = null; Integer number = null;
@@ -142,8 +147,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
} }
} }
@Override private BigDecimal convertFrom(final String numericalValueFormatted, final String parameterName, final Locale clientApplicationLocale) {
public BigDecimal convertFrom(final String numericalValueFormatted, final String parameterName, final Locale clientApplicationLocale) {
if (clientApplicationLocale == null) { if (clientApplicationLocale == null) {
@@ -196,8 +200,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
} }
} }
@Override private Locale localeFromString(final String localeAsString) {
public Locale localeFromString(final String localeAsString) {
if (StringUtils.isBlank(localeAsString)) { if (StringUtils.isBlank(localeAsString)) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
@@ -233,8 +236,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
return localeFrom(languageCode, courntryCode, variantCode); return localeFrom(languageCode, courntryCode, variantCode);
} }
@Override private Locale localeFrom(final String languageCode, final String courntryCode, final String variantCode) {
public Locale localeFrom(final String languageCode, final String courntryCode, final String variantCode) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
@@ -271,11 +273,10 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType(); Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap); Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>( Set<String> supportedParams = new HashSet<String>(
Arrays.asList("name", "description", "fundId", "currencyCode", "digitsAfterDecimalValue", Arrays.asList("name", "description", "fundId", "currencyCode", "digitsAfterDecimalValue",
"principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments", "principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType") "repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType", "locale")
); );
checkForUnsupportedParameters(requestMap, supportedParams); checkForUnsupportedParameters(requestMap, supportedParams);
@@ -395,6 +396,244 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
return new RoleCommand(modifiedParameters, resourceIdentifier, name, description, permissionIds); return new RoleCommand(modifiedParameters, resourceIdentifier, name, description, permissionIds);
} }
@Override
public UserCommand convertJsonToUserCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("username", "firstname", "lastname", "password", "repeatPassword", "email", "officeId", "notSelectedRoles", "roles")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
String username = extractStringParameter("username", requestMap, modifiedParameters);
String firstname = extractStringParameter("firstname", requestMap, modifiedParameters);
String lastname = extractStringParameter("lastname", requestMap, modifiedParameters);
String password = extractStringParameter("password", requestMap, modifiedParameters);
String repeatPassword = extractStringParameter("repeatPassword", requestMap, modifiedParameters);
String email = extractStringParameter("email", requestMap, modifiedParameters);
Long officeId = extractLongParameter("officeId", requestMap, modifiedParameters);
// check array
JsonParser parser = new JsonParser();
String[] notSelectedRoles = null;
String[] roles = null;
JsonElement element = parser.parse(json);
if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
if (object.has("notSelectedRoles")) {
modifiedParameters.add("notSelectedRoles");
JsonArray array = object.get("notSelectedRoles").getAsJsonArray();
notSelectedRoles = new String[array.size()];
for (int i=0; i<array.size(); i++) {
notSelectedRoles[i] = array.get(i).getAsString();
}
}
if (object.has("roles")) {
modifiedParameters.add("roles");
JsonArray array = object.get("roles").getAsJsonArray();
roles = new String[array.size()];
for (int i=0; i<array.size(); i++) {
roles[i] = array.get(i).getAsString();
}
}
}
//
return new UserCommand(modifiedParameters, resourceIdentifier, username, firstname, lastname, password, repeatPassword, email, officeId, notSelectedRoles, roles);
}
@Override
public BranchMoneyTransferCommand convertJsonToBranchMoneyTransferCommand(final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("fromOfficeId", "toOfficeId", "transactionDate", "currencyCode", "transactionAmount", "description", "locale", "dateFormat")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
Long fromOfficeId = extractLongParameter("fromOfficeId", requestMap, modifiedParameters);
Long toOfficeId = extractLongParameter("toOfficeId", requestMap, modifiedParameters);
LocalDate transactionLocalDate = extractLocalDateParameter("transactionDate", requestMap, modifiedParameters);
String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters);
BigDecimal transactionAmountValue = extractBigDecimalParameter("transactionAmount", requestMap, modifiedParameters);
String description = extractStringParameter("description", requestMap, modifiedParameters);
return new BranchMoneyTransferCommand(modifiedParameters, fromOfficeId, toOfficeId, transactionLocalDate, currencyCode, transactionAmountValue, description);
}
@Override
public ClientCommand convertJsonToClientCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("externalId", "firstname", "lastname", "clientOrBusinessName", "officeId", "joiningDate", "dateFormat")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
String externalId = extractStringParameter("externalId", requestMap, modifiedParameters);
Long officeId = extractLongParameter("officeId", requestMap, modifiedParameters);
LocalDate joiningDate = extractLocalDateParameter("joiningDate", requestMap, modifiedParameters);
String firstname = extractStringParameter("firstname", requestMap, modifiedParameters);
String lastname = extractStringParameter("lastname", requestMap, modifiedParameters);
String clientOrBusinessName = extractStringParameter("clientOrBusinessName", requestMap, modifiedParameters);
return new ClientCommand(resourceIdentifier, externalId, firstname, lastname, clientOrBusinessName, officeId, joiningDate);
}
@Override
public SubmitLoanApplicationCommand convertJsonToSubmitLoanApplicationCommand(final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("clientId", "productId", "externalId", "fundId",
"principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType",
"expectedDisbursementDate", "repaymentsStartingFromDate", "interestChargedFromDate", "submittedOnDate", "submittedOnNote",
"locale", "dateFormat")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
Long clientId = extractLongParameter("clientId", requestMap, modifiedParameters);
Long productId = extractLongParameter("productId", requestMap, modifiedParameters);
Long fundId = extractLongParameter("fundId", requestMap, modifiedParameters);
String externalId = extractStringParameter("externalId", requestMap, modifiedParameters);
BigDecimal principal = extractBigDecimalParameter("principal", requestMap, modifiedParameters);
BigDecimal inArrearsToleranceValue = extractBigDecimalParameter("inArrearsTolerance", requestMap, modifiedParameters);
BigDecimal interestRatePerPeriod = extractBigDecimalParameter("interestRatePerPeriod", requestMap, modifiedParameters);
Integer repaymentEvery = extractIntegerParameter("repaymentEvery", requestMap, modifiedParameters);
Integer numberOfRepayments = extractIntegerParameter("numberOfRepayments", requestMap, modifiedParameters);
Integer repaymentFrequencyType = extractIntegerParameter("repaymentFrequencyType", requestMap, modifiedParameters);
Integer interestRateFrequencyTypeValue = extractIntegerParameter("interestRateFrequencyType", requestMap, modifiedParameters);
Integer amortizationTypeValue = extractIntegerParameter("amortizationType", requestMap, modifiedParameters);
Integer interestTypeValue = extractIntegerParameter("interestType", requestMap, modifiedParameters);
Integer interestCalculationPeriodTypeValue = extractIntegerParameter("interestCalculationPeriodType", requestMap, modifiedParameters);
LocalDate expectedDisbursementDate = extractLocalDateParameter("expectedDisbursementDate", requestMap, modifiedParameters);
LocalDate repaymentsStartingFromDate = extractLocalDateParameter("repaymentsStartingFromDate", requestMap, modifiedParameters);
LocalDate interestChargedFromDate = extractLocalDateParameter("interestChargedFromDate", requestMap, modifiedParameters);
LocalDate submittedOnDate = extractLocalDateParameter("submittedOnDate", requestMap, modifiedParameters);
String submittedOnNote = extractStringParameter("submittedOnNote", requestMap, modifiedParameters);
return new SubmitLoanApplicationCommand(clientId, productId, externalId, fundId, submittedOnDate, submittedOnNote,
expectedDisbursementDate, repaymentsStartingFromDate, interestChargedFromDate,
principal, interestRatePerPeriod, interestRateFrequencyTypeValue, interestTypeValue, interestCalculationPeriodTypeValue,
repaymentEvery, repaymentFrequencyType, numberOfRepayments, amortizationTypeValue, inArrearsToleranceValue);
}
@Override
public LoanStateTransitionCommand convertJsonToLoanStateTransitionCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("eventDate", "note", "dateFormat")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
LocalDate eventDate = extractLocalDateParameter("eventDate", requestMap, modifiedParameters);
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new LoanStateTransitionCommand(resourceIdentifier, eventDate, note);
}
@Override
public LoanTransactionCommand convertJsonToLoanTransactionCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("transactionDate", "transactionAmount", "note", "dateFormat", "locale")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
LocalDate paymentDate = extractLocalDateParameter("paymentDate", requestMap, modifiedParameters);
BigDecimal paymentAmount = extractBigDecimalParameter("paymentAmount", requestMap, modifiedParameters);
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new LoanTransactionCommand(resourceIdentifier, paymentDate, paymentAmount, note);
}
@Override
public AdjustLoanTransactionCommand convertJsonToAdjustLoanTransactionCommand(
final Long loanId, final Long transactionId, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("transactionDate", "transactionAmount", "note", "dateFormat", "locale")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
LocalDate transactionDate = extractLocalDateParameter("paymentDate", requestMap, modifiedParameters);
BigDecimal transactionAmount = extractBigDecimalParameter("paymentAmount", requestMap, modifiedParameters);
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new AdjustLoanTransactionCommand(loanId, transactionId, transactionDate, note, transactionAmount);
}
private void checkForUnsupportedParameters(Map<String, ?> requestMap, Set<String> supportedParams) { private void checkForUnsupportedParameters(Map<String, ?> requestMap, Set<String> supportedParams) {
List<String> unsupportedParameterList = new ArrayList<String>(); List<String> unsupportedParameterList = new ArrayList<String>();
@@ -79,7 +79,7 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
} }
public void update(ClientCommand command) { public void update(ClientCommand command) {
this.joiningDate = command.getJoiningLocalDate().toDate(); this.joiningDate = command.getJoiningDate().toDate();
this.firstName = command.getFirstname(); this.firstName = command.getFirstname();
this.lastName = command.getLastname(); this.lastName = command.getLastname();
@@ -35,7 +35,7 @@ public class ClientCommandValidator {
baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).ignoreIfNull().notNull().greaterThanZero(); baseDataValidator.reset().parameter("officeId").value(command.getOfficeId()).ignoreIfNull().notNull().greaterThanZero();
baseDataValidator.reset().anyOfNotNull(command.getFirstname(), command.getLastname(), command.getClientOrBusinessName(), baseDataValidator.reset().anyOfNotNull(command.getFirstname(), command.getLastname(), command.getClientOrBusinessName(),
command.getJoiningLocalDate(), command.getExternalId(), command.getOfficeId()); command.getJoiningDate(), command.getExternalId(), command.getOfficeId());
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
@@ -56,7 +56,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
firstname = null; firstname = null;
} }
Client newClient = Client.newClient(clientOffice, firstname, lastname, command.getJoiningLocalDate(), command.getExternalId()); Client newClient = Client.newClient(clientOffice, firstname, lastname, command.getJoiningDate(), command.getExternalId());
this.clientRepository.save(newClient); this.clientRepository.save(newClient);
@@ -88,12 +88,11 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
firstname = null; firstname = null;
} }
// Client clientForUpdate = this.clientRepository.findOne(clientsThatMatch(currentUser.getOrganisation(), command.getId()));
Client clientForUpdate = this.clientRepository.findOne(command.getId()); Client clientForUpdate = this.clientRepository.findOne(command.getId());
if (clientForUpdate == null) { if (clientForUpdate == null) {
throw new ClientNotFoundException(command.getId()); throw new ClientNotFoundException(command.getId());
} }
clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningLocalDate()); clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningDate());
this.clientRepository.save(clientForUpdate); this.clientRepository.save(clientForUpdate);
@@ -29,13 +29,13 @@ public class AdjustLoanTransactionCommandValidator {
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
if (command.getTransactionLocalDate() == null) { if (command.getTransactionDate() == null) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDate cannot be blank.", "transactionDate"); ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.date.cannot.be.blank", "The parameter transactionDate cannot be blank.", "transactionDate");
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
if (command.getTransactionAmountValue() == null || command.getTransactionAmountValue().doubleValue() <= 0) { if (command.getTransactionAmount() == null || command.getTransactionAmount().doubleValue() <= 0) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.must.be.greater.than.zero", "The parameter transactionAmount less than zero.", "transactionAmount", command.getTransactionAmountValue()); ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.repayment.must.be.greater.than.zero", "The parameter transactionAmount less than zero.", "transactionAmount", command.getTransactionAmount());
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
@@ -64,23 +64,23 @@ public class LoanAssembler {
} }
MonetaryCurrency currency = loanProduct.getCurrency(); MonetaryCurrency currency = loanProduct.getCurrency();
final BigDecimal defaultNominalInterestRatePerPeriod = command.getInterestRatePerPeriodValue(); final BigDecimal defaultNominalInterestRatePerPeriod = command.getInterestRatePerPeriod();
final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyType()); final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyType());
BigDecimal defaultAnnualNominalInterestRate = aprCalculator.calculateFrom(interestPeriodFrequencyType, command.getInterestRatePerPeriodValue()); BigDecimal defaultAnnualNominalInterestRate = aprCalculator.calculateFrom(interestPeriodFrequencyType, command.getInterestRatePerPeriod());
final InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestType()); final InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestType());
final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodType()); final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodType());
final Integer repayEvery = command.getRepaymentEveryValue(); final Integer repayEvery = command.getRepaymentEvery();
final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequencyType()); final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequencyType());
final Integer defaultNumberOfInstallments = command.getNumberOfRepaymentsValue(); final Integer defaultNumberOfInstallments = command.getNumberOfRepayments();
final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationType()); final AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationType());
LoanProductRelatedDetail loanRepaymentScheduleDetail = new LoanProductRelatedDetail(currency, LoanProductRelatedDetail loanRepaymentScheduleDetail = new LoanProductRelatedDetail(currency,
command.getPrincipalValue(), defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate, command.getPrincipal(), defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate,
interestMethod, interestCalculationPeriodMethod, interestMethod, interestCalculationPeriodMethod,
repayEvery, repaymentFrequencyType, defaultNumberOfInstallments, amortizationMethod, command.getInArrearsToleranceValue()); repayEvery, repaymentFrequencyType, defaultNumberOfInstallments, amortizationMethod, command.getInArrearsTolerance());
LoanSchedule loanSchedule = command.getLoanSchedule(); LoanSchedule loanSchedule = command.getLoanSchedule();
List<ScheduledLoanInstallment> loanRepaymentSchedule = loanSchedule.getScheduledLoanInstallments(); List<ScheduledLoanInstallment> loanRepaymentSchedule = loanSchedule.getScheduledLoanInstallments();
@@ -98,13 +98,14 @@ public class LoanAssembler {
LoanRepaymentScheduleInstallment installment = new LoanRepaymentScheduleInstallment( LoanRepaymentScheduleInstallment installment = new LoanRepaymentScheduleInstallment(
loan, scheduledLoanInstallment.getInstallmentNumber(), loan, scheduledLoanInstallment.getInstallmentNumber(),
// scheduledLoanInstallment.getPeriodStart(),
scheduledLoanInstallment.getPeriodEnd(), readPrincipalDue.getAmount(), scheduledLoanInstallment.getPeriodEnd(), readPrincipalDue.getAmount(),
readInterestDue.getAmount()); readInterestDue.getAmount());
loan.addRepaymentScheduleInstallment(installment); loan.addRepaymentScheduleInstallment(installment);
} }
loan.submitApplication(command.getSubmittedOnLocalDate(), command.getExpectedDisbursementLocalDate(), command.getRepaymentsStartingFromLocalDate(), command.getInterestChargedFromLocalDate(), defaultLoanLifecycleStateMachine()); loan.submitApplication(command.getSubmittedOnDate(), command.getExpectedDisbursementDate(),
command.getRepaymentsStartingFromDate(), command.getInterestChargedFromDate(),
defaultLoanLifecycleStateMachine());
return loan; return loan;
} }
@@ -22,7 +22,7 @@ public class LoanStateTransitionCommandValidator {
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transition"); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transition");
baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().greaterThanZero(); baseDataValidator.reset().parameter("loanId").value(command.getLoanId()).notNull().greaterThanZero();
baseDataValidator.reset().parameter("eventDate").value(command.getEventLocalDate()).notNull(); baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull();
baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000); baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000);
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
@@ -23,8 +23,8 @@ public class LoanTransactionCommandValidator {
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role"); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
baseDataValidator.reset().parameter("loanid").value(command.getLoanId()).notNull().greaterThanZero(); baseDataValidator.reset().parameter("loanid").value(command.getLoanId()).notNull().greaterThanZero();
baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionLocalDate()).notNull(); baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionDate()).notNull();
baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmountValue()).notNull().positiveAmount(); baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmount()).notNull().positiveAmount();
baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000); baseDataValidator.reset().parameter("note").value(command.getNote()).notExceedingLengthOf(1000);
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
@@ -82,7 +82,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
SubmitLoanApplicationCommandValidator validator = new SubmitLoanApplicationCommandValidator(command); SubmitLoanApplicationCommandValidator validator = new SubmitLoanApplicationCommandValidator(command);
validator.validate(); validator.validate();
LocalDate submittedOn = command.getSubmittedOnLocalDate(); LocalDate submittedOn = command.getSubmittedOnDate();
if (this.isBeforeToday(submittedOn) && currentUser.hasNotPermissionForAnyOf("CAN_SUBMIT_HISTORIC_LOAN_APPLICATION_ROLE", "PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE")) { if (this.isBeforeToday(submittedOn) && currentUser.hasNotPermissionForAnyOf("CAN_SUBMIT_HISTORIC_LOAN_APPLICATION_ROLE", "PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE")) {
throw new NoAuthorizationException("Cannot add backdated loan."); throw new NoAuthorizationException("Cannot add backdated loan.");
} }
@@ -136,7 +136,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); throw new LoanNotFoundException(command.getLoanId());
} }
LocalDate eventDate = command.getEventLocalDate(); LocalDate eventDate = command.getEventDate();
if (this.isBeforeToday(eventDate) && currentUser.canNotApproveLoanInPast()) { if (this.isBeforeToday(eventDate) && currentUser.canNotApproveLoanInPast()) {
throw new NoAuthorizationException("User has no authority to approve loan with a date in the past."); throw new NoAuthorizationException("User has no authority to approve loan with a date in the past.");
} }
@@ -190,7 +190,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); throw new LoanNotFoundException(command.getLoanId());
} }
LocalDate eventDate = command.getEventLocalDate(); LocalDate eventDate = command.getEventDate();
if (this.isBeforeToday(eventDate) && currentUser.canNotRejectLoanInPast()) { if (this.isBeforeToday(eventDate) && currentUser.canNotRejectLoanInPast()) {
throw new NoAuthorizationException("User has no authority to reject loan with a date in the past."); throw new NoAuthorizationException("User has no authority to reject loan with a date in the past.");
} }
@@ -221,7 +221,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); throw new LoanNotFoundException(command.getLoanId());
} }
LocalDate eventDate = command.getEventLocalDate(); LocalDate eventDate = command.getEventDate();
if (this.isBeforeToday(eventDate) && currentUser.canNotWithdrawByClientLoanInPast()) { if (this.isBeforeToday(eventDate) && currentUser.canNotWithdrawByClientLoanInPast()) {
throw new NoAuthorizationException("User has no authority to mark loan as withdrawn by client with a date in the past."); throw new NoAuthorizationException("User has no authority to mark loan as withdrawn by client with a date in the past.");
} }
@@ -253,7 +253,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
} }
String noteText = command.getNote(); String noteText = command.getNote();
LocalDate actualDisbursementDate = command.getEventLocalDate(); LocalDate actualDisbursementDate = command.getEventDate();
if (this.isBeforeToday(actualDisbursementDate) && currentUser.canNotDisburseLoanInPast()) { if (this.isBeforeToday(actualDisbursementDate) && currentUser.canNotDisburseLoanInPast()) {
throw new NoAuthorizationException("User has no authority to disburse loan with a date in the past."); throw new NoAuthorizationException("User has no authority to disburse loan with a date in the past.");
} }
@@ -264,9 +264,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
LocalDate interestCalculatedFromDate = loan.getInterestChargedFromDate(); LocalDate interestCalculatedFromDate = loan.getInterestChargedFromDate();
Number principalAsDecimal = loan.getLoanRepaymentScheduleDetail().getPrincipal().getAmount(); Number principalAsDecimal = loan.getLoanRepaymentScheduleDetail().getPrincipal().getAmount();
// String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode();
// int currencyDigits = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyDigitsAfterDecimal();
Number interestRatePerYear = loan.getLoanRepaymentScheduleDetail().getAnnualNominalInterestRate(); Number interestRatePerYear = loan.getLoanRepaymentScheduleDetail().getAnnualNominalInterestRate();
Integer numberOfInstallments = loan.getLoanRepaymentScheduleDetail().getNumberOfRepayments(); Integer numberOfInstallments = loan.getLoanRepaymentScheduleDetail().getNumberOfRepayments();
@@ -369,14 +366,14 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
throw new LoanNotFoundException(command.getLoanId()); throw new LoanNotFoundException(command.getLoanId());
} }
LocalDate transactionDate = command.getTransactionLocalDate(); LocalDate transactionDate = command.getTransactionDate();
if (this.isBeforeToday(transactionDate) && currentUser.canNotMakeRepaymentOnLoanInPast()) { if (this.isBeforeToday(transactionDate) && currentUser.canNotMakeRepaymentOnLoanInPast()) {
throw new NoAuthorizationException("error.msg.no.permission.to.make.repayment.on.loan.in.past"); throw new NoAuthorizationException("error.msg.no.permission.to.make.repayment.on.loan.in.past");
} }
Money repayment = Money.of(loan.getLoanRepaymentScheduleDetail() Money repayment = Money.of(loan.getLoanRepaymentScheduleDetail()
.getPrincipal().getCurrency(), .getPrincipal().getCurrency(),
command.getTransactionAmountValue()); command.getTransactionAmount());
LoanTransaction loanRepayment = LoanTransaction.repayment(repayment, transactionDate); LoanTransaction loanRepayment = LoanTransaction.repayment(repayment, transactionDate);
loan.makeRepayment(loanRepayment, defaultLoanLifecycleStateMachine()); loan.makeRepayment(loanRepayment, defaultLoanLifecycleStateMachine());
@@ -413,10 +410,10 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
Money transactionAmount = Money.of(loan Money transactionAmount = Money.of(loan
.getLoanRepaymentScheduleDetail().getPrincipal() .getLoanRepaymentScheduleDetail().getPrincipal()
.getCurrency(), command.getTransactionAmountValue()); .getCurrency(), command.getTransactionAmount());
// adjustment is only supported for repayments and waivers at present // adjustment is only supported for repayments and waivers at present
LocalDate transactionDate = command.getTransactionLocalDate(); LocalDate transactionDate = command.getTransactionDate();
LoanTransaction newTransactionDetail = LoanTransaction.repayment(transactionAmount, transactionDate); LoanTransaction newTransactionDetail = LoanTransaction.repayment(transactionAmount, transactionDate);
if (transactionToAdjust.isWaiver()) { if (transactionToAdjust.isWaiver()) {
newTransactionDetail = LoanTransaction.waiver(transactionAmount, transactionDate); newTransactionDetail = LoanTransaction.waiver(transactionAmount, transactionDate);
@@ -453,9 +450,9 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
Money waived = Money.of(loan.getLoanRepaymentScheduleDetail() Money waived = Money.of(loan.getLoanRepaymentScheduleDetail()
.getPrincipal().getCurrency(), .getPrincipal().getCurrency(),
command.getTransactionAmountValue()); command.getTransactionAmount());
LoanTransaction waiver = LoanTransaction.waiver(waived, command.getTransactionLocalDate()); LoanTransaction waiver = LoanTransaction.waiver(waived, command.getTransactionDate());
loan.waive(waiver, defaultLoanLifecycleStateMachine()); loan.waive(waiver, defaultLoanLifecycleStateMachine());
@@ -25,12 +25,12 @@ public class SubmitLoanApplicationCommandValidator {
dataValidationErrors.add(error); dataValidationErrors.add(error);
} }
if (command.getSubmittedOnLocalDate() == null) { if (command.getSubmittedOnDate() == null) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.submitted.on.date.cannot.be.blank", ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.submitted.on.date.cannot.be.blank",
"The parameter submittedOnDate cannot be empty.", "submittedOnDate"); "The parameter submittedOnDate cannot be empty.", "submittedOnDate");
dataValidationErrors.add(error); dataValidationErrors.add(error);
} else { } else {
if (command.getSubmittedOnLocalDate().isAfter(command.getExpectedDisbursementLocalDate())) { if (command.getSubmittedOnDate().isAfter(command.getExpectedDisbursementDate())) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.submitted.on.date.cannot.be.after.expectedDisbursementDate", ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.submitted.on.date.cannot.be.after.expectedDisbursementDate",
"The date of parameter submittedOnDate cannot fall after the date given for expectedDisbursementDate.", "submittedOnDate", "The date of parameter submittedOnDate cannot fall after the date given for expectedDisbursementDate.", "submittedOnDate",
command.getSubmittedOnDate(), command.getExpectedDisbursementDate()); command.getSubmittedOnDate(), command.getExpectedDisbursementDate());
@@ -40,21 +40,8 @@ public class SubmitLoanApplicationCommandValidator {
try { try {
// reuse calculate loan schedule validator for now // reuse calculate loan schedule validator for now
CalculateLoanScheduleCommand calculateLoanScheduleCommand = new CalculateLoanScheduleCommand( CalculateLoanScheduleCommand calculateLoanScheduleCommand = this.command.toCalculateLoanScheduleCommand();
command.getProductId(), CalculateLoanScheduleCommandValidator validator = new CalculateLoanScheduleCommandValidator(calculateLoanScheduleCommand);
command.getPrincipalValue(), command.getInterestRatePerPeriodValue(),
command.getInterestRateFrequencyType(),
command.getInterestType(), command.getInterestCalculationPeriodType(),
command.getRepaymentEveryValue(),
command.getRepaymentFrequencyType(),
command.getNumberOfRepaymentsValue(),
command.getAmortizationType(),
command.getExpectedDisbursementLocalDate(),
command.getRepaymentsStartingFromLocalDate(),
command.getInterestChargedFromLocalDate());
CalculateLoanScheduleCommandValidator validator = new CalculateLoanScheduleCommandValidator(
calculateLoanScheduleCommand);
validator.validate(); validator.validate();
} catch (PlatformApiDataValidationException e) { } catch (PlatformApiDataValidationException e) {
dataValidationErrors.addAll(e.getErrors()); dataValidationErrors.addAll(e.getErrors());
@@ -37,9 +37,9 @@ public class BranchMoneyTransferCommandValidator {
baseDataValidator.reset().parameter("fromOfficeId").value(command.getFromOfficeId()).notSameAsParameter("toOfficeId", command.getToOfficeId()); baseDataValidator.reset().parameter("fromOfficeId").value(command.getFromOfficeId()).notSameAsParameter("toOfficeId", command.getToOfficeId());
} }
baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionLocalDate()).notNull(); baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionDate()).notNull();
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmountValue()).notNull(); baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmount()).notNull();
baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(100); baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(100);
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
@@ -129,9 +129,9 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
} }
MonetaryCurrency currency = new MonetaryCurrency(appCurrency.getCode(), appCurrency.getDecimalPlaces()); MonetaryCurrency currency = new MonetaryCurrency(appCurrency.getCode(), appCurrency.getDecimalPlaces());
Money amount = Money.of(currency, command.getTransactionAmountValue()); Money amount = Money.of(currency, command.getTransactionAmount());
OfficeTransaction entity = OfficeTransaction.create(fromOffice, toOffice, command.getTransactionLocalDate(), amount); OfficeTransaction entity = OfficeTransaction.create(fromOffice, toOffice, command.getTransactionDate(), amount);
this.officeMonetaryTransferRepository.save(entity); this.officeMonetaryTransferRepository.save(entity);
@@ -14,6 +14,7 @@ import javax.persistence.JoinTable;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.Table; import javax.persistence.Table;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.data.PermissionData; import org.mifosng.platform.api.data.PermissionData;
import org.mifosng.platform.api.data.RoleData; import org.mifosng.platform.api.data.RoleData;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom; import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
@@ -73,17 +74,16 @@ public class Role extends AbstractAuditableCustom<AppUser, Long> {
return data; return data;
} }
/** public void update(final RoleCommand command, List<Permission> selectedPermissions) {
* When updating details, any parameters with null values are ignored. if (command.isNameChanged()) {
*/ this.name = command.getName();
public void update(String name, String description, List<Permission> selectedPermissions) {
if (name != null) {
this.name = name;
} }
if (description != null) {
this.description = description; if (command.isDescriptionChanged()) {
this.description = command.getDescription();
} }
if (!selectedPermissions.isEmpty()) {
if (command.isPermissionsChanged()) {
this.permissions.clear(); this.permissions.clear();
this.permissions = new HashSet<Permission>(selectedPermissions); this.permissions = new HashSet<Permission>(selectedPermissions);
} }
@@ -64,7 +64,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
if (role == null) { if (role == null) {
throw new RoleNotFoundException(command.getId()); throw new RoleNotFoundException(command.getId());
} }
role.update(command.getName(), command.getDescription(), selectedPermissions); role.update(command, selectedPermissions);
this.roleRepository.save(role); this.roleRepository.save(role);