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,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;
}
}
@@ -0,0 +1,58 @@
package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement;
/**
* For creating and updating roles. When updating the id is expected to be populated.
*/
@XmlRootElement
public class RoleCommand {
private Long id;
private String name;
private String description;
private String[] permissions;
public RoleCommand() {
//
}
public RoleCommand(final String name, final String description, final String[] permissionIds) {
this.name = name;
this.description = description;
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() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String[] getPermissions() {
return permissions;
}
public void setPermissions(String[] permissions) {
this.permissions = permissions;
}
}
@@ -0,0 +1,112 @@
package org.mifosng.platform.api.commands;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;
/**
* create or update user details command.
*/
@XmlRootElement
public class UserCommand implements Serializable {
private Long id;
private String username;
private String firstname;
private String lastname;
private String password;
private String repeatPassword;
private String email;
private Long officeId;
private String[] notSelectedRoles;
private String[] roles;
public UserCommand() {
//
}
public String getDisplayName() {
return new StringBuilder(this.lastname).append(", ").append(this.firstname).toString();
}
public String getUsername() {
return this.username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(final String password) {
this.password = password;
}
public String getEmail() {
return this.email;
}
public void setEmail(final String email) {
this.email = email;
}
public Long getOfficeId() {
return this.officeId;
}
public void setOfficeId(final Long officeId) {
this.officeId = officeId;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String[] getNotSelectedRoles() {
return notSelectedRoles;
}
public void setNotSelectedRoles(String... notSelectedRoles) {
this.notSelectedRoles = notSelectedRoles;
}
public String[] getRoles() {
return roles;
}
public void setRoles(String... roles) {
this.roles = roles;
}
public String getRepeatPassword() {
return repeatPassword;
}
public void setRepeatPassword(String repeatPassword) {
this.repeatPassword = repeatPassword;
}
}
@@ -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 {