update loan product resource for create and update

This commit is contained in:
Keith Woodlock
2012-05-29 02:12:16 +01:00
parent defcce1a31
commit 442b9d93d0
23 changed files with 384 additions and 467 deletions
@@ -1,184 +0,0 @@
package org.mifosng.data.command;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class CommonLoanProperties {
private String currencyCode;
private Integer digitsAfterDecimal;
private BigDecimal principal;
private Integer repaymentEvery;
private Integer repaymentFrequency;
private Integer numberOfRepayments;
private Integer amortizationMethod;
private BigDecimal inArrearsToleranceAmount;
private BigDecimal interestRatePerPeriod;
private Integer interestRateFrequencyMethod;
private Integer interestMethod;
private Integer interestCalculationPeriodMethod;
private boolean flexibleRepaymentSchedule = false;
private boolean interestRebateAllowed = false;
public CommonLoanProperties() {
//
}
public CommonLoanProperties(final String currencyCode,
final Integer digitsAfterDecimal, final Number principal,
final Number interestRatePerPeriod, Integer interestRateFrequencyMethod,
final Integer interestMethod, final Integer interestCalculationPeriodMethod,
final Integer repaymentEvery, final Integer repaymentFrequency, final Integer numberOfRepayments, Integer amortizationMethod, final Number toleranceAmount,
final boolean flexibleRepaymentSchedule,
final boolean interestRebateAllowed) {
this.currencyCode = currencyCode;
this.digitsAfterDecimal = digitsAfterDecimal;
if (principal != null) {
this.principal = BigDecimal.valueOf(Double.valueOf(principal.doubleValue()));
}
if (interestRatePerPeriod != null) {
this.interestRatePerPeriod = BigDecimal.valueOf(Double.valueOf(interestRatePerPeriod.doubleValue()));
}
this.interestRateFrequencyMethod = interestRateFrequencyMethod;
this.interestMethod = interestMethod;
this.interestCalculationPeriodMethod = interestCalculationPeriodMethod;
this.repaymentEvery = repaymentEvery;
this.repaymentFrequency = repaymentFrequency;
this.numberOfRepayments = numberOfRepayments;
this.amortizationMethod = amortizationMethod;
this.inArrearsToleranceAmount = BigDecimal.valueOf(Double.valueOf(toleranceAmount.toString()));
this.flexibleRepaymentSchedule = flexibleRepaymentSchedule;
this.interestRebateAllowed = interestRebateAllowed;
}
public String getCurrencyCode() {
return this.currencyCode;
}
public void setCurrencyCode(final String currencyCode) {
this.currencyCode = currencyCode;
}
public Integer getDigitsAfterDecimal() {
return this.digitsAfterDecimal;
}
public void setDigitsAfterDecimal(final Integer digitsAfterDecimal) {
this.digitsAfterDecimal = digitsAfterDecimal;
}
public Integer getRepaymentEvery() {
return this.repaymentEvery;
}
public void setRepaymentEvery(final Integer repaymentEvery) {
this.repaymentEvery = repaymentEvery;
}
public Integer getRepaymentFrequency() {
return this.repaymentFrequency;
}
public void setRepaymentFrequency(final Integer repaymentFrequency) {
this.repaymentFrequency = repaymentFrequency;
}
public boolean isFlexibleRepaymentSchedule() {
return this.flexibleRepaymentSchedule;
}
public void setFlexibleRepaymentSchedule(
final boolean flexibleRepaymentSchedule) {
this.flexibleRepaymentSchedule = flexibleRepaymentSchedule;
}
public boolean isInterestRebateAllowed() {
return this.interestRebateAllowed;
}
public void setInterestRebateAllowed(final boolean interestRebateAllowed) {
this.interestRebateAllowed = interestRebateAllowed;
}
public BigDecimal getPrincipal() {
return this.principal;
}
public void setPrincipal(final BigDecimal principal) {
this.principal = principal;
}
// public Boolean getFlexibleRepaymentSchedule() {
// return this.flexibleRepaymentSchedule;
// }
// public Boolean getInterestRebateAllowed() {
// return this.interestRebateAllowed;
// }
public Integer getInterestRateFrequencyMethod() {
return interestRateFrequencyMethod;
}
public void setInterestRateFrequencyMethod(Integer interestRateFrequencyMethod) {
this.interestRateFrequencyMethod = interestRateFrequencyMethod;
}
public Integer getInterestMethod() {
return interestMethod;
}
public void setInterestMethod(Integer interestMethod) {
this.interestMethod = interestMethod;
}
public Integer getAmortizationMethod() {
return amortizationMethod;
}
public void setAmortizationMethod(Integer amortizationMethod) {
this.amortizationMethod = amortizationMethod;
}
public Integer getNumberOfRepayments() {
return numberOfRepayments;
}
public void setNumberOfRepayments(Integer numberOfRepayments) {
this.numberOfRepayments = numberOfRepayments;
}
public BigDecimal getInterestRatePerPeriod() {
return interestRatePerPeriod;
}
public void setInterestRatePerPeriod(BigDecimal interestRatePerPeriod) {
this.interestRatePerPeriod = interestRatePerPeriod;
}
public BigDecimal getInArrearsToleranceAmount() {
return inArrearsToleranceAmount;
}
public void setInArrearsToleranceAmount(BigDecimal inArrearsToleranceAmount) {
this.inArrearsToleranceAmount = inArrearsToleranceAmount;
}
public Integer getInterestCalculationPeriodMethod() {
return interestCalculationPeriodMethod;
}
public void setInterestCalculationPeriodMethod(
Integer interestCalculationPeriodMethod) {
this.interestCalculationPeriodMethod = interestCalculationPeriodMethod;
}
}
@@ -1,200 +0,0 @@
package org.mifosng.data.command;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class LoanProductCommand {
private Long id;
private String name;
private String description;
private String externalId;
private String locale;
private String currencyCode;
private Integer digitsAfterDecimal;
private BigDecimal principal;
private String principalFormatted;
private BigDecimal inArrearsToleranceAmount;
private String inArrearsToleranceAmountFormatted;
private Integer repaymentEvery;
private Integer repaymentFrequency;
private Integer numberOfRepayments;
private BigDecimal interestRatePerPeriod;
private String interestRatePerPeriodFormatted;
private Integer interestRateFrequencyMethod;
private Integer amortizationMethod;
private Integer interestMethod;
private Integer interestCalculationPeriodMethod;
protected LoanProductCommand() {
//
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public String getCurrencyCode() {
return currencyCode;
}
public void setCurrencyCode(String currencyCode) {
this.currencyCode = currencyCode;
}
public Integer getDigitsAfterDecimal() {
return digitsAfterDecimal;
}
public void setDigitsAfterDecimal(Integer digitsAfterDecimal) {
this.digitsAfterDecimal = digitsAfterDecimal;
}
public BigDecimal getPrincipal() {
return principal;
}
public void setPrincipal(BigDecimal principal) {
this.principal = principal;
}
public BigDecimal getInArrearsToleranceAmount() {
return inArrearsToleranceAmount;
}
public void setInArrearsToleranceAmount(BigDecimal inArrearsToleranceAmount) {
this.inArrearsToleranceAmount = inArrearsToleranceAmount;
}
public Integer getRepaymentEvery() {
return repaymentEvery;
}
public void setRepaymentEvery(Integer repaymentEvery) {
this.repaymentEvery = repaymentEvery;
}
public Integer getRepaymentFrequency() {
return repaymentFrequency;
}
public void setRepaymentFrequency(Integer repaymentFrequency) {
this.repaymentFrequency = repaymentFrequency;
}
public Integer getNumberOfRepayments() {
return numberOfRepayments;
}
public void setNumberOfRepayments(Integer numberOfRepayments) {
this.numberOfRepayments = numberOfRepayments;
}
public BigDecimal getInterestRatePerPeriod() {
return interestRatePerPeriod;
}
public void setInterestRatePerPeriod(BigDecimal interestRatePerPeriod) {
this.interestRatePerPeriod = interestRatePerPeriod;
}
public Integer getInterestRateFrequencyMethod() {
return interestRateFrequencyMethod;
}
public void setInterestRateFrequencyMethod(Integer interestRateFrequencyMethod) {
this.interestRateFrequencyMethod = interestRateFrequencyMethod;
}
public Integer getAmortizationMethod() {
return amortizationMethod;
}
public void setAmortizationMethod(Integer amortizationMethod) {
this.amortizationMethod = amortizationMethod;
}
public Integer getInterestMethod() {
return interestMethod;
}
public void setInterestMethod(Integer interestMethod) {
this.interestMethod = interestMethod;
}
public Integer getInterestCalculationPeriodMethod() {
return interestCalculationPeriodMethod;
}
public void setInterestCalculationPeriodMethod(
Integer interestCalculationPeriodMethod) {
this.interestCalculationPeriodMethod = interestCalculationPeriodMethod;
}
public String getPrincipalFormatted() {
return principalFormatted;
}
public void setPrincipalFormatted(String principalFormatted) {
this.principalFormatted = principalFormatted;
}
public String getInterestRatePerPeriodFormatted() {
return interestRatePerPeriodFormatted;
}
public void setInterestRatePerPeriodFormatted(
String interestRatePerPeriodFormatted) {
this.interestRatePerPeriodFormatted = interestRatePerPeriodFormatted;
}
public String getInArrearsToleranceAmountFormatted() {
return inArrearsToleranceAmountFormatted;
}
public void setInArrearsToleranceAmountFormatted(
String inArrearsToleranceAmountFormatted) {
this.inArrearsToleranceAmountFormatted = inArrearsToleranceAmountFormatted;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
}
@@ -58,7 +58,7 @@
<tr>
<td><spring:message code="form.label.loan.product.loan.amount"/></td>
<td>
<input id="principalFormatted" name="principalFormatted" title="" style="width: 125px;" value="{{=$ctx.money(principalMoney)}}" />
<input id="principal" name="principal" title="" style="width: 125px;" value="{{=$ctx.money(principalMoney)}}" />
</td>
</tr>
<tr>
@@ -66,7 +66,7 @@
<td>
<input id="repaymentEvery" name="repaymentEvery" title="" style="width: 50px;" value="{{=$ctx.number(repaidEvery)}}"/>
<select id="repaymentFrequency" name="repaymentFrequency" title="" style="width: 121px;">
<select id="repaymentFrequencyType" name="repaymentFrequencyType" title="" style="width: 121px;">
{{#each repaymentFrequencyOptions}}
{{#if $ctx.number($parent.parent.data.repaymentPeriodFrequency)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -90,9 +90,9 @@
<tr>
<td><spring:message code="form.label.loan.product.nominal.interestrate"/></td>
<td>
<input id="interestRatePerPeriodFormatted" name="interestRatePerPeriodFormatted" title="" style="width: 70px;" value="{{=$ctx.decimal(interestRatePerPeriod, 4)}}" />
<input id="interestRatePerPeriod" name="interestRatePerPeriod" title="" style="width: 70px;" value="{{=$ctx.decimal(interestRatePerPeriod, 4)}}" />
<select id="interestRateFrequencyMethod" name="interestRateFrequencyMethod" title="" style="width: 139px;">
<select id="interestRateFrequencyType" name="interestRateFrequencyType" title="" style="width: 139px;">
{{#each interestFrequencyOptions}}
{{#if $ctx.number($parent.parent.data.interestRatePeriod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -106,7 +106,7 @@
<tr>
<td><spring:message code="form.label.loan.product.amortization"/></td>
<td>
<select id="amortizationMethod" name="amortizationMethod" title="" style="width: 220px;">
<select id="amortizationType" name="amortizationType" title="" style="width: 220px;">
{{#each possibleAmortizationOptions}}
{{#if $ctx.number($parent.parent.data.amortizationMethod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -120,7 +120,7 @@
<tr>
<td><spring:message code="form.label.loan.product.interest.method"/></td>
<td>
<select id="interestMethod" name="interestMethod" title="" style="width: 220px;">
<select id="interestType" name="interestType" title="" style="width: 220px;">
{{#each possibleInterestOptions}}
{{#if $ctx.number($parent.parent.data.interestMethod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -134,7 +134,7 @@
<tr>
<td><spring:message code="form.label.loan.product.interest.rate.calcutated.in.period"/></td>
<td>
<select id="interestCalculationPeriodMethod" name="interestCalculationPeriodMethod" title="" style="width: 220px;">
<select id="interestCalculationPeriodType" name="interestCalculationPeriodType" title="" style="width: 220px;">
{{#each possibleInterestRateCalculatedInPeriodOptions}}
{{#if $ctx.number($parent.parent.data.interestRateCalculatedInPeriod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -148,7 +148,7 @@
<tr>
<td><spring:message code="form.label.loan.product.arrears.tolerance"/></td>
<td>
<input id="inArrearsToleranceAmountFormatted" name="inArrearsToleranceAmountFormatted" title="" style="width: 215px;" value="{{=$ctx.money(inArrearsTolerance)}}" />
<input id="inArrearsTolerance" name="inArrearsTolerance" title="" style="width: 215px;" value="{{=$ctx.money(inArrearsTolerance)}}" />
</td>
</tr>
</table>
@@ -1,5 +1,6 @@
package org.mifosng.platform;
import java.math.BigDecimal;
import java.util.List;
import org.apache.commons.lang.StringUtils;
@@ -126,6 +127,23 @@ public class DataValidatorBuilder {
return this;
}
public DataValidatorBuilder positiveAmount() {
if (value == null && ignoreNullValue) {
return this;
}
if (value != null) {
BigDecimal number = BigDecimal.valueOf(Double.valueOf(value.toString()));
if (number.compareTo(BigDecimal.ZERO) <= 0) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".not.greater.than.zero");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be greater than 0.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, number, 0);
dataValidationErrors.add(error);
}
}
return this;
}
public DataValidatorBuilder greaterThanZero() {
if (value == null && ignoreNullValue) {
return this;
@@ -18,7 +18,7 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.LoanProductData;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.loanproduct.service.LoanProductReadPlatformService;
@@ -52,6 +52,23 @@ public class LoanProductApiResource {
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON })
public Response createLoanProduct(LoanProductCommand command) {
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 digitsAfterDecimalValue = this.apiDataConversionService.convertToInteger(command.getDigitsAfterDecimal(), "digitsAfterDecimal", 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.setDigitsAfterDecimalValue(digitsAfterDecimalValue);
command.setRepaymentEveryValue(repaymentEveryValue);
command.setNumberOfRepaymentsValue(numberOfRepaymentsValue);
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService
.createLoanProduct(command);
@@ -116,14 +133,21 @@ public class LoanProductApiResource {
public Response updateLoanProduct(@PathParam("productId") final Long productId, final LoanProductCommand command) {
Locale clientApplicationLocale = this.apiDataConversionService.localeFromString(command.getLocale());
BigDecimal principal = this.apiDataConversionService.convertFrom(command.getPrincipalFormatted(), "principalFormatted", clientApplicationLocale);
BigDecimal interestRatePerPeriod = this.apiDataConversionService.convertFrom(command.getInterestRatePerPeriodFormatted(),"interestRatePerPeriodFormatted", clientApplicationLocale);
BigDecimal inArrearsToleranceAmount = this.apiDataConversionService.convertFrom(command.getInArrearsToleranceAmountFormatted(), "inArrearsToleranceAmountFormatted", clientApplicationLocale);
command.setPrincipal(principal);
command.setInterestRatePerPeriod(interestRatePerPeriod);
command.setInArrearsToleranceAmount(inArrearsToleranceAmount);
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 digitsAfterDecimalValue = this.apiDataConversionService.convertToInteger(command.getDigitsAfterDecimal(), "digitsAfterDecimal", 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.setDigitsAfterDecimalValue(digitsAfterDecimalValue);
command.setRepaymentEveryValue(repaymentEveryValue);
command.setNumberOfRepaymentsValue(numberOfRepaymentsValue);
command.setId(productId);
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.updateLoanProduct(command);
@@ -18,7 +18,7 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.PermissionData;
import org.mifosng.data.RoleData;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.user.service.PermissionReadPlatformService;
import org.mifosng.platform.user.service.RoleReadPlatformService;
@@ -17,7 +17,7 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.data.AppUserData;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.UserCommand;
import org.mifosng.platform.api.commands.UserCommand;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.user.service.AppUserReadPlatformService;
import org.mifosng.platform.user.service.AppUserWritePlatformService;
@@ -0,0 +1,226 @@
package org.mifosng.platform.api.commands;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class LoanProductCommand {
private Long id;
private String name;
private String description;
private String externalId;
private String locale;
private String currencyCode;
private String digitsAfterDecimal;
private Integer digitsAfterDecimalValue;
private BigDecimal principalValue;
private String principal;
private BigDecimal inArrearsToleranceValue;
private String inArrearsTolerance;
private String numberOfRepayments;
private Integer numberOfRepaymentsValue;
private String repaymentEvery;
private Integer repaymentEveryValue;
private String interestRatePerPeriod;
private BigDecimal interestRatePerPeriodValue;
private Integer repaymentFrequencyType;
private Integer interestRateFrequencyType;
private Integer amortizationType;
private Integer interestType;
private Integer interestCalculationPeriodType;
protected LoanProductCommand() {
//
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public String getCurrencyCode() {
return currencyCode;
}
public void setCurrencyCode(String currencyCode) {
this.currencyCode = currencyCode;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public String getDigitsAfterDecimal() {
return digitsAfterDecimal;
}
public void setDigitsAfterDecimal(String digitsAfterDecimal) {
this.digitsAfterDecimal = digitsAfterDecimal;
}
public Integer getDigitsAfterDecimalValue() {
return digitsAfterDecimalValue;
}
public void setDigitsAfterDecimalValue(Integer digitsAfterDecimalValue) {
this.digitsAfterDecimalValue = digitsAfterDecimalValue;
}
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;
}
}
@@ -1,4 +1,4 @@
package org.mifosng.data.command;
package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement;
@@ -1,4 +1,4 @@
package org.mifosng.data.command;
package org.mifosng.platform.api.commands;
import java.io.Serializable;
@@ -10,9 +10,10 @@ 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);
}
@@ -48,6 +48,36 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
return eventLocalDate;
}
@Override
public Integer convertToInteger(String numericalValueFormatted, String parameterName, Locale clientApplicationLocale) {
try {
Integer number = null;
if (StringUtils.isNotBlank(numericalValueFormatted)) {
String sourceWithoutSpaces = numericalValueFormatted.replaceAll(" ", "");
NumberFormat format = NumberFormat.getNumberInstance(clientApplicationLocale);
Number parsedNumber = format.parse(sourceWithoutSpaces);
number = parsedNumber.intValue();
}
return number;
} catch (ParseException e) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError(
"validation.msg.invalid.number.format", "The parameter "
+ parameterName + " is invalid for provided locale"
+ clientApplicationLocale.toString() + ".",
parameterName, numericalValueFormatted,
clientApplicationLocale);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException(
"validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors);
}
}
@Override
public BigDecimal convertFrom(String numericalValueFormatted,
@@ -10,7 +10,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.apache.commons.lang.StringUtils;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
@@ -8,7 +8,7 @@ import javax.persistence.Embedded;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money;
@@ -174,37 +174,37 @@ public class LoanProductRelatedDetail implements
public void update(LoanProductCommand command) {
if (command.getCurrencyCode() != null && command.getDigitsAfterDecimal() != null) {
this.currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
this.currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimalValue());
}
if (command.getPrincipal() != null) {
this.principal = command.getPrincipal();
this.principal = command.getPrincipalValue();
}
if (command.getRepaymentEvery() != null) {
this.repayEvery = command.getRepaymentEvery();
this.repayEvery = command.getRepaymentEveryValue();
}
if (command.getRepaymentFrequency() != null) {
this.repaymentPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequency());
if (command.getRepaymentFrequencyType() != null) {
this.repaymentPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequencyType());
}
if (command.getNumberOfRepayments() != null) {
this.numberOfRepayments = command.getNumberOfRepayments();
this.numberOfRepayments = command.getNumberOfRepaymentsValue();
}
if (command.getAmortizationMethod() != null) {
this.amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationMethod());
if (command.getAmortizationType() != null) {
this.amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationType());
}
if (command.getInArrearsToleranceAmount() != null) {
this.inArrearsTolerance = command.getInArrearsToleranceAmount();
if (command.getInArrearsToleranceValue() != null) {
this.inArrearsTolerance = command.getInArrearsToleranceValue();
}
if (command.getInterestRatePerPeriod() != null) {
this.nominalInterestRatePerPeriod = command.getInterestRatePerPeriod();
this.nominalInterestRatePerPeriod = command.getInterestRatePerPeriodValue();
}
if (command.getInterestRateFrequencyMethod() != null) {
this.interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyMethod());
if (command.getInterestRateFrequencyType() != null) {
this.interestPeriodFrequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyType());
}
if (command.getInterestMethod() != null) {
this.interestMethod = InterestMethod.fromInt(command.getInterestMethod());
if (command.getInterestType() != null) {
this.interestMethod = InterestMethod.fromInt(command.getInterestType());
}
if (command.getInterestCalculationPeriodMethod() != null) {
this.interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodMethod());
if (command.getInterestCalculationPeriodType() != null) {
this.interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodType());
}
}
}
@@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class LoanProductCommandValidator {
@@ -27,25 +27,26 @@ public class LoanProductCommandValidator {
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("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimalValue()).ignoreIfNull().notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("principalFormatted").value(command.getPrincipalFormatted()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("inArrearsToleranceAmountFormatted").value(command.getInArrearsToleranceAmountFormatted()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("principal").value(command.getPrincipalValue()).ignoreIfNull().notNull().positiveAmount();
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsToleranceValue()).ignoreIfNull().positiveAmount();
baseDataValidator.reset().parameter("repaymentFrequency").value(command.getRepaymentFrequency()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).ignoreIfNull().notNull().greaterThanZero();
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).ignoreIfNull().notNull().greaterThanZero();
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("interestRatePerPeriodFormatted").value(command.getInterestRatePerPeriodFormatted()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("interestRateFrequencyMethod").value(command.getInterestRateFrequencyMethod()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEveryValue()).ignoreIfNull().notNull().greaterThanZero();
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepaymentsValue()).ignoreIfNull().notNull().greaterThanZero();
baseDataValidator.reset().parameter("amortizationMethod").value(command.getAmortizationMethod()).ignoreIfNull().notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestMethod").value(command.getInterestMethod()).ignoreIfNull().notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestCalculationPeriodMethod").value(command.getInterestCalculationPeriodMethod()).ignoreIfNull().notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestRatePerPeriod").value(command.getInterestRatePerPeriodValue()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("interestRateFrequencyType").value(command.getInterestRateFrequencyType()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("amortizationType").value(command.getAmortizationType()).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().anyOfNotNull(command.getName(), command.getDescription(), command.getExternalId(), command.getCurrencyCode(), command.getDigitsAfterDecimal(),
command.getPrincipalFormatted(), command.getInArrearsToleranceAmountFormatted(), command.getRepaymentFrequency(), command.getRepaymentEvery(), command.getNumberOfRepayments(),
command.getInterestRatePerPeriodFormatted(), command.getInterestRateFrequencyMethod(), command.getAmortizationMethod(), command.getInterestMethod(), command.getInterestCalculationPeriodMethod());
command.getPrincipal(), command.getInArrearsTolerance(), command.getRepaymentFrequencyType(), command.getRepaymentEvery(), command.getNumberOfRepayments(),
command.getInterestRatePerPeriod(), command.getInterestRateFrequencyType(), command.getAmortizationType(), command.getInterestType(), command.getInterestCalculationPeriodType());
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
@@ -62,21 +63,21 @@ public class LoanProductCommandValidator {
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("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimalValue()).notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("principalFormatted").value(command.getPrincipalFormatted()).notBlank();
baseDataValidator.reset().parameter("inArrearsToleranceAmountFormatted").value(command.getInArrearsToleranceAmountFormatted()).notBlank();
baseDataValidator.reset().parameter("principal").value(command.getPrincipalValue()).notNull().positiveAmount();
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsToleranceValue()).positiveAmount();
baseDataValidator.reset().parameter("repaymentFrequency").value(command.getRepaymentFrequency()).notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEvery()).notNull().greaterThanZero();
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepayments()).notNull().greaterThanZero();
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEveryValue()).notNull().greaterThanZero();
baseDataValidator.reset().parameter("numberOfRepayments").value(command.getNumberOfRepaymentsValue()).notNull().greaterThanZero();
baseDataValidator.reset().parameter("interestRatePerPeriodFormatted").value(command.getInterestRatePerPeriodFormatted()).notBlank();
baseDataValidator.reset().parameter("interestRateFrequencyMethod").value(command.getInterestRateFrequencyMethod()).notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("interestRatePerPeriod").value(command.getInterestRatePerPeriodValue()).notNull();
baseDataValidator.reset().parameter("interestRateFrequencyType").value(command.getInterestRateFrequencyType()).notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("amortizationMethod").value(command.getAmortizationMethod()).notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestMethod").value(command.getInterestMethod()).notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestCalculationPeriodMethod").value(command.getInterestCalculationPeriodMethod()).notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("amortizationType").value(command.getAmortizationType()).notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).notNull().inMinMaxRange(0, 1);
baseDataValidator.reset().parameter("interestCalculationPeriodType").value(command.getInterestCalculationPeriodType()).notNull().inMinMaxRange(0, 1);
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
@@ -1,7 +1,7 @@
package org.mifosng.platform.loanproduct.service;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
public interface LoanProductWritePlatformService {
@@ -5,7 +5,7 @@ import static org.mifosng.platform.Specifications.productThatMatches;
import java.math.BigDecimal;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.exceptions.LoanProductNotFoundException;
import org.mifosng.platform.loan.domain.AmortizationMethod;
@@ -45,25 +45,26 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
validator.validateForCreate();
// assemble LoanProduct from data
InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestMethod());
InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodMethod());
InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestType());
InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodType());
AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationMethod());
AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationType());
PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType
.fromInt(command.getRepaymentFrequency());
.fromInt(command.getRepaymentFrequencyType());
PeriodFrequencyType interestFrequencyType = PeriodFrequencyType
.fromInt(command.getInterestRateFrequencyMethod());
.fromInt(command.getInterestRateFrequencyType());
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimalValue());
BigDecimal annualInterestRate = this.aprCalculator.calculateFrom(interestFrequencyType, command.getInterestRatePerPeriod());
BigDecimal annualInterestRate = this.aprCalculator.calculateFrom(interestFrequencyType, command.getInterestRatePerPeriodValue());
LoanProduct loanproduct = new LoanProduct(currentUser.getOrganisation(), command.getName(), command.getDescription(),
currency, command.getPrincipal(),
command.getInterestRatePerPeriod(), interestFrequencyType, annualInterestRate, interestMethod, interestCalculationPeriodMethod,
command.getRepaymentEvery(), repaymentFrequencyType, command.getNumberOfRepayments(), amortizationMethod, command.getInArrearsToleranceAmount());
currency, command.getPrincipalValue(),
command.getInterestRatePerPeriodValue(), interestFrequencyType, annualInterestRate, interestMethod, interestCalculationPeriodMethod,
command.getRepaymentEveryValue(), repaymentFrequencyType, command.getNumberOfRepaymentsValue(),
amortizationMethod, command.getInArrearsToleranceValue());
this.loanProductRepository.save(loanproduct);
@@ -1,6 +1,6 @@
package org.mifosng.platform.user.service;
import org.mifosng.data.command.UserCommand;
import org.mifosng.platform.api.commands.UserCommand;
import org.springframework.security.access.prepost.PreAuthorize;
public interface AppUserWritePlatformService {
@@ -9,7 +9,7 @@ import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.UserCommand;
import org.mifosng.platform.api.commands.UserCommand;
import org.mifosng.platform.exceptions.OfficeNotFoundException;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
@@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class RoleCommandValidator {
@@ -1,6 +1,6 @@
package org.mifosng.platform.user.service;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.platform.api.commands.RoleCommand;
import org.springframework.security.access.prepost.PreAuthorize;
public interface RoleWritePlatformService {
@@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.exceptions.RoleNotFoundException;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.mifosng.platform.user.domain.AppUser;
@@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.UserCommand;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.UserCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class UserCommandValidator {