modify offices, permissions and roles to support more flexible updates.

This commit is contained in:
Keith Woodlock
2012-07-17 22:48:20 +01:00
parent ae7d78a16e
commit d492d41800
16 changed files with 312 additions and 334 deletions
@@ -1,8 +1,6 @@
package org.mifosng.platform.api; package org.mifosng.platform.api;
import java.lang.reflect.Type;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@@ -19,6 +17,7 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.FundCommand; import org.mifosng.platform.api.commands.FundCommand;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.FundData; import org.mifosng.platform.api.data.FundData;
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.fund.service.FundReadPlatformService; import org.mifosng.platform.fund.service.FundReadPlatformService;
import org.mifosng.platform.fund.service.FundWritePlatformService; import org.mifosng.platform.fund.service.FundWritePlatformService;
@@ -26,9 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@Path("/funds") @Path("/funds")
@Component @Component
@Scope("singleton") @Scope("singleton")
@@ -43,12 +39,15 @@ public class FundsApiResource {
@Autowired @Autowired
private FundWritePlatformService writePlatformService; private FundWritePlatformService writePlatformService;
@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 retrieveFunds(@Context UriInfo uriInfo) { public String retrieveFunds(@Context UriInfo uriInfo) {
Collection<FundData> funds = this.readPlatformService.retrieveAllFunds(); Collection<FundData> funds = this.readPlatformService.retrieveAllFunds();
@@ -62,21 +61,7 @@ public class FundsApiResource {
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response createFund(final String jsonRequestBody) { public Response createFund(final String jsonRequestBody) {
Gson gson = new Gson(); FundCommand command = this.apiDataConversionService.convertJsonToFundCommand(null, jsonRequestBody);
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gson.fromJson(jsonRequestBody, typeOfMap);
String name = null;
if (requestMap.containsKey("name")) {
name = requestMap.get("name");
}
String externalId = null;
if (requestMap.containsKey("externalId")) {
externalId = requestMap.get("externalId");
}
FundCommand command = new FundCommand(name, externalId);
Long fundId = this.writePlatformService.createFund(command); Long fundId = this.writePlatformService.createFund(command);
@@ -85,8 +70,8 @@ public class FundsApiResource {
@GET @GET
@Path("{fundId}") @Path("{fundId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retreiveOffice(@PathParam("fundId") final Long fundId, @Context UriInfo uriInfo) { public String retreiveOffice(@PathParam("fundId") final Long fundId, @Context UriInfo uriInfo) {
FundData fund = this.readPlatformService.retrieveFund(fundId); FundData fund = this.readPlatformService.retrieveFund(fundId);
@@ -102,22 +87,7 @@ public class FundsApiResource {
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response updateFund(@PathParam("fundId") final Long fundId, final String jsonRequestBody) { public Response updateFund(@PathParam("fundId") final Long fundId, final String jsonRequestBody) {
Gson gson = new Gson(); FundCommand command = this.apiDataConversionService.convertJsonToFundCommand(fundId, jsonRequestBody);
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gson.fromJson(jsonRequestBody, typeOfMap);
String name = null;
if (requestMap.containsKey("name")) {
name = requestMap.get("name");
}
String externalId = null;
if (requestMap.containsKey("externalId")) {
externalId = requestMap.get("externalId");
}
FundCommand command = new FundCommand(name, externalId);
command.setId(fundId);
Long entityId = this.writePlatformService.updateFund(command); Long entityId = this.writePlatformService.updateFund(command);
@@ -28,7 +28,7 @@ import org.springframework.stereotype.Component;
@Path("/loanproducts") @Path("/loanproducts")
@Component @Component
@Scope("singleton") @Scope("singleton")
public class LoanProductApiResource { public class LoanProductsApiResource {
private String defaultFieldList = "principal,inArrearsTolerance,interestRatePerPeriod,annualInterestRate,repaymentFrequencyType,interestRateFrequencyType,amortizationType,interestType,interestCalculationPeriodType,fundId"; private String defaultFieldList = "principal,inArrearsTolerance,interestRatePerPeriod,annualInterestRate,repaymentFrequencyType,interestRateFrequencyType,amortizationType,interestType,interestCalculationPeriodType,fundId";
private String allowedFieldList = "currencyOptions,amortizationTypeOptions,interestTypeOptions,interestCalculationPeriodTypeOptions,repaymentFrequencyTypeOptions,interestRateFrequencyTypeOptions,fundOptions"; private String allowedFieldList = "currencyOptions,amortizationTypeOptions,interestTypeOptions,interestCalculationPeriodTypeOptions,repaymentFrequencyTypeOptions,interestRateFrequencyTypeOptions,fundOptions";
@@ -51,7 +51,7 @@ public class LoanProductApiResource {
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response createLoanProduct(final String jsonRequestBody) { public Response createLoanProduct(final String jsonRequestBody) {
final LoanProductCommand command = this.apiDataConversionService.convertJsonToCommand(null, jsonRequestBody); final LoanProductCommand command = this.apiDataConversionService.convertJsonToLoanProductCommand(null, jsonRequestBody);
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.createLoanProduct(command); EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.createLoanProduct(command);
@@ -93,7 +93,7 @@ public class LoanProductApiResource {
@Path("{productId}") @Path("{productId}")
@Consumes({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public String retrieveLoanProductDetails(@PathParam("productId") final Long productId, final UriInfo uriInfo) { public String retrieveLoanProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo) {
LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId); LoanProductData loanProduct = this.loanProductReadPlatformService.retrieveLoanProduct(productId);
@@ -109,7 +109,7 @@ public class LoanProductApiResource {
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response updateLoanProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) { public Response updateLoanProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) {
LoanProductCommand command = this.apiDataConversionService.convertJsonToCommand(productId, jsonRequestBody); LoanProductCommand command = this.apiDataConversionService.convertJsonToLoanProductCommand(productId, jsonRequestBody);
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.updateLoanProduct(command); EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.updateLoanProduct(command);
@@ -1,8 +1,6 @@
package org.mifosng.platform.api; package org.mifosng.platform.api;
import java.lang.reflect.Type;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@@ -17,7 +15,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.OfficeCommand; import org.mifosng.platform.api.commands.OfficeCommand;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeData;
@@ -29,13 +26,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@Path("/offices") @Path("/offices")
@Component @Component
@Scope("singleton") @Scope("singleton")
public class OfficeApiResource { public class OfficesApiResource {
private String defaultFieldList = "openingDate"; private String defaultFieldList = "openingDate";
private String allowedFieldList = "allowedParents"; private String allowedFieldList = "allowedParents";
@@ -54,12 +48,11 @@ public class OfficeApiResource {
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 retrieveOffices(@Context UriInfo uriInfo) { public String retrieveOffices(@Context UriInfo uriInfo) {
Collection<OfficeData> offices = this.readPlatformService Collection<OfficeData> offices = this.readPlatformService.retrieveAllOffices();
.retrieveAllOffices();
String selectedFields = ""; String selectedFields = "";
return this.jsonFormattingService.convertRequest(offices, filterName, return this.jsonFormattingService.convertRequest(offices, filterName,
allowedFieldList, selectedFields, uriInfo.getQueryParameters()); allowedFieldList, selectedFields, uriInfo.getQueryParameters());
@@ -67,8 +60,8 @@ public class OfficeApiResource {
@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 retrieveOfficeTemplate(@Context UriInfo uriInfo) { public String retrieveOfficeTemplate(@Context UriInfo uriInfo) {
OfficeData officeData = this.readPlatformService OfficeData officeData = this.readPlatformService
@@ -85,38 +78,7 @@ public class OfficeApiResource {
@Produces({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON})
public Response createOffice(final String jsonRequestBody) { public Response createOffice(final String jsonRequestBody) {
Gson gson = new Gson(); OfficeCommand command = this.apiDataConversionService.convertJsonToOfficeCommand(null, jsonRequestBody);
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gson.fromJson(jsonRequestBody, typeOfMap);
String name = null;
if (requestMap.containsKey("name")) {
name = requestMap.get("name");
}
String externalId = null;
if (requestMap.containsKey("externalId")) {
externalId = requestMap.get("externalId");
}
Long parentId = null;
if (requestMap.containsKey("parentId")) {
parentId = Long.valueOf(requestMap.get("parentId"));
}
String openingDate = null;
if (requestMap.containsKey("openingDate")) {
openingDate = requestMap.get("openingDate");
}
String dateFormat = null;
if (requestMap.containsKey("dateFormat")) {
dateFormat = requestMap.get("dateFormat");
}
LocalDate openingLocalDate = apiDataConversionService.convertFrom(openingDate, "openingDate", dateFormat);
OfficeCommand command = new OfficeCommand(name, externalId, parentId, openingLocalDate);
Long officeId = this.writePlatformService.createOffice(command); Long officeId = this.writePlatformService.createOffice(command);
@@ -125,8 +87,8 @@ public class OfficeApiResource {
@GET @GET
@Path("{officeId}") @Path("{officeId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retreiveOffice(@PathParam("officeId") final Long officeId, public String retreiveOffice(@PathParam("officeId") final Long officeId,
@QueryParam("template") String template, @Context UriInfo uriInfo) { @QueryParam("template") String template, @Context UriInfo uriInfo) {
@@ -143,42 +105,11 @@ public class OfficeApiResource {
@PUT @PUT
@Path("{officeId}") @Path("{officeId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response updateOffice(@PathParam("officeId") final Long officeId, final String jsonRequestBody) { public Response updateOffice(@PathParam("officeId") final Long officeId, final String jsonRequestBody) {
Gson gson = new Gson(); OfficeCommand command = this.apiDataConversionService.convertJsonToOfficeCommand(officeId, jsonRequestBody);
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gson.fromJson(jsonRequestBody, typeOfMap);
String name = null;
if (requestMap.containsKey("name")) {
name = requestMap.get("name");
}
String externalId = null;
if (requestMap.containsKey("externalId")) {
externalId = requestMap.get("externalId");
}
Long parentId = null;
if (requestMap.containsKey("parentId")) {
parentId = Long.valueOf(requestMap.get("parentId"));
}
String openingDate = null;
if (requestMap.containsKey("openingDate")) {
openingDate = requestMap.get("openingDate");
}
String dateFormat = null;
if (requestMap.containsKey("dateFormat")) {
dateFormat = requestMap.get("dateFormat");
}
LocalDate openingLocalDate = apiDataConversionService.convertFrom(openingDate, "openingDate", dateFormat);
OfficeCommand command = new OfficeCommand(officeId, name, externalId, parentId, openingLocalDate);
Long entityId = this.writePlatformService.updateOffice(command); Long entityId = this.writePlatformService.updateOffice(command);
@@ -20,7 +20,7 @@ import org.springframework.stereotype.Component;
@Path("/permissions") @Path("/permissions")
@Component @Component
@Scope("singleton") @Scope("singleton")
public class PermissionApiResource { public class PermissionsApiResource {
private String allowedFieldList = ""; private String allowedFieldList = "";
private String filterName = "permissionFilter"; private String filterName = "permissionFilter";
@@ -31,12 +31,11 @@ public class PermissionApiResource {
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 retrieveAllPermissions(@Context UriInfo uriInfo) { public String retrieveAllPermissions(@Context final UriInfo uriInfo) {
Collection<PermissionData> permissions = this.permissionReadPlatformService Collection<PermissionData> permissions = this.permissionReadPlatformService.retrieveAllPermissions();
.retrieveAllPermissions();
String selectedFields = ""; String selectedFields = "";
return this.jsonFormattingService.convertRequest(permissions, return this.jsonFormattingService.convertRequest(permissions,
@@ -19,6 +19,7 @@ import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
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.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.user.service.PermissionReadPlatformService; import org.mifosng.platform.user.service.PermissionReadPlatformService;
import org.mifosng.platform.user.service.RoleReadPlatformService; import org.mifosng.platform.user.service.RoleReadPlatformService;
@@ -30,7 +31,7 @@ import org.springframework.stereotype.Component;
@Path("/roles") @Path("/roles")
@Component @Component
@Scope("singleton") @Scope("singleton")
public class RoleApiResource { public class RolesApiResource {
private String allowedFieldList = "availablePermissions"; private String allowedFieldList = "availablePermissions";
private String filterName = "roleFilter"; private String filterName = "roleFilter";
@@ -47,13 +48,15 @@ public class RoleApiResource {
@Autowired @Autowired
private ApiJSONFormattingService jsonFormattingService; private ApiJSONFormattingService jsonFormattingService;
@GET @Autowired
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) private ApiDataConversionService apiDataConversionService;
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAllRoles(@Context UriInfo uriInfo) {
Collection<RoleData> roles = this.roleReadPlatformService @GET
.retrieveAllRoles(); @Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String retrieveAllRoles(@Context final UriInfo uriInfo) {
Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
String selectedFields = "id,name,description"; String selectedFields = "id,name,description";
return this.jsonFormattingService.convertRequest(roles, filterName, return this.jsonFormattingService.convertRequest(roles, filterName,
@@ -62,12 +65,11 @@ public class RoleApiResource {
@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 retrieveNewRoleDetails(@Context UriInfo uriInfo) { public String retrieveNewRoleDetails(@Context final UriInfo uriInfo) {
Collection<PermissionData> allPermissions = this.permissionReadPlatformService Collection<PermissionData> allPermissions = this.permissionReadPlatformService.retrieveAllPermissions();
.retrieveAllPermissions();
RoleData role = new RoleData(); RoleData role = new RoleData();
role.setAvailablePermissions(allPermissions); role.setAvailablePermissions(allPermissions);
@@ -78,20 +80,23 @@ public class RoleApiResource {
} }
@POST @POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response createRole(final RoleCommand command) { public Response createRole(final String jsonRequestBody) {
RoleCommand command = this.apiDataConversionService.convertJsonToRoleCommand(null, jsonRequestBody);
Long roleId = this.roleWritePlatformService.createRole(command); Long roleId = this.roleWritePlatformService.createRole(command);
return Response.ok().entity(new EntityIdentifier(roleId)).build(); return Response.ok().entity(new EntityIdentifier(roleId)).build();
} }
@GET @GET
@Path("{roleId}") @Path("{roleId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public String retrieveRole(@PathParam("roleId") final Long roleId, public String retrieveRole(@PathParam("roleId") final Long roleId,
@QueryParam("template") String template, @Context UriInfo uriInfo) { @QueryParam("template") final String template, @Context final UriInfo uriInfo) {
RoleData role = this.roleReadPlatformService.retrieveRole(roleId); RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
@@ -109,13 +114,14 @@ public class RoleApiResource {
@PUT @PUT
@Path("{roleId}") @Path("{roleId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON }) @Produces({MediaType.APPLICATION_JSON})
public Response updateRole(@PathParam("roleId") final Long roleId, public Response updateRole(@PathParam("roleId") final Long roleId, final String jsonRequestBody) {
final RoleCommand command) {
RoleCommand command = this.apiDataConversionService.convertJsonToRoleCommand(roleId, jsonRequestBody);
command.setId(roleId);
this.roleWritePlatformService.updateRole(command); this.roleWritePlatformService.updateRole(command);
return Response.ok().entity(new EntityIdentifier(roleId)).build(); return Response.ok().entity(new EntityIdentifier(roleId)).build();
} }
} }
@@ -1,22 +1,21 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import java.util.Set;
/** /**
* Command used for create and update fund operations. * Immutable command for creating or updating details of a fund.
*/ */
@XmlRootElement
public class FundCommand { public class FundCommand {
private Long id; private final Long id;
private String name; private final String name;
private String externalId; private final String externalId;
protected FundCommand() { private final Set<String> modifiedParameters;
//
}
public FundCommand(final String fundName, final String externalId) { public FundCommand(final Set<String> modifiedParameters, final Long id, final String fundName, final String externalId) {
this.modifiedParameters = modifiedParameters;
this.id = id;
this.name = fundName; this.name = fundName;
this.externalId = externalId; this.externalId = externalId;
} }
@@ -25,23 +24,19 @@ public class FundCommand {
return id; return id;
} }
public void setId(Long id) {
this.id = id;
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) {
this.name = name;
}
public String getExternalId() { public String getExternalId() {
return externalId; return externalId;
} }
public void setExternalId(String externalId) { public boolean isNameChanged() {
this.externalId = externalId; return this.modifiedParameters.contains("name");
}
public boolean isExternalIdChanged() {
return this.modifiedParameters.contains("externalId");
} }
} }
@@ -11,7 +11,6 @@ public class LoanProductCommand {
private final Long id; private final Long id;
private final String name; private final String name;
private final String description; private final String description;
private final String externalId;
private final Long fundId; private final Long fundId;
@@ -33,7 +32,8 @@ public class LoanProductCommand {
private final Set<String> modifiedParameters; private final Set<String> modifiedParameters;
public LoanProductCommand(Set<String> modifiedParameters, final Long id, final String name, final String description, final String externalId, final Long fundId, public LoanProductCommand(final Set<String> modifiedParameters, final Long id, final String name, final String description,
final Long fundId,
final String currencyCode, final Integer digitsAfterDecimal, final String currencyCode, final Integer digitsAfterDecimal,
final BigDecimal principal, final BigDecimal inArrearsTolerance, final Integer numberOfRepayments, final BigDecimal principal, final BigDecimal inArrearsTolerance, final Integer numberOfRepayments,
final Integer repaymentEvery, final BigDecimal interestRatePerPeriod, final Integer repaymentEvery, final BigDecimal interestRatePerPeriod,
@@ -43,7 +43,6 @@ public class LoanProductCommand {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.externalId = externalId;
this.fundId = fundId; this.fundId = fundId;
this.currencyCode = currencyCode; this.currencyCode = currencyCode;
this.digitsAfterDecimal = digitsAfterDecimal; this.digitsAfterDecimal = digitsAfterDecimal;
@@ -71,10 +70,6 @@ public class LoanProductCommand {
return description; return description;
} }
public String getExternalId() {
return externalId;
}
public Long getFundId() { public Long getFundId() {
return fundId; return fundId;
} }
@@ -1,109 +1,66 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import java.util.Set;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
/** /**
* Command used for create and update office operations. * Immutable command for creating or updating details of a office.
*/ */
@XmlRootElement
public class OfficeCommand { public class OfficeCommand {
private Long id; private final Long id;
private String name; private final String name;
private String externalId; private final String externalId;
private final LocalDate openingDate;
private final Long parentId;
private String dateFormat; private final Set<String> modifiedParameters;
private String openingDate;
private LocalDate openingLocalDate;
private Long parentId; public OfficeCommand(Set<String> modifiedParameters, final Long id, final String officeName,
private Boolean rootOffice = false;
protected OfficeCommand() {
//
}
public OfficeCommand(final String officeName, final String externalId,
final Long parentId, final LocalDate openingDate) {
this.name = officeName;
this.externalId = externalId;
this.parentId = parentId;
this.openingLocalDate = openingDate;
}
public OfficeCommand(final Long id, final String officeName,
final String externalId, final Long parentId, final String externalId, final Long parentId,
final LocalDate openingDate) { final LocalDate openingDate) {
this.modifiedParameters = modifiedParameters;
this.id = id; this.id = id;
this.name = officeName; this.name = officeName;
this.externalId = externalId; this.externalId = externalId;
this.parentId = parentId; this.parentId = parentId;
this.openingLocalDate = openingDate;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getExternalId() {
return this.externalId;
}
public void setExternalId(final String externalId) {
this.externalId = externalId;
}
public Long getParentId() {
return this.parentId;
}
public void setParentId(final Long parentId) {
this.parentId = parentId;
}
public Long getId() {
return this.id;
}
public void setId(final Long id) {
this.id = id;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public boolean isRootOffice() {
return rootOffice;
}
public void setRootOffice(boolean rootOffice) {
this.rootOffice = rootOffice;
}
public String getOpeningDate() {
return openingDate;
}
public void setOpeningDate(String openingDate) {
this.openingDate = openingDate; this.openingDate = openingDate;
} }
public LocalDate getOpeningLocalDate() { public Long getId() {
return openingLocalDate; return id;
} }
public void setOpeningLocalDate(LocalDate openingLocalDate) { public String getName() {
this.openingLocalDate = openingLocalDate; return name;
}
public String getExternalId() {
return externalId;
}
public LocalDate getOpeningDate() {
return openingDate;
}
public Long getParentId() {
return parentId;
}
public boolean isNameChanged() {
return this.modifiedParameters.contains("name");
}
public boolean isExternalIdChanged() {
return this.modifiedParameters.contains("externalId");
}
public boolean isOpeningDateChanged() {
return this.modifiedParameters.contains("openingDate");
}
public boolean isParentChanged() {
return this.modifiedParameters.contains("parentId");
} }
} }
@@ -1,58 +1,44 @@
package org.mifosng.platform.api.commands; package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement; import java.util.Set;
/** /**
* For creating and updating roles. When updating the id is expected to be populated. * Immutable command for creating or updating details of a role.
*/ */
@XmlRootElement
public class RoleCommand { public class RoleCommand {
private Long id; private final Long id;
private String name; private final String name;
private String description; private final String description;
private final String[] permissions;
private String[] permissions; private final Set<String> modifiedParameters;
public RoleCommand() { public RoleCommand(Set<String> modifiedParameters, final Long id, final String name, final String description, final String[] permissionIds) {
// this.modifiedParameters = modifiedParameters;
} this.id = id;
public RoleCommand(final String name, final String description, final String[] permissionIds) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.permissions = permissionIds; this.permissions = permissionIds;
} }
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public void setDescription(final String description) {
this.description = description;
}
public Long getId() { public Long getId() {
return id; return id;
} }
public void setId(Long id) { public String getName() {
this.id = id; return name;
}
public String getDescription() {
return description;
} }
public String[] getPermissions() { public String[] getPermissions() {
return permissions; return permissions;
} }
public void setPermissions(String[] permissions) { public Set<String> getModifiedParameters() {
this.permissions = permissions; return modifiedParameters;
} }
} }
@@ -4,7 +4,10 @@ import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
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.OfficeCommand;
import org.mifosng.platform.api.commands.RoleCommand;
public interface ApiDataConversionService { public interface ApiDataConversionService {
@@ -20,5 +23,11 @@ public interface ApiDataConversionService {
Locale localeFrom(String languageCode, String courntryCode, String variantCode); Locale localeFrom(String languageCode, String courntryCode, String variantCode);
LoanProductCommand convertJsonToCommand(Long productId, String jsonRequestBody); LoanProductCommand convertJsonToLoanProductCommand(Long resourceIdentifier, String json);
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
OfficeCommand convertJsonToOfficeCommand(Long resourceIdentifier, String json);
RoleCommand convertJsonToRoleCommand(Long resourceIdentifier, String json);
} }
@@ -17,7 +17,10 @@ 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.FundCommand;
import org.mifosng.platform.api.commands.LoanProductCommand; import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.api.commands.OfficeCommand;
import org.mifosng.platform.api.commands.RoleCommand;
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;
@@ -27,6 +30,10 @@ import org.springframework.format.number.NumberFormatter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@Service @Service
@@ -39,8 +46,20 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
} }
@Override @Override
public LocalDate convertFrom(String dateAsString, String parameterName, public LocalDate convertFrom(final String dateAsString, final String parameterName, final String dateFormat) {
String dateFormat) {
if (StringUtils.isBlank(dateFormat)) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
String defaultMessage = new StringBuilder("The parameter '" + parameterName + "' requires a 'dateFormat' parameter to be passed with it.").toString();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.missing.dateFormat.parameter", defaultMessage, parameterName);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors);
}
LocalDate eventLocalDate = null; LocalDate eventLocalDate = null;
if (StringUtils.isNotBlank(dateAsString)) { if (StringUtils.isNotBlank(dateAsString)) {
try { try {
@@ -243,7 +262,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
} }
@Override @Override
public LoanProductCommand convertJsonToCommand(final Long resourceIdentifier, final String json) { public LoanProductCommand convertJsonToLoanProductCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) { if (StringUtils.isBlank(json)) {
throw new InvalidJsonException(); throw new InvalidJsonException();
@@ -254,7 +273,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Set<String> supportedParams = new HashSet<String>( Set<String> supportedParams = new HashSet<String>(
Arrays.asList("name", "description", "externalId", "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")
); );
@@ -265,7 +284,6 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
String name = extractStringParameter("name", requestMap, modifiedParameters); String name = extractStringParameter("name", requestMap, modifiedParameters);
String description = extractStringParameter("description", requestMap, modifiedParameters); String description = extractStringParameter("description", requestMap, modifiedParameters);
String externalId = extractStringParameter("externalId", requestMap, modifiedParameters);
Long fundId = extractLongParameter("fundId", requestMap, modifiedParameters); Long fundId = extractLongParameter("fundId", requestMap, modifiedParameters);
String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters); String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters);
Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters); Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters);
@@ -282,12 +300,103 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Integer interestTypeValue = extractIntegerParameter("interestType", requestMap, modifiedParameters); Integer interestTypeValue = extractIntegerParameter("interestType", requestMap, modifiedParameters);
Integer interestCalculationPeriodTypeValue = extractIntegerParameter("interestCalculationPeriodType", requestMap, modifiedParameters); Integer interestCalculationPeriodTypeValue = extractIntegerParameter("interestCalculationPeriodType", requestMap, modifiedParameters);
return new LoanProductCommand(modifiedParameters, resourceIdentifier, name, description, externalId, fundId, return new LoanProductCommand(modifiedParameters, resourceIdentifier, name, description, fundId,
currencyCode, digitsAfterDecimalValue, principalValue, inArrearsToleranceValue, numberOfRepaymentsValue, repaymentEveryValue, interestRatePerPeriodValue, currencyCode, digitsAfterDecimalValue, principalValue, inArrearsToleranceValue, numberOfRepaymentsValue, repaymentEveryValue, interestRatePerPeriodValue,
repaymentFrequencyTypeValue, interestRateFrequencyTypeValue, amortizationTypeValue, interestTypeValue, interestCalculationPeriodTypeValue); repaymentFrequencyTypeValue, interestRateFrequencyTypeValue, amortizationTypeValue, interestTypeValue, interestCalculationPeriodTypeValue);
} }
private void checkForUnsupportedParameters(Map<String, String> requestMap, Set<String> supportedParams) { @Override
public FundCommand convertJsonToFundCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("name", "externalId")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
String name = extractStringParameter("name", requestMap, modifiedParameters);
String externalId = extractStringParameter("externalId", requestMap, modifiedParameters);
return new FundCommand(modifiedParameters, resourceIdentifier, name, externalId);
}
@Override
public OfficeCommand convertJsonToOfficeCommand(final Long resourceIdentifier, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("name", "externalId", "parentId", "openingDate")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
String name = extractStringParameter("name", requestMap, modifiedParameters);
String externalId = extractStringParameter("externalId", requestMap, modifiedParameters);
Long parentId = extractLongParameter("parentId", requestMap, modifiedParameters);
LocalDate openingLocalDate = extractLocalDateParameter("openingDate", requestMap, modifiedParameters);
return new OfficeCommand(modifiedParameters, resourceIdentifier, name, externalId, parentId, openingLocalDate);
}
@Override
public RoleCommand convertJsonToRoleCommand(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("name", "description", "permissions")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
// check array
JsonParser parser = new JsonParser();
String[] permissionIds = null;
JsonElement element = parser.parse(json);
if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
if (object.has("permissions")) {
modifiedParameters.add("permissions");
JsonArray array = object.get("permissions").getAsJsonArray();
permissionIds = new String[array.size()];
for (int i=0; i<array.size(); i++) {
permissionIds[i] = array.get(i).getAsString();
}
}
}
//
String name = extractStringParameter("name", requestMap, modifiedParameters);
String description = extractStringParameter("description", requestMap, modifiedParameters);
return new RoleCommand(modifiedParameters, resourceIdentifier, name, description, permissionIds);
}
private void checkForUnsupportedParameters(Map<String, ?> requestMap, Set<String> supportedParams) {
List<String> unsupportedParameterList = new ArrayList<String>(); List<String> unsupportedParameterList = new ArrayList<String>();
for (String providedParameter : requestMap.keySet()) { for (String providedParameter : requestMap.keySet()) {
if (!supportedParams.contains(providedParameter)) { if (!supportedParams.contains(providedParameter)) {
@@ -300,37 +409,39 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
} }
} }
private String extractStringParameter(final String paramName, final Map<String, String> requestMap, final Set<String> modifiedParameters) { private String extractStringParameter(final String paramName, final Map<String, ?> requestMap, final Set<String> modifiedParameters) {
String paramValue = null; String paramValue = null;
if (requestMap.containsKey(paramName)) { if (requestMap.containsKey(paramName)) {
paramValue = requestMap.get(paramName); paramValue = (String) requestMap.get(paramName);
modifiedParameters.add(paramName); modifiedParameters.add(paramName);
} }
return paramValue; return paramValue;
} }
private Integer extractIntegerParameter(final String paramName, final Map<String, String> requestMap, final Set<String> modifiedParameters) { private Integer extractIntegerParameter(final String paramName, final Map<String, ?> requestMap, final Set<String> modifiedParameters) {
Integer paramValue = null; Integer paramValue = null;
if (requestMap.containsKey(paramName)) { if (requestMap.containsKey(paramName)) {
paramValue = convertToInteger(requestMap.get(paramName), paramName, extractLocaleValue(requestMap)); String valueAsString = (String) requestMap.get(paramName);
paramValue = convertToInteger(valueAsString, paramName, extractLocaleValue(requestMap));
modifiedParameters.add(paramName); modifiedParameters.add(paramName);
} }
return paramValue; return paramValue;
} }
private BigDecimal extractBigDecimalParameter(final String paramName, final Map<String, String> requestMap, final Set<String> modifiedParameters) { private BigDecimal extractBigDecimalParameter(final String paramName, final Map<String, ?> requestMap, final Set<String> modifiedParameters) {
BigDecimal paramValue = null; BigDecimal paramValue = null;
if (requestMap.containsKey(paramName)) { if (requestMap.containsKey(paramName)) {
paramValue = convertFrom(requestMap.get(paramName), paramName, extractLocaleValue(requestMap)); String valueAsString = (String) requestMap.get(paramName);
paramValue = convertFrom(valueAsString, paramName, extractLocaleValue(requestMap));
modifiedParameters.add(paramName); modifiedParameters.add(paramName);
} }
return paramValue; return paramValue;
} }
private Long extractLongParameter(final String paramName, final Map<String, String> requestMap, final Set<String> modifiedParameters) { private Long extractLongParameter(final String paramName, final Map<String, ?> requestMap, final Set<String> modifiedParameters) {
Long paramValue = null; Long paramValue = null;
if (requestMap.containsKey(paramName)) { if (requestMap.containsKey(paramName)) {
String valueAsString = requestMap.get(paramName); String valueAsString = (String) requestMap.get(paramName);
if (StringUtils.isNotBlank(valueAsString)) { if (StringUtils.isNotBlank(valueAsString)) {
paramValue = Long.valueOf(valueAsString); paramValue = Long.valueOf(valueAsString);
} }
@@ -339,11 +450,24 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
return paramValue; return paramValue;
} }
private Locale extractLocaleValue(Map<String, String> requestMap) { private LocalDate extractLocalDateParameter(final String paramName, final Map<String, ?> requestMap, final Set<String> modifiedParameters) {
LocalDate paramValue = null;
if (requestMap.containsKey(paramName)) {
String valueAsString = (String) requestMap.get(paramName);
if (StringUtils.isNotBlank(valueAsString)) {
final String dateFormat = (String) requestMap.get("dateFormat");
paramValue = convertFrom(valueAsString, paramName, dateFormat);
}
modifiedParameters.add(paramName);
}
return paramValue;
}
private Locale extractLocaleValue(Map<String, ?> requestMap) {
Locale clientApplicationLocale = null; Locale clientApplicationLocale = null;
String locale = null; String locale = null;
if (requestMap.containsKey("locale")) { if (requestMap.containsKey("locale")) {
locale = requestMap.get("locale"); locale = (String) requestMap.get("locale");
clientApplicationLocale = localeFromString(locale); clientApplicationLocale = localeFromString(locale);
} }
return clientApplicationLocale; return clientApplicationLocale;
@@ -37,11 +37,12 @@ public class Fund extends AbstractAuditableCustom<AppUser, Long> {
} }
public void update(final FundCommand command) { public void update(final FundCommand command) {
if (StringUtils.isNotBlank(command.getName())) {
this.name = command.getName(); if (command.isNameChanged()) {
this.name = StringUtils.defaultIfEmpty(command.getName(), null);
} }
if (command.getExternalId() != null) { if (command.isExternalIdChanged()) {
this.externalId = StringUtils.defaultIfEmpty(command.getExternalId(), null); this.externalId = StringUtils.defaultIfEmpty(command.getExternalId(), null);
} }
} }
@@ -56,7 +56,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf
context.authenticatedUser(); context.authenticatedUser();
FundCommandValidator validator = new FundCommandValidator(command); FundCommandValidator validator = new FundCommandValidator(command);
validator.validateForCreate(); validator.validateForUpdate();
final Long fundId = command.getId(); final Long fundId = command.getId();
Fund fund = this.fundRepository.findOne(fundId); Fund fund = this.fundRepository.findOne(fundId);
@@ -25,7 +25,6 @@ public class LoanProductCommandValidator {
baseDataValidator.reset().parameter("id").value(command.getId()).notNull(); baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank(); baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("description").value(command.getDescription()).ignoreIfNull().notExceedingLengthOf(500); baseDataValidator.reset().parameter("description").value(command.getDescription()).ignoreIfNull().notExceedingLengthOf(500);
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank(); baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().notNull().inMinMaxRange(0, 6); baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().notNull().inMinMaxRange(0, 6);
@@ -44,7 +43,7 @@ public class LoanProductCommandValidator {
baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull().notNull().inMinMaxRange(0, 1); baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull().notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestCalculationPeriodType").value(command.getInterestCalculationPeriodType()).ignoreIfNull().notNull().inMinMaxRange(0, 1); baseDataValidator.reset().parameter("interestCalculationPeriodType").value(command.getInterestCalculationPeriodType()).ignoreIfNull().notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().anyOfNotNull(command.getFundId(), command.getName(), command.getDescription(), command.getExternalId(), command.getCurrencyCode(), command.getDigitsAfterDecimal(), baseDataValidator.reset().anyOfNotNull(command.getFundId(), command.getName(), command.getDescription(), command.getCurrencyCode(), command.getDigitsAfterDecimal(),
command.getPrincipal(), command.getInArrearsTolerance(), command.getRepaymentFrequencyType(), command.getRepaymentEvery(), command.getNumberOfRepayments(), command.getPrincipal(), command.getInArrearsTolerance(), command.getRepaymentFrequencyType(), command.getRepaymentEvery(), command.getNumberOfRepayments(),
command.getInterestRatePerPeriod(), command.getInterestRateFrequencyType(), command.getAmortizationType(), command.getInterestType(), command.getInterestCalculationPeriodType()); command.getInterestRatePerPeriod(), command.getInterestRateFrequencyType(), command.getAmortizationType(), command.getInterestType(), command.getInterestCalculationPeriodType());
@@ -61,7 +60,6 @@ public class LoanProductCommandValidator {
baseDataValidator.reset().parameter("name").value(command.getName()).notBlank(); baseDataValidator.reset().parameter("name").value(command.getName()).notBlank();
baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(500); baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(500);
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).notExceedingLengthOf(100);
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6); baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6);
@@ -98,28 +98,35 @@ public class Office extends AbstractAuditableCustom<AppUser, Long> {
return this.parent == null; return this.parent == null;
} }
public void update(final OfficeCommand command) { public void update(final OfficeCommand command) {
if (StringUtils.isNotBlank(command.getName())) {
this.name = command.getName().trim(); if (command.isNameChanged()) {
this.name = StringUtils.defaultIfEmpty(command.getName(), null);
} }
if (command.getExternalId() != null) { if (command.isExternalIdChanged()) {
this.externalId = StringUtils.defaultIfEmpty(command.getExternalId().trim(), null); this.externalId = StringUtils.defaultIfEmpty(command.getExternalId(), null);
} }
if (command.getOpeningDate() != null) { if (command.isOpeningDateChanged()) {
this.openingDate = command.getOpeningLocalDate().toDate(); if (command.getOpeningDate() != null) {
this.openingDate = command.getOpeningDate().toDate();
} else {
this.openingDate = null;
}
} }
} }
public void update(Office newParent) { public void update(final Office newParent) {
if (this.parent == null) { if (this.parent == null) {
throw new RootOfficeParentCannotBeUpdated(); throw new RootOfficeParentCannotBeUpdated();
} }
if (this.identifiedBy(newParent.getId())) { if (this.identifiedBy(newParent.getId())) {
throw new CannotUpdateOfficeWithParentOfficeSameAsSelf(this.getId(), newParent.getId()); throw new CannotUpdateOfficeWithParentOfficeSameAsSelf(this.getId(), newParent.getId());
} }
this.parent = newParent; this.parent = newParent;
generateHierarchy(); generateHierarchy();
} }
@@ -56,7 +56,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId()); Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId());
Office office = Office.createNew(parent, command.getName(), command.getOpeningLocalDate(), command.getExternalId()); Office office = Office.createNew(parent, command.getName(), command.getOpeningDate(), command.getExternalId());
// pre save to generate id for use in office hierarchy // pre save to generate id for use in office hierarchy
this.officeRepository.save(office); this.officeRepository.save(office);
@@ -86,7 +86,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
office.update(command); office.update(command);
if (command.getParentId() != null) { if (command.isParentChanged()) {
Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId()); Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId());
office.update(parent); office.update(parent);
} }