From 41493b5c49c4ab4625650c4608a0323ff52cf6d2 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Tue, 29 May 2012 13:30:58 +0100 Subject: [PATCH] support loan product validation messages. --- .../global-translations/messages.properties | 16 ++++++++-------- .../messages_fr.properties | 19 ++++++++++--------- .../platform/DataValidatorBuilder.java | 17 +++++++++++++++++ .../api/ConfigurationApiResource.java | 2 +- .../OrganisationCurrencyCommand.java | 2 +- .../ConfigurationWritePlatformService.java | 2 +- ...WritePlatformServiceJpaRepositoryImpl.java | 2 +- .../service/LoanProductCommandValidator.java | 4 ++-- .../user/service/RoleCommandValidator.java | 2 -- 9 files changed, 41 insertions(+), 25 deletions(-) rename {mifosng-data/src/main/java/org/mifosng/data/command => mifosng-provider/src/main/java/org/mifosng/platform/api/commands}/OrganisationCurrencyCommand.java (93%) diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties index 9a89ec2ce..4ddd7ec19 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties @@ -239,20 +239,20 @@ form.label.loan.product.interest.rate.calcutated.in.period=Interest calculation validation.msg.product.name.cannot.be.blank=Product name cannot be blank. validation.msg.product.description.exceeds.max.length=The content of the description has exceeded max allowed length of 500 characters. -validation.msg.product.currency.digitsAfterDecimal.cannot.be.empty=You must enter a number to represent number of digits after decimal to be supported for product. +validation.msg.product.digitsAfterDecimal.cannot.be.blank=You must enter a number to represent number of digits after decimal to be supported for product. validation.msg.product.digitsAfterDecimal.is.not.within.expected.range=Decimal places must be a number between {1} and {2} inclusive. -validation.msg.product.repayment.repaidEvery.cannot.be.empty=Repaid every cannot be blank. +validation.msg.product.repaymentEvery.cannot.be.blank=Repaid every cannot be blank. validation.msg.product.repaymentEvery.not.greater.than.zero=Repaid every must be greater than 0. -validation.msg.product.number.of.repayments.cannot.be.empty=# of repayments cannot be blank. +validation.msg.product.numberOfRepayments.cannot.be.blank=# of repayments cannot be blank. validation.msg.product.numberOfRepayments.not.greater.than.zero=# of repayments must be greater than 0. -validation.msg.product.principalFormatted.cannot.be.blank=Loan amount cannot be blank. -validation.msg.product.inArrearsToleranceAmountFormatted.cannot.be.blank=Arrears tolerance cannot be blank. -validation.msg.product.interestRatePerPeriodFormatted.cannot.be.blank=Nominal interest rate % cannot be blank. +validation.msg.product.principal.cannot.be.blank=Loan amount cannot be blank. +validation.msg.product.inArrearsTolerance.cannot.be.blank=Arrears tolerance cannot be blank. +validation.msg.product.interestRatePerPeriod.cannot.be.blank=Nominal interest rate % cannot be blank. -validation.msg.product.principal.amount.must.be.greater.than.zero=Loan amount must be greater than zero. -validation.msg.product.arrears.tolerance.amount.cannot.be.negative=Arrears tolerance cannot be negative. +validation.msg.product.principal.not.greater.than.zero=Loan amount must be greater than zero. +validation.msg.product.inArrearsTolerance.not.zero.or.greater=Arrears tolerance must be greater than or equal to zero. validation.msg.product.interest.rate.per.period.amount.cannot.be.negative=Nominal interest rate % cannot be negative. table.heading.office.name=Office Name diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties index 14f497cda..00b3958c6 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties @@ -235,22 +235,23 @@ form.label.loan.product.nominal.interestrate=Nominal interest rate %:(fr) form.label.loan.product.interest.method=Interest method:(fr) form.label.loan.product.interest.rate.calcutated.in.period=Interest calculation period:(fr) + validation.msg.product.name.cannot.be.blank=Product name cannot be blank.(fr) validation.msg.product.description.exceeds.max.length=The content of the description has exceeded max allowed length of 500 characters.(fr) -validation.msg.product.currency.digitsAfterDecimal.cannot.be.empty=You must enter a number to represent number of digits after decimal to be supported for product.(fr) -validation.msg.product.digitsAfterDecimal.is.not.within.expected.range=Decimal places must be a number between {1} and {2} inclusive. +validation.msg.product.digitsAfterDecimal.cannot.be.blank=You must enter a number to represent number of digits after decimal to be supported for product.(fr) +validation.msg.product.digitsAfterDecimal.is.not.within.expected.range=Decimal places must be a number between {1} and {2} inclusive.(fr) -validation.msg.product.repayment.repaidEvery.cannot.be.empty=Repaid every cannot be blank.(fr) +validation.msg.product.repaymentEvery.cannot.be.blank=Repaid every cannot be blank.(fr) validation.msg.product.repaymentEvery.not.greater.than.zero=Repaid every must be greater than 0.(fr) -validation.msg.product.number.of.repayments.cannot.be.empty=# of repayments cannot be blank.(fr) +validation.msg.product.numberOfRepayments.cannot.be.blank=# of repayments cannot be blank.(fr) validation.msg.product.numberOfRepayments.not.greater.than.zero=# of repayments must be greater than 0.(fr) -validation.msg.product.principalFormatted.cannot.be.blank=Loan amount cannot be blank.(fr) -validation.msg.product.inArrearsToleranceAmountFormatted.cannot.be.blank=Arrears tolerance cannot be blank.(fr) -validation.msg.product.interestRatePerPeriodFormatted.cannot.be.blank=Nominal interest rate % cannot be blank.(fr) +validation.msg.product.principal.cannot.be.blank=Loan amount cannot be blank.(fr) +validation.msg.product.inArrearsTolerance.cannot.be.blank=Arrears tolerance cannot be blank.(fr) +validation.msg.product.interestRatePerPeriod.cannot.be.blank=Nominal interest rate % cannot be blank.(fr) -validation.msg.product.principal.amount.must.be.greater.than.zero=Loan amount must be greater than zero.(fr) -validation.msg.product.arrears.tolerance.amount.cannot.be.negative=Arrears tolerance cannot be negative.(fr) +validation.msg.product.principal.not.greater.than.zero=Loan amount must be greater than zero.(fr) +validation.msg.product.inArrearsTolerance.not.zero.or.greater=Arrears tolerance must be greater than or equal to zero.(fr) validation.msg.product.interest.rate.per.period.amount.cannot.be.negative=Nominal interest rate % cannot be negative.(fr) table.heading.office.name=Office Name(fr) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java b/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java index 9ddf6198d..a301d2999 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java @@ -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; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java index f346a3ba2..006f1c78f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java @@ -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; diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/OrganisationCurrencyCommand.java similarity index 93% rename from mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java rename to mifosng-provider/src/main/java/org/mifosng/platform/api/commands/OrganisationCurrencyCommand.java index 99198299a..0251c562e 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/OrganisationCurrencyCommand.java @@ -1,4 +1,4 @@ -package org.mifosng.data.command; +package org.mifosng.platform.api.commands; import java.io.Serializable; import java.util.List; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformService.java index 3b0eb7ace..988a671e7 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformService.java @@ -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 { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java index 622e86fa4..3a65eaa4c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java @@ -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; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java index 0dd671fae..9fcfcdad6 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java @@ -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(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/RoleCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/RoleCommandValidator.java index 815922aa7..b4aec2c12 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/RoleCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/RoleCommandValidator.java @@ -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); }