support loan product validation messages.

This commit is contained in:
Keith Woodlock
2012-05-29 13:31:16 +01:00
parent 53bf93468f
commit 41493b5c49
9 changed files with 41 additions and 25 deletions
@@ -144,6 +144,23 @@ public class DataValidatorBuilder {
return this;
}
public DataValidatorBuilder zeroOrPositiveAmount() {
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.zero.or.greater");
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" must be greater than or equal to 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;
@@ -11,7 +11,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.mifosng.data.ConfigurationData;
import org.mifosng.data.command.OrganisationCurrencyCommand;
import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.configuration.service.ConfigurationReadPlatformService;
import org.mifosng.platform.configuration.service.ConfigurationWritePlatformService;
@@ -0,0 +1,28 @@
package org.mifosng.platform.api.commands;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class OrganisationCurrencyCommand implements Serializable {
private String[] currencies;
public OrganisationCurrencyCommand() {
//
}
public OrganisationCurrencyCommand(final List<String> selectedCurrencyCodes) {
this.currencies = selectedCurrencyCodes.toArray(new String[selectedCurrencyCodes.size()]);
}
public String[] getCurrencies() {
return currencies;
}
public void setCurrencies(String... currencies) {
this.currencies = currencies;
}
}
@@ -1,6 +1,6 @@
package org.mifosng.platform.configuration.service;
import org.mifosng.data.command.OrganisationCurrencyCommand;
import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
public interface ConfigurationWritePlatformService {
@@ -6,8 +6,8 @@ import java.util.List;
import java.util.Set;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.OrganisationCurrencyCommand;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
import org.mifosng.platform.currency.domain.ApplicationCurrency;
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
@@ -30,7 +30,7 @@ public class LoanProductCommandValidator {
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimalValue()).ignoreIfNull().notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("principal").value(command.getPrincipalValue()).ignoreIfNull().notNull().positiveAmount();
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsToleranceValue()).ignoreIfNull().positiveAmount();
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsToleranceValue()).ignoreIfNull().notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
@@ -66,7 +66,7 @@ public class LoanProductCommandValidator {
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimalValue()).notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("principal").value(command.getPrincipalValue()).notNull().positiveAmount();
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsToleranceValue()).positiveAmount();
baseDataValidator.reset().parameter("inArrearsTolerance").value(command.getInArrearsToleranceValue()).notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("repaymentFrequencyType").value(command.getRepaymentFrequencyType()).notNull().inMinMaxRange(0, 3);
baseDataValidator.reset().parameter("repaymentEvery").value(command.getRepaymentEveryValue()).notNull().greaterThanZero();
@@ -25,8 +25,6 @@ public class RoleCommandValidator {
baseDataValidator.reset().parameter("description").value(command.getDescription()).notBlank().notExceedingLengthOf(500);
baseDataValidator.reset().parameter("permissions").value(command.getPermissions()).arrayNotEmpty();
baseDataValidator.reset().anyOfNotNull(command.getName(), command.getDescription(), command.getPermissions());
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}