MIFOSX-311: cherry pick of fix from 0.11.4 branch.

This commit is contained in:
Keith Woodlock
2013-04-30 01:20:02 +01:00
parent bc85e81316
commit f9f55b8b3a
4 changed files with 197 additions and 150 deletions
@@ -36,12 +36,12 @@ public final class CalculateLoanScheduleQueryFromApiJsonHelper {
/** /**
* The parameters supported for this command. * The parameters supported for this command.
*/ */
final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "clientId", "groupId", "loanType", "calendarId", "productId", "accountNo", final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "clientId", "groupId", "loanType", "calendarId",
"externalId", "fundId", "loanOfficerId", "loanPurposeId", "transactionProcessingStrategyId", "principal", "inArrearsTolerance", "productId", "accountNo", "externalId", "fundId", "loanOfficerId", "loanPurposeId", "transactionProcessingStrategyId",
"interestRatePerPeriod", "repaymentEvery", "numberOfRepayments", "loanTermFrequency", "loanTermFrequencyType", "principal", "inArrearsTolerance", "interestRatePerPeriod", "repaymentEvery", "numberOfRepayments", "loanTermFrequency",
"repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType", "interestCalculationPeriodType", "loanTermFrequencyType", "repaymentFrequencyType", "interestRateFrequencyType", "amortizationType", "interestType",
"expectedDisbursementDate", "repaymentsStartingFromDate", "interestChargedFromDate", "submittedOnDate", "submittedOnNote", "interestCalculationPeriodType", "expectedDisbursementDate", "repaymentsStartingFromDate", "interestChargedFromDate",
"locale", "dateFormat", "charges", "collateral")); "submittedOnDate", "submittedOnNote", "locale", "dateFormat", "charges", "collateral"));
private final FromJsonHelper fromApiJsonHelper; private final FromJsonHelper fromApiJsonHelper;
@@ -98,7 +98,8 @@ public final class CalculateLoanScheduleQueryFromApiJsonHelper {
final String interestRatePerPeriodParameterName = "interestRatePerPeriod"; final String interestRatePerPeriodParameterName = "interestRatePerPeriod";
final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(interestRatePerPeriodParameterName, final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(interestRatePerPeriodParameterName,
element); element);
baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notNull().positiveAmount(); baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notNull()
.zeroOrPositiveAmount();
final String interestTypeParameterName = "interestType"; final String interestTypeParameterName = "interestType";
final Integer interestType = fromApiJsonHelper.extractIntegerWithLocaleNamed(interestTypeParameterName, element); final Integer interestType = fromApiJsonHelper.extractIntegerWithLocaleNamed(interestTypeParameterName, element);
@@ -160,7 +160,8 @@ public final class LoanApplicationCommandFromApiJsonHelper {
final String interestRatePerPeriodParameterName = "interestRatePerPeriod"; final String interestRatePerPeriodParameterName = "interestRatePerPeriod";
final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(interestRatePerPeriodParameterName, final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(interestRatePerPeriodParameterName,
element); element);
baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notNull().positiveAmount(); baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notNull()
.zeroOrPositiveAmount();
final String interestTypeParameterName = "interestType"; final String interestTypeParameterName = "interestType";
final Integer interestType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestTypeParameterName, element); final Integer interestType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestTypeParameterName, element);
@@ -427,7 +428,8 @@ public final class LoanApplicationCommandFromApiJsonHelper {
atLeastOneParameterPassedForUpdate = true; atLeastOneParameterPassedForUpdate = true;
final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(interestRatePerPeriodParameterName, final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(interestRatePerPeriodParameterName,
element); element);
baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notNull().positiveAmount(); baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notNull()
.zeroOrPositiveAmount();
} }
final String interestTypeParameterName = "interestType"; final String interestTypeParameterName = "interestType";
@@ -600,11 +602,21 @@ public final class LoanApplicationCommandFromApiJsonHelper {
"Validation errors exist.", dataValidationErrors); } "Validation errors exist.", dataValidationErrors); }
} }
public void validateMinMaxConstraintsForModification(final String json, final LoanProduct loanProduct) { public void validateMinMaxConstraintValues(final JsonElement element, final LoanProduct loanProduct) {
final JsonElement element = fromApiJsonHelper.parse(json);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan"); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan");
this.loanProductCommandFromApiJsonDeserializer.validateMinMaxConstraints(element, baseDataValidator, loanProduct);
final BigDecimal minPrincipal = loanProduct.getMinPrincipalAmount().getAmount();
final BigDecimal maxPrincipal = loanProduct.getMaxPrincipalAmount().getAmount();
final String principalParameterName = "principal";
if (fromApiJsonHelper.parameterExists(principalParameterName, element)) {
final BigDecimal principal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(principalParameterName, element);
baseDataValidator.reset().parameter(principalParameterName).value(principal).notNull().positiveAmount()
.inMinAndMaxAmountRange(minPrincipal, maxPrincipal);
}
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); } "Validation errors exist.", dataValidationErrors); }
} }
@@ -232,7 +232,7 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
} }
// validate min and maximum constraints // validate min and maximum constraints
this.fromApiJsonDeserializer.validateMinMaxConstraintsForModification(command.json(), existingLoanApplication.loanProduct()); this.fromApiJsonDeserializer.validateForModify(command.json());
final String fundIdParamName = "fundId"; final String fundIdParamName = "fundId";
if (changes.containsKey(fundIdParamName)) { if (changes.containsKey(fundIdParamName)) {
@@ -308,7 +308,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
} }
} else { } else {
// attaching new calendar // attaching new calendar
CalendarInstance calendarInstance = new CalendarInstance(calendar, existingLoanApplication.getId(), CalendarEntityType.LOANS.getValue()); CalendarInstance calendarInstance = new CalendarInstance(calendar, existingLoanApplication.getId(),
CalendarEntityType.LOANS.getValue());
this.calendarInstanceRepository.save(calendarInstance); this.calendarInstanceRepository.save(calendarInstance);
} }
@@ -104,7 +104,8 @@ public final class LoanProductCommandFromApiJsonDeserializer {
if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) != -1) { if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) != -1) {
baseDataValidator.reset().parameter(maxPrincipalParameterName).value(maxPrincipalAmount).notLessThanMin(minPrincipalAmount); baseDataValidator.reset().parameter(maxPrincipalParameterName).value(maxPrincipalAmount).notLessThanMin(minPrincipalAmount);
if (minPrincipalAmount.compareTo(maxPrincipalAmount) <= 0) { if (minPrincipalAmount.compareTo(maxPrincipalAmount) <= 0) {
baseDataValidator.reset().parameter("principal").value(principal).inMinAndMaxAmountRange(minPrincipalAmount, maxPrincipalAmount); baseDataValidator.reset().parameter("principal").value(principal)
.inMinAndMaxAmountRange(minPrincipalAmount, maxPrincipalAmount);
} }
} else { } else {
baseDataValidator.reset().parameter("principal").value(principal).notGreaterThanMax(maxPrincipalAmount); baseDataValidator.reset().parameter("principal").value(principal).notGreaterThanMax(maxPrincipalAmount);
@@ -120,24 +121,29 @@ public final class LoanProductCommandFromApiJsonDeserializer {
Integer minNumberOfRepayments = null; Integer minNumberOfRepayments = null;
if (fromApiJsonHelper.parameterExists(minNumberOfRepaymentsParameterName, element)) { if (fromApiJsonHelper.parameterExists(minNumberOfRepaymentsParameterName, element)) {
minNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(minNumberOfRepaymentsParameterName, element); minNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(minNumberOfRepaymentsParameterName, element);
baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments).ignoreIfNull()
.integerGreaterThanZero();
} }
String maxNumberOfRepaymentsParameterName = "maxNumberOfRepayments"; String maxNumberOfRepaymentsParameterName = "maxNumberOfRepayments";
Integer maxNumberOfRepayments = null; Integer maxNumberOfRepayments = null;
if (fromApiJsonHelper.parameterExists(maxNumberOfRepaymentsParameterName, element)) { if (fromApiJsonHelper.parameterExists(maxNumberOfRepaymentsParameterName, element)) {
maxNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(maxNumberOfRepaymentsParameterName, element); maxNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(maxNumberOfRepaymentsParameterName, element);
baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments).ignoreIfNull()
.integerGreaterThanZero();
} }
if (maxNumberOfRepayments != null && maxNumberOfRepayments.compareTo(0) == 1) { if (maxNumberOfRepayments != null && maxNumberOfRepayments.compareTo(0) == 1) {
if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) {
baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments).notLessThanMin(minNumberOfRepayments); baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments)
.notLessThanMin(minNumberOfRepayments);
if (minNumberOfRepayments.compareTo(maxNumberOfRepayments) <= 0) { if (minNumberOfRepayments.compareTo(maxNumberOfRepayments) <= 0) {
baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments).inMinMaxRange(minNumberOfRepayments, maxNumberOfRepayments); baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments)
.inMinMaxRange(minNumberOfRepayments, maxNumberOfRepayments);
} }
} else { } else {
baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments).notGreaterThanMax(maxNumberOfRepayments); baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments)
.notGreaterThanMax(maxNumberOfRepayments);
} }
} else if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { } else if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) {
baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments).notLessThanMin(minNumberOfRepayments); baseDataValidator.reset().parameter("numberOfRepayments").value(numberOfRepayments).notLessThanMin(minNumberOfRepayments);
@@ -157,27 +163,33 @@ public final class LoanProductCommandFromApiJsonDeserializer {
BigDecimal minInterestRatePerPeriod = null; BigDecimal minInterestRatePerPeriod = null;
if (fromApiJsonHelper.parameterExists(minInterestRatePerPeriodParameterName, element)) { if (fromApiJsonHelper.parameterExists(minInterestRatePerPeriodParameterName, element)) {
minInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minInterestRatePerPeriodParameterName, element); minInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minInterestRatePerPeriodParameterName, element);
baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName).value(minInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName).value(minInterestRatePerPeriod).ignoreIfNull()
.zeroOrPositiveAmount();
} }
String maxInterestRatePerPeriodParameterName = "maxInterestRatePerPeriod"; String maxInterestRatePerPeriodParameterName = "maxInterestRatePerPeriod";
BigDecimal maxInterestRatePerPeriod = null; BigDecimal maxInterestRatePerPeriod = null;
if (fromApiJsonHelper.parameterExists(maxInterestRatePerPeriodParameterName, element)) { if (fromApiJsonHelper.parameterExists(maxInterestRatePerPeriodParameterName, element)) {
maxInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxInterestRatePerPeriodParameterName, element); maxInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxInterestRatePerPeriodParameterName, element);
baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).ignoreIfNull()
.zeroOrPositiveAmount();
} }
if (maxInterestRatePerPeriod != null && maxInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { if (maxInterestRatePerPeriod != null && maxInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) {
if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) {
baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).notLessThanMin(minInterestRatePerPeriod); baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod)
.notLessThanMin(minInterestRatePerPeriod);
if (minInterestRatePerPeriod.compareTo(maxInterestRatePerPeriod) <= 0) { if (minInterestRatePerPeriod.compareTo(maxInterestRatePerPeriod) <= 0) {
baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).inMinAndMaxAmountRange(minInterestRatePerPeriod, maxInterestRatePerPeriod); baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod)
.inMinAndMaxAmountRange(minInterestRatePerPeriod, maxInterestRatePerPeriod);
} }
} else { } else {
baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).notGreaterThanMax(maxInterestRatePerPeriod); baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod)
.notGreaterThanMax(maxInterestRatePerPeriod);
} }
} else if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) { } else if (minInterestRatePerPeriod != null && minInterestRatePerPeriod.compareTo(BigDecimal.ZERO) != -1) {
baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).notLessThanMin(minInterestRatePerPeriod); baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod)
.notLessThanMin(minInterestRatePerPeriod);
} }
final Integer interestRateFrequencyType = fromApiJsonHelper.extractIntegerNamed("interestRateFrequencyType", element, final Integer interestRateFrequencyType = fromApiJsonHelper.extractIntegerNamed("interestRateFrequencyType", element,
@@ -324,33 +336,37 @@ public final class LoanProductCommandFromApiJsonDeserializer {
BigDecimal minInterestRatePerPeriod = null; BigDecimal minInterestRatePerPeriod = null;
if (fromApiJsonHelper.parameterExists(minInterestRatePerPeriodParameterName, element)) { if (fromApiJsonHelper.parameterExists(minInterestRatePerPeriodParameterName, element)) {
minInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minInterestRatePerPeriodParameterName, element); minInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minInterestRatePerPeriodParameterName, element);
baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName).value(minInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName).value(minInterestRatePerPeriod).ignoreIfNull()
.zeroOrPositiveAmount();
} }
String maxInterestRatePerPeriodParameterName = "maxInterestRatePerPeriod"; String maxInterestRatePerPeriodParameterName = "maxInterestRatePerPeriod";
BigDecimal maxInterestRatePerPeriod = null; BigDecimal maxInterestRatePerPeriod = null;
if (fromApiJsonHelper.parameterExists(maxInterestRatePerPeriodParameterName, element)) { if (fromApiJsonHelper.parameterExists(maxInterestRatePerPeriodParameterName, element)) {
maxInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxInterestRatePerPeriodParameterName, element); maxInterestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(maxInterestRatePerPeriodParameterName, element);
baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).ignoreIfNull().zeroOrPositiveAmount(); baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).ignoreIfNull()
.zeroOrPositiveAmount();
} }
if (fromApiJsonHelper.parameterExists("interestRatePerPeriod", element)) { if (fromApiJsonHelper.parameterExists("interestRatePerPeriod", element)) {
final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element); final BigDecimal interestRatePerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("interestRatePerPeriod", element);
baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).notNull().positiveAmount(); baseDataValidator.reset().parameter("interestRatePerPeriod").value(interestRatePerPeriod).notNull().zeroOrPositiveAmount();
} }
String minNumberOfRepaymentsParameterName = "minNumberOfRepayments"; String minNumberOfRepaymentsParameterName = "minNumberOfRepayments";
Integer minNumberOfRepayments = null; Integer minNumberOfRepayments = null;
if (fromApiJsonHelper.parameterExists(minNumberOfRepaymentsParameterName, element)) { if (fromApiJsonHelper.parameterExists(minNumberOfRepaymentsParameterName, element)) {
minNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(minNumberOfRepaymentsParameterName, element); minNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(minNumberOfRepaymentsParameterName, element);
baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments).ignoreIfNull()
.integerGreaterThanZero();
} }
String maxNumberOfRepaymentsParameterName = "maxNumberOfRepayments"; String maxNumberOfRepaymentsParameterName = "maxNumberOfRepayments";
Integer maxNumberOfRepayments = null; Integer maxNumberOfRepayments = null;
if (fromApiJsonHelper.parameterExists(maxNumberOfRepaymentsParameterName, element)) { if (fromApiJsonHelper.parameterExists(maxNumberOfRepaymentsParameterName, element)) {
maxNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(maxNumberOfRepaymentsParameterName, element); maxNumberOfRepayments = fromApiJsonHelper.extractIntegerWithLocaleNamed(maxNumberOfRepaymentsParameterName, element);
baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments).ignoreIfNull()
.integerGreaterThanZero();
} }
if (fromApiJsonHelper.parameterExists("numberOfRepayments", element)) { if (fromApiJsonHelper.parameterExists("numberOfRepayments", element)) {
@@ -450,7 +466,8 @@ public final class LoanProductCommandFromApiJsonDeserializer {
throwExceptionIfValidationWarningsExist(dataValidationErrors); throwExceptionIfValidationWarningsExist(dataValidationErrors);
} }
public void validateMinMaxConstraints(final JsonElement element, final DataValidatorBuilder baseDataValidator, final LoanProduct loanProduct){ public void validateMinMaxConstraints(final JsonElement element, final DataValidatorBuilder baseDataValidator,
final LoanProduct loanProduct) {
validatePrincipalMinMaxConstraint(element, loanProduct, baseDataValidator); validatePrincipalMinMaxConstraint(element, loanProduct, baseDataValidator);
@@ -459,7 +476,8 @@ public final class LoanProductCommandFromApiJsonDeserializer {
validateNominalInterestRatePerPeriodMinMaxConstraint(element, loanProduct, baseDataValidator); validateNominalInterestRatePerPeriodMinMaxConstraint(element, loanProduct, baseDataValidator);
} }
private void validatePrincipalMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct, final DataValidatorBuilder baseDataValidator) { private void validatePrincipalMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct,
final DataValidatorBuilder baseDataValidator) {
boolean principalUpdated = false; boolean principalUpdated = false;
boolean minPrincipalUpdated = false; boolean minPrincipalUpdated = false;
@@ -501,19 +519,23 @@ public final class LoanProductCommandFromApiJsonDeserializer {
if ((principalUpdated || minPrincipalUpdated || maxPrincipalUpdated)) { if ((principalUpdated || minPrincipalUpdated || maxPrincipalUpdated)) {
if((minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) == 1) && (maxPrincipalAmount != null && maxPrincipalAmount.compareTo(BigDecimal.ZERO) == 1)){ if ((minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) == 1)
baseDataValidator.reset().parameter(principalParameterName).value(principalAmount).inMinAndMaxAmountRange(minPrincipalAmount, maxPrincipalAmount); && (maxPrincipalAmount != null && maxPrincipalAmount.compareTo(BigDecimal.ZERO) == 1)) {
baseDataValidator.reset().parameter(principalParameterName).value(principalAmount)
.inMinAndMaxAmountRange(minPrincipalAmount, maxPrincipalAmount);
} else { } else {
if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) == 1) { if (minPrincipalAmount != null && minPrincipalAmount.compareTo(BigDecimal.ZERO) == 1) {
baseDataValidator.reset().parameter(principalParameterName).value(principalAmount).notLessThanMin(minPrincipalAmount); baseDataValidator.reset().parameter(principalParameterName).value(principalAmount).notLessThanMin(minPrincipalAmount);
} else if (maxPrincipalAmount != null && maxPrincipalAmount.compareTo(BigDecimal.ZERO) == 1) { } else if (maxPrincipalAmount != null && maxPrincipalAmount.compareTo(BigDecimal.ZERO) == 1) {
baseDataValidator.reset().parameter(principalParameterName).value(principalAmount).notGreaterThanMax(maxPrincipalAmount); baseDataValidator.reset().parameter(principalParameterName).value(principalAmount)
.notGreaterThanMax(maxPrincipalAmount);
} }
} }
} }
} }
private void validateNumberOfRepaymentsMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct, final DataValidatorBuilder baseDataValidator) { private void validateNumberOfRepaymentsMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct,
final DataValidatorBuilder baseDataValidator) {
boolean numberOfRepaymentsUpdated = false; boolean numberOfRepaymentsUpdated = false;
boolean minNumberOfRepaymentsUpdated = false; boolean minNumberOfRepaymentsUpdated = false;
boolean maxNumberOfRepaymentsUpdated = false; boolean maxNumberOfRepaymentsUpdated = false;
@@ -546,27 +568,33 @@ public final class LoanProductCommandFromApiJsonDeserializer {
} }
if (minNumberOfRepaymentsUpdated) { if (minNumberOfRepaymentsUpdated) {
baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments).ignoreIfNull().notGreaterThanMax(maxNumberOfRepayments); baseDataValidator.reset().parameter(minNumberOfRepaymentsParameterName).value(minNumberOfRepayments).ignoreIfNull()
.notGreaterThanMax(maxNumberOfRepayments);
} }
if (maxNumberOfRepaymentsUpdated) { if (maxNumberOfRepaymentsUpdated) {
baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments).notLessThanMin(minNumberOfRepayments); baseDataValidator.reset().parameter(maxNumberOfRepaymentsParameterName).value(maxNumberOfRepayments)
.notLessThanMin(minNumberOfRepayments);
} }
if (numberOfRepaymentsUpdated || minNumberOfRepaymentsUpdated || maxNumberOfRepaymentsUpdated) { if (numberOfRepaymentsUpdated || minNumberOfRepaymentsUpdated || maxNumberOfRepaymentsUpdated) {
if (maxNumberOfRepayments != null && maxNumberOfRepayments.compareTo(0) == 1) { if (maxNumberOfRepayments != null && maxNumberOfRepayments.compareTo(0) == 1) {
if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) {
baseDataValidator.reset().parameter(numberOfRepaymentsParameterName).value(numberOfRepayments).inMinMaxRange(minNumberOfRepayments, maxNumberOfRepayments); baseDataValidator.reset().parameter(numberOfRepaymentsParameterName).value(numberOfRepayments)
.inMinMaxRange(minNumberOfRepayments, maxNumberOfRepayments);
} else { } else {
baseDataValidator.reset().parameter(numberOfRepaymentsParameterName).value(numberOfRepayments).notGreaterThanMax(maxNumberOfRepayments); baseDataValidator.reset().parameter(numberOfRepaymentsParameterName).value(numberOfRepayments)
.notGreaterThanMax(maxNumberOfRepayments);
} }
} else if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) { } else if (minNumberOfRepayments != null && minNumberOfRepayments.compareTo(0) == 1) {
baseDataValidator.reset().parameter(numberOfRepaymentsParameterName).value(numberOfRepayments).notLessThanMin(minNumberOfRepayments); baseDataValidator.reset().parameter(numberOfRepaymentsParameterName).value(numberOfRepayments)
.notLessThanMin(minNumberOfRepayments);
} }
} }
} }
private void validateNominalInterestRatePerPeriodMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct, final DataValidatorBuilder baseDataValidator) { private void validateNominalInterestRatePerPeriodMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct,
final DataValidatorBuilder baseDataValidator) {
boolean iRPUpdated = false; boolean iRPUpdated = false;
boolean minIRPUpdated = false; boolean minIRPUpdated = false;
@@ -600,22 +628,27 @@ public final class LoanProductCommandFromApiJsonDeserializer {
} }
if (minIRPUpdated) { if (minIRPUpdated) {
baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName).value(minInterestRatePerPeriod).ignoreIfNull().notGreaterThanMax(maxInterestRatePerPeriod); baseDataValidator.reset().parameter(minInterestRatePerPeriodParameterName).value(minInterestRatePerPeriod).ignoreIfNull()
.notGreaterThanMax(maxInterestRatePerPeriod);
} }
if (maxIRPUpdated) { if (maxIRPUpdated) {
baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).ignoreIfNull().notLessThanMin(minInterestRatePerPeriod); baseDataValidator.reset().parameter(maxInterestRatePerPeriodParameterName).value(maxInterestRatePerPeriod).ignoreIfNull()
.notLessThanMin(minInterestRatePerPeriod);
} }
if (iRPUpdated || minIRPUpdated || maxIRPUpdated) { if (iRPUpdated || minIRPUpdated || maxIRPUpdated) {
if (maxInterestRatePerPeriod != null) { if (maxInterestRatePerPeriod != null) {
if (minInterestRatePerPeriod != null) { if (minInterestRatePerPeriod != null) {
baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).inMinAndMaxAmountRange(minInterestRatePerPeriod, maxInterestRatePerPeriod); baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod)
.inMinAndMaxAmountRange(minInterestRatePerPeriod, maxInterestRatePerPeriod);
} else { } else {
baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notGreaterThanMax(maxInterestRatePerPeriod); baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod)
.notGreaterThanMax(maxInterestRatePerPeriod);
} }
} else if (minInterestRatePerPeriod != null) { } else if (minInterestRatePerPeriod != null) {
baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod).notLessThanMin(minInterestRatePerPeriod); baseDataValidator.reset().parameter(interestRatePerPeriodParameterName).value(interestRatePerPeriod)
.notLessThanMin(minInterestRatePerPeriod);
} }
} }
} }