From d87defcb36e712a7731285a5d869993e29a6969e Mon Sep 17 00:00:00 2001 From: Kristof Jozsa Date: Tue, 6 Aug 2024 16:36:26 +0200 Subject: [PATCH] FINERACT-2081: clear closed_on date on repayment reversal --- .../core/data/DataValidatorBuilder.java | 551 ++++++++---------- .../workingdays/service/WorkingDaysUtil.java | 2 +- .../portfolio/calendar/data/CalendarData.java | 2 +- .../portfolio/calendar/domain/Calendar.java | 4 +- .../calendar/service/CalendarUtils.java | 10 +- .../test/stepdef/loan/LoanStepDef.java | 15 + .../fineract-test-application.properties | 2 +- .../src/test/resources/features/Loan.feature | 14 + .../DefaultLoanLifecycleStateMachine.java | 12 + .../domain/LoanApplicationTerms.java | 2 +- .../service/LoanScheduleAssembler.java | 2 +- .../LoanApplicationValidator.java | 15 +- .../LoanTransactionValidator.java | 2 +- .../LoanProductDataValidator.java | 12 +- 14 files changed, 292 insertions(+), 353 deletions(-) diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/data/DataValidatorBuilder.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/data/DataValidatorBuilder.java index da2a1abd585..6a718e16e62 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/data/DataValidatorBuilder.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/data/DataValidatorBuilder.java @@ -38,7 +38,7 @@ public class DataValidatorBuilder { - public static final String VALID_INPUT_SEPERATOR = "_"; + public static final String VALID_INPUT_SEPARATOR = "_"; private final List dataValidationErrors; private String resource; private String parameter; @@ -113,31 +113,29 @@ public DataValidatorBuilder andNotBlank(final String linkedParameterName, final } if (StringUtils.isBlank(linkedValue)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(linkedParameterName).append(".cannot.be.empty.when.").append(this.parameter).append(".is.populated"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(linkedParameterName) - .append("` cannot be empty when ").append(this.parameter).append(" is populated."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), linkedParameterName, linkedValue, this.value); + String validationErrorCode = "validation.msg." + this.resource + "." + linkedParameterName + ".cannot.be.empty.when." + + this.parameter + ".is.populated"; + String defaultEnglishMessage = "The parameter `" + linkedParameterName + "` cannot be empty when " + this.parameter + + " is populated."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, + linkedParameterName, linkedValue, this.value); this.dataValidationErrors.add(error); } return this; } public void failWithCode(final String errorCode, final Object... defaultUserMessageArgs) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".").append(errorCode); - final StringBuilder defaultEnglishMessage = new StringBuilder("Failed data validation due to: ").append(errorCode).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter, this.value, defaultUserMessageArgs); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + "." + errorCode; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, + "Failed data validation due to: " + errorCode + ".", this.parameter, this.value, defaultUserMessageArgs); this.dataValidationErrors.add(error); } public void failWithCodeNoParameterAddedToErrorCode(final String errorCode, final Object... defaultUserMessageArgs) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".").append(errorCode); - final StringBuilder defaultEnglishMessage = new StringBuilder("Failed data validation due to: ").append(errorCode).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter, this.value, defaultUserMessageArgs); + String validationErrorCode = "validation.msg." + this.resource + "." + errorCode; + String defaultEnglishMessage = "Failed data validation due to: " + errorCode + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, defaultUserMessageArgs); this.dataValidationErrors.add(error); } @@ -147,12 +145,10 @@ public DataValidatorBuilder equalToParameter(final String linkedParameterName, f } if (this.value != null && !this.value.equals(linkedValue)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(linkedParameterName).append(".not.equal.to.").append(this.parameter); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(linkedParameterName) - .append("` is not equal to ").append(this.parameter).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), linkedParameterName, linkedValue, this.value); + String validationErrorCode = "validation.msg." + this.resource + "." + linkedParameterName + ".not.equal.to." + this.parameter; + String defaultEnglishMessage = "The parameter `" + linkedParameterName + "` is not equal to " + this.parameter + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, + linkedParameterName, linkedValue, this.value); this.dataValidationErrors.add(error); } return this; @@ -164,12 +160,10 @@ public DataValidatorBuilder notSameAsParameter(final String linkedParameterName, } if (this.value != null && this.value.equals(linkedValue)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(linkedParameterName).append(".same.as.").append(this.parameter); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(linkedParameterName) - .append("` is same as ").append(this.parameter).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), linkedParameterName, linkedValue, this.value); + String validationErrorCode = "validation.msg." + this.resource + "." + linkedParameterName + ".same.as." + this.parameter; + String defaultEnglishMessage = "The parameter `" + linkedParameterName + "` is same as " + this.parameter + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, + linkedParameterName, linkedValue, this.value); this.dataValidationErrors.add(error); } return this; @@ -179,12 +173,9 @@ public DataValidatorBuilder trueOrFalseRequired(final Object trueOfFalseField) { if (trueOfFalseField != null && !trueOfFalseField.toString().equalsIgnoreCase("true") && !trueOfFalseField.toString().equalsIgnoreCase("false")) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".must.be.true.or.false"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be set as true or false."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".must.be.true.or.false"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be set as true or false."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter); this.dataValidationErrors.add(error); } @@ -199,15 +190,13 @@ public DataValidatorBuilder notNull() { .append(this.parameter); if (this.arrayIndex != null && StringUtils.isNotBlank(this.arrayPart)) { validationErrorCode.append(".").append(this.arrayPart); - realParameterName = new StringBuilder(this.parameter).append('[').append(this.arrayIndex).append("][") - .append(this.arrayPart).append(']').toString(); + realParameterName = this.parameter + '[' + this.arrayIndex + "][" + this.arrayPart + ']'; } validationErrorCode.append(".cannot.be.blank"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(realParameterName) - .append("` is mandatory."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), realParameterName, this.arrayIndex); + String defaultEnglishMessage = "The parameter `" + realParameterName + "` is mandatory."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage, + realParameterName, this.arrayIndex); this.dataValidationErrors.add(error); } return this; @@ -224,15 +213,13 @@ public DataValidatorBuilder notBlank() { .append(this.parameter); if (this.arrayIndex != null && StringUtils.isNotBlank(this.arrayPart)) { validationErrorCode.append(".").append(this.arrayPart); - realParameterName = new StringBuilder(this.parameter).append('[').append(this.arrayIndex).append("][") - .append(this.arrayPart).append(']').toString(); + realParameterName = this.parameter + '[' + this.arrayIndex + "][" + this.arrayPart + ']'; } validationErrorCode.append(".cannot.be.blank"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(realParameterName) - .append("` is mandatory."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), realParameterName, this.arrayIndex); + String defaultEnglishMessage = "The parameter `" + realParameterName + "` is mandatory."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage, + realParameterName, this.arrayIndex); this.dataValidationErrors.add(error); } return this; @@ -244,12 +231,10 @@ public DataValidatorBuilder notExceedingLengthOf(final Integer maxLength) { } if (this.value != null && this.value.toString().trim().length() > maxLength) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".exceeds.max.length"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` exceeds max length of ").append(maxLength).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, maxLength, this.value.toString()); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".exceeds.max.length"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` exceeds max length of " + maxLength + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + maxLength, this.value.toString()); this.dataValidationErrors.add(error); } return this; @@ -261,12 +246,9 @@ public DataValidatorBuilder notExceedingListLengthOf(final Integer maxLength) { } if (this.value instanceof List && ((List) this.value).size() > maxLength) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".exceeds.max.length.allowed"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` exceeds allowed max length of ").append(maxLength).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".exceeds.max.length.allowed"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` exceeds allowed max length of " + maxLength + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter); this.dataValidationErrors.add(error); } return this; @@ -280,12 +262,10 @@ public DataValidatorBuilder inMinMaxRange(final Integer min, final Integer max) if (this.value != null) { final Integer number = Integer.valueOf(this.value.toString()); if (number < min || number > max) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.within.expected.range"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be between ").append(min).append(" and ").append(max).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, min, max); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.within.expected.range"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be between " + min + " and " + max + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, min, max); this.dataValidationErrors.add(error); } } @@ -302,13 +282,11 @@ public DataValidatorBuilder isOneOfTheseValues(final Object... values) { if (this.value == null || !rawValuesList.contains(this.value)) { final List valuesList = Arrays.stream(values).map(Object::toString).toList(); final String valuesListStr = String.join(", ", valuesList); - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.one.of.expected.enumerations"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be one of [ ").append(valuesListStr).append(" ] ").append("."); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.one.of.expected.enumerations"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be one of [ " + valuesListStr + " ] " + "."; - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value, values); + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, values); this.dataValidationErrors.add(error); } @@ -331,13 +309,11 @@ public DataValidatorBuilder isOneOfTheseStringValues(final Object... values) { if (this.value == null || !rawValuesList.contains(this.value.toString().toLowerCase())) { final List valuesList = Arrays.stream(values).map(Object::toString).toList(); final String valuesListStr = String.join(", ", valuesList); - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.one.of.expected.enumerations"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be one of [ ").append(valuesListStr).append(" ] ").append("."); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.one.of.expected.enumerations"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be one of [ " + valuesListStr + " ] " + "."; - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value, values); + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, values); this.dataValidationErrors.add(error); } @@ -354,13 +330,11 @@ public DataValidatorBuilder isOneOfTheseStringValues(final List valuesLi if (this.value == null || !valuesListLowercase.contains(this.value.toString().toLowerCase())) { final String valuesListStr = String.join(", ", valuesList); - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.one.of.expected.enumerations"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be one of [ ").append(valuesListStr).append(" ] ").append("."); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.one.of.expected.enumerations"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be one of [ " + valuesListStr + " ] " + "."; - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value, valuesList); + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, valuesList); this.dataValidationErrors.add(error); } @@ -379,13 +353,11 @@ public DataValidatorBuilder isNotOneOfTheseValues(final Object... values) { if (rawValuesList.contains(this.value)) { final List valuesList = Arrays.stream(values).map(Object::toString).toList(); final String valuesListStr = String.join(", ", valuesList); - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.one.of.unwanted.enumerations"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must not be any of [ ").append(valuesListStr).append(" ] ").append("."); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.one.of.unwanted.enumerations"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must not be any of [ " + valuesListStr + " ] " + "."; - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value, values); + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, values); this.dataValidationErrors.add(error); } @@ -401,12 +373,10 @@ public DataValidatorBuilder positiveAmount() { if (this.value != null) { final BigDecimal number = BigDecimal.valueOf(Double.parseDouble(this.value.toString())); if (number.compareTo(BigDecimal.ZERO) <= 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.greater.than.zero"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than 0."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, 0); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.greater.than.zero"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than 0."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, 0); this.dataValidationErrors.add(error); } } @@ -424,12 +394,10 @@ public DataValidatorBuilder zeroOrPositiveAmount() { if (this.value != null) { final BigDecimal number = BigDecimal.valueOf(Double.parseDouble(this.value.toString())); if (number.compareTo(BigDecimal.ZERO) < 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.zero.or.greater"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than or equal to 0."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, 0); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.zero.or.greater"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than or equal to 0."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, 0); this.dataValidationErrors.add(error); } } @@ -445,14 +413,12 @@ public DataValidatorBuilder integerZeroOrGreater() { } if (this.value != null) { - final Integer number = Integer.valueOf(this.value.toString()); + final int number = Integer.parseInt(this.value.toString()); if (number < 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.zero.or.greater"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be zero or greater."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, 0); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.zero.or.greater"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be zero or greater."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, 0); this.dataValidationErrors.add(error); } } @@ -468,14 +434,12 @@ public DataValidatorBuilder integerGreaterThanZero() { } if (this.value != null) { - final Integer number = Integer.valueOf(this.value.toString()); + final int number = Integer.parseInt(this.value.toString()); if (number < 1) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.greater.than.zero"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than 0."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, 0); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.greater.than.zero"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than 0."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, 0); this.dataValidationErrors.add(error); } } @@ -488,14 +452,13 @@ public DataValidatorBuilder integerGreaterThanNumber(Integer number) { } if (this.value != null) { - final Integer intValue = Integer.valueOf(this.value.toString()); + final int intValue = Integer.parseInt(this.value.toString()); if (intValue < number + 1) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.greater.than.specified.number"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than ").append(number); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, intValue, number); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + + ".not.greater.than.specified.number"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than " + number; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + intValue, number); this.dataValidationErrors.add(error); } } @@ -510,12 +473,11 @@ public DataValidatorBuilder integerEqualToOrGreaterThanNumber(Integer number) { if (this.value != null) { final Integer intValue = Integer.valueOf(this.value.toString()); if (intValue < number) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.equal.to.or.greater.than.specified.number"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be equal to or greater than").append(number); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, intValue, number); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + + ".not.equal.to.or.greater.than.specified.number"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be equal to or greater than" + number; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + intValue, number); this.dataValidationErrors.add(error); } } @@ -530,12 +492,10 @@ public DataValidatorBuilder integerSameAsNumber(Integer number) { if (this.value != null) { final Integer intValue = Integer.valueOf(this.value.toString()); if (!intValue.equals(number)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.equal.to.specified.number"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be same as").append(number); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, intValue, number); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.equal.to.specified.number"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be same as" + number; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + intValue, number); this.dataValidationErrors.add(error); } } @@ -550,12 +510,11 @@ public DataValidatorBuilder integerInMultiplesOfNumber(Integer number) { if (this.value != null) { final Integer intValue = Integer.valueOf(this.value.toString()); if (intValue < number || intValue % number != 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.in.multiples.of.specified.number"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be multiples of ").append(number); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, intValue, number); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + + ".not.in.multiples.of.specified.number"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be multiples of " + number; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + intValue, number); this.dataValidationErrors.add(error); } } @@ -571,14 +530,12 @@ public DataValidatorBuilder longGreaterThanZero() { } if (this.value != null) { - final Long number = Long.valueOf(this.value.toString()); + final long number = Long.parseLong(this.value.toString()); if (number < 1) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.greater.than.zero"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than 0."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, 0); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.greater.than.zero"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than 0."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, 0); this.dataValidationErrors.add(error); } } @@ -594,14 +551,12 @@ public DataValidatorBuilder longZeroOrGreater() { } if (this.value != null) { - final Long number = Long.valueOf(this.value.toString()); + final long number = Long.parseLong(this.value.toString()); if (number < 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.equal.or.greater.than.zero"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be equal or greater than 0."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, 0); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.equal.or.greater.than.zero"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be equal or greater than 0."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, 0); this.dataValidationErrors.add(error); } } @@ -614,14 +569,13 @@ public DataValidatorBuilder longGreaterThanNumber(Long number) { } if (this.value != null) { - final Long longValue = Long.valueOf(this.value.toString()); + final long longValue = Long.parseLong(this.value.toString()); if (longValue < number + 1) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.greater.than.specified.number"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than ").append(number); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, longValue, number); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + + ".not.greater.than.specified.number"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than " + number; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + longValue, number); this.dataValidationErrors.add(error); } } @@ -634,14 +588,13 @@ public DataValidatorBuilder longGreaterThanNumber(String paramName, Long number, } if (this.value != null) { - final Long longValue = Long.valueOf(this.value.toString()); + final long longValue = Long.parseLong(this.value.toString()); if (longValue < number + 1) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".not.greater.than.specified.").append(paramName).append(".at Index.").append(index); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than ").append(number); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, longValue, number); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".not.greater.than.specified." + + paramName + ".at Index." + index; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than " + number; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + longValue, number); this.dataValidationErrors.add(error); } } @@ -655,12 +608,9 @@ public DataValidatorBuilder arrayNotEmpty() { final Object[] array = (Object[]) this.value; if (ObjectUtils.isEmpty(array)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".cannot.be.empty"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` cannot be empty. You must select at least one."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".cannot.be.empty"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` cannot be empty. You must select at least one."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter); this.dataValidationErrors.add(error); } return this; @@ -673,24 +623,18 @@ public DataValidatorBuilder jsonArrayNotEmpty() { final JsonArray array = (JsonArray) this.value; if (this.value != null && !array.iterator().hasNext()) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".cannot.be.empty"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` cannot be empty. You must select at least one."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".cannot.be.empty"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` cannot be empty. You must select at least one."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter); this.dataValidationErrors.add(error); } return this; } public void expectedArrayButIsNot() { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.an.array"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` is not an array."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.an.array"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` is not an array."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter); this.dataValidationErrors.add(error); } @@ -704,23 +648,18 @@ public DataValidatorBuilder anyOfNotNull(final Object... object) { } if (!hasData) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource) - .append(".no.parameters.for.update"); - final StringBuilder defaultEnglishMessage = new StringBuilder("No parameters passed for update."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), "id"); + String validationErrorCode = "validation.msg." + this.resource + ".no.parameters.for.update"; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, "No parameters passed for update.", "id"); this.dataValidationErrors.add(error); } return this; } public DataValidatorBuilder inValidValue(final String parameterValueCode, final Object invalidValue) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".invalid.").append(parameterValueCode); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` has an invalid value."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter, invalidValue); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".invalid." + parameterValueCode; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` has an invalid value."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + invalidValue); this.dataValidationErrors.add(error); return this; } @@ -739,12 +678,12 @@ public DataValidatorBuilder mustBeBlankWhenParameterProvided(final String parame return this; } - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".cannot.also.be.provided.when.").append(parameterName).append(".is.populated"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` cannot also be provided when `").append(parameterName).append("` is populated."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter, this.value, parameterName, parameterValue); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".cannot.also.be.provided.when." + + parameterName + ".is.populated"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` cannot also be provided when `" + parameterName + + "` is populated."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, parameterName, parameterValue); this.dataValidationErrors.add(error); return this; } @@ -763,13 +702,12 @@ public DataValidatorBuilder mustBeBlankWhenParameterProvidedIs(final String para return this; } - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".cannot.also.be.provided.when.").append(parameterName).append(".is.") - .append(parameterValue); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` cannot also be provided when `").append(parameterName).append("` is ").append(parameterValue); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter, this.value, parameterName, parameterValue); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".cannot.also.be.provided.when." + + parameterName + ".is." + parameterValue; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` cannot also be provided when `" + parameterName + "` is " + + parameterValue; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, parameterName, parameterValue); this.dataValidationErrors.add(error); return this; } @@ -779,12 +717,12 @@ public DataValidatorBuilder cantBeBlankWhenParameterProvidedIs(final String para return this; } - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".must.be.provided.when.").append(parameterName).append(".is.").append(parameterValue); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be provided when `").append(parameterName).append("` is ").append(parameterValue); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - this.parameter, this.value, parameterName, parameterValue); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".must.be.provided.when." + parameterName + + ".is." + parameterValue; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be provided when `" + parameterName + "` is " + + parameterValue; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, parameterName, parameterValue); this.dataValidationErrors.add(error); return this; } @@ -792,13 +730,11 @@ public DataValidatorBuilder cantBeBlankWhenParameterProvidedIs(final String para public DataValidatorBuilder compareMinimumAndMaximumAmounts(final BigDecimal minimumBalance, final BigDecimal maximumBalance) { if (minimumBalance != null && maximumBalance != null) { if (maximumBalance.compareTo(minimumBalance) < 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.within.expected.range"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` minimum amount ").append(minimumBalance).append(" should less than the maximum amount ") - .append(maximumBalance).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, minimumBalance, maximumBalance); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.within.expected.range"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` minimum amount " + minimumBalance + + " should less than the maximum amount " + maximumBalance + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + minimumBalance, maximumBalance); this.dataValidationErrors.add(error); return this; } @@ -810,13 +746,12 @@ public DataValidatorBuilder inMinAndMaxAmountRange(final BigDecimal minimumAmoun if (minimumAmount != null && maximumAmount != null && this.value != null) { final BigDecimal amount = BigDecimal.valueOf(Double.parseDouble(this.value.toString())); if (amount.compareTo(minimumAmount) < 0 || amount.compareTo(maximumAmount) > 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".amount.is.not.within.min.max.range"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter).append("` amount ") - .append(amount).append(" must be between ").append(minimumAmount).append(" and ").append(maximumAmount) - .append(" ."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, amount, minimumAmount, maximumAmount); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + + ".amount.is.not.within.min.max.range"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` amount " + amount + " must be between " + + minimumAmount + " and " + maximumAmount + " ."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + amount, minimumAmount, maximumAmount); this.dataValidationErrors.add(error); return this; } @@ -828,12 +763,11 @@ public DataValidatorBuilder notLessThanMin(final BigDecimal min) { if (min != null && this.value != null) { final BigDecimal amount = BigDecimal.valueOf(Double.parseDouble(this.value.toString())); if (amount.compareTo(min) < 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.less.than.min"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter).append("` value ") - .append(amount).append(" must not be less than the minimum value ").append(min); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, amount, min); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.less.than.min"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` value " + amount + + " must not be less than the minimum value " + min; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + amount, min); this.dataValidationErrors.add(error); return this; } @@ -845,12 +779,11 @@ public DataValidatorBuilder notGreaterThanMax(final BigDecimal max) { if (max != null && this.value != null) { final BigDecimal amount = BigDecimal.valueOf(Double.parseDouble(this.value.toString())); if (amount.compareTo(max) > 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.greater.than.max"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter).append("` value ") - .append(amount).append(" must not be more than maximum value ").append(max); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, amount, max); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.greater.than.max"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` value " + amount + + " must not be more than maximum value " + max; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + amount, max); this.dataValidationErrors.add(error); return this; } @@ -860,12 +793,10 @@ public DataValidatorBuilder notGreaterThanMax(final BigDecimal max) { public DataValidatorBuilder compareMinAndMaxOfTwoBigDecmimalNos(final BigDecimal min, final BigDecimal max) { if (min != null && max != null && max.compareTo(min) < 0) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.within.expected.range"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(" min number ").append(min) - .append(" should less than max number ").append(max).append("."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, min, max); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.within.expected.range"; + String defaultEnglishMessage = "The " + " min number " + min + " should less than max number " + max + "."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + min, max); this.dataValidationErrors.add(error); return this; } @@ -900,12 +831,10 @@ public DataValidatorBuilder notLessThanMin(final Integer min) { if (this.value != null && min != null) { final Integer number = Integer.valueOf(this.value.toString()); if (number < min) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.less.than.min"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than the minimum value ").append(min); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, min); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.less.than.min"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than the minimum value " + min; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, min); this.dataValidationErrors.add(error); } } @@ -920,12 +849,10 @@ public DataValidatorBuilder notGreaterThanMax(final Integer max) { if (this.value != null && max != null) { final Integer number = Integer.valueOf(this.value.toString()); if (number > max) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.greater.than.max"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be less than the maximum value ").append(max); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, number, max); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.greater.than.max"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be less than the maximum value " + max; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + number, max); this.dataValidationErrors.add(error); } } @@ -938,13 +865,12 @@ public DataValidatorBuilder matchesRegularExpression(final String expression) { } if (this.value != null && !this.value.toString().matches(expression)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".does.not.match.regexp"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must match the provided regular expression [ ").append(expression).append(" ] ").append("."); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".does.not.match.regexp"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must match the provided regular expression [ " + + expression + " ] " + "."; - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value, expression); + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value, expression); this.dataValidationErrors.add(error); } @@ -958,12 +884,10 @@ public DataValidatorBuilder matchesRegularExpression(final String expression, fi } if (this.value != null && !this.value.toString().matches(expression)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".does.not.match.regexp"); - final StringBuilder defaultEnglishMessage = new StringBuilder(Message); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".does.not.match.regexp"; - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value, expression); + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, Message, this.parameter, this.value, + expression); this.dataValidationErrors.add(error); } @@ -975,7 +899,7 @@ private DataValidatorBuilder validateStringFor(final String validInputs) { if (this.value == null && this.ignoreNullValue) { return this; } - final Iterable inputs = Splitter.onPattern(VALID_INPUT_SEPERATOR).split(validInputs); + final Iterable inputs = Splitter.onPattern(VALID_INPUT_SEPARATOR).split(validInputs); boolean validationErr = true; for (final String input : inputs) { if (input.equalsIgnoreCase(this.value.toString().trim())) { @@ -984,19 +908,17 @@ private DataValidatorBuilder validateStringFor(final String validInputs) { } } if (validationErr) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".value.should.true.or.false"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` value should true or false "); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".value.should.true.or.false"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` value should true or false "; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value); this.dataValidationErrors.add(error); } return this; } public DataValidatorBuilder validateForBooleanValue() { - return validateStringFor("TRUE" + VALID_INPUT_SEPERATOR + "FALSE"); + return validateStringFor("TRUE" + VALID_INPUT_SEPARATOR + "FALSE"); } public DataValidatorBuilder validatePhoneNumber() { @@ -1015,12 +937,11 @@ public DataValidatorBuilder validatePhoneNumber() { validationErr = false; } if (validationErr) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".format.is.invalid"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` is in invalid format, should contain '-','+','()' and numbers only."); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".format.is.invalid"; + String defaultEnglishMessage = "The parameter `" + this.parameter + + "` is in invalid format, should contain '-','+','()' and numbers only."; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value); this.dataValidationErrors.add(error); } return this; @@ -1028,12 +949,10 @@ public DataValidatorBuilder validatePhoneNumber() { public DataValidatorBuilder validateCronExpression() { if (this.value != null && !CronExpression.isValidExpression(this.value.toString().trim())) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".invalid"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` value is not a valid cron expression"); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, this.value); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".invalid"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` value is not a valid cron expression"; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + this.value); this.dataValidationErrors.add(error); } return this; @@ -1047,12 +966,10 @@ public DataValidatorBuilder validateDateAfter(final LocalDate date) { if (this.value != null && date != null) { final LocalDate dateVal = (LocalDate) this.value; if (DateUtils.isAfter(date, dateVal)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.less.than.date"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be greater than the provided date").append(date); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, dateVal, date); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.less.than.date"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be greater than the provided date" + date; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + dateVal, date); this.dataValidationErrors.add(error); } } @@ -1067,12 +984,10 @@ public DataValidatorBuilder validateDateBefore(final LocalDate date) { if (this.value != null && date != null) { final LocalDate dateVal = (LocalDate) this.value; if (DateUtils.isBefore(date, dateVal)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.greater.than.date"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be less than the provided date").append(date); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, dateVal, date); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.greater.than.date"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be less than the provided date" + date; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + dateVal, date); this.dataValidationErrors.add(error); } } @@ -1087,12 +1002,11 @@ public DataValidatorBuilder validateDateBeforeOrEqual(final LocalDate date) { if (this.value != null && date != null) { final LocalDate dateVal = (LocalDate) this.value; if (DateUtils.isAfter(dateVal, date)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.greater.than.date"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be less than or equal to the provided date: ").append(date); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, dateVal, date); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.greater.than.date"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be less than or equal to the provided date: " + + date; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + dateVal, date); this.dataValidationErrors.add(error); } } @@ -1107,12 +1021,10 @@ public DataValidatorBuilder validateDateForEqual(final LocalDate date) { if (this.value != null && date != null) { final LocalDate dateVal = (LocalDate) this.value; if (!DateUtils.isEqual(dateVal, date)) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".is.not.equal.to.date"); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter) - .append("` must be equal to the provided date").append(date); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, dateVal, date); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".is.not.equal.to.date"; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` must be equal to the provided date" + date; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + dateVal, date); this.dataValidationErrors.add(error); } } @@ -1122,12 +1034,11 @@ public DataValidatorBuilder validateDateForEqual(final LocalDate date) { public DataValidatorBuilder scaleNotGreaterThan(Integer scale) { final BigDecimal value = BigDecimal.valueOf(Double.parseDouble(this.value.toString())); if (value.scale() > scale.intValue()) { - final StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(this.resource).append(".") - .append(this.parameter).append(".scale.is.greater.than.").append(scale); - final StringBuilder defaultEnglishMessage = new StringBuilder("The parameter `").append(this.parameter).append("` value ") - .append(value).append(" decimal place must not be more than ").append(scale).append(" places"); - final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), - defaultEnglishMessage.toString(), this.parameter, value, scale); + String validationErrorCode = "validation.msg." + this.resource + "." + this.parameter + ".scale.is.greater.than." + scale; + String defaultEnglishMessage = "The parameter `" + this.parameter + "` value " + value + " decimal place must not be more than " + + scale + " places"; + final ApiParameterError error = ApiParameterError.parameterError(validationErrorCode, defaultEnglishMessage, this.parameter, + value, scale); this.dataValidationErrors.add(error); return this; } diff --git a/fineract-core/src/main/java/org/apache/fineract/organisation/workingdays/service/WorkingDaysUtil.java b/fineract-core/src/main/java/org/apache/fineract/organisation/workingdays/service/WorkingDaysUtil.java index fec8fc3204f..989e76d9eca 100644 --- a/fineract-core/src/main/java/org/apache/fineract/organisation/workingdays/service/WorkingDaysUtil.java +++ b/fineract-core/src/main/java/org/apache/fineract/organisation/workingdays/service/WorkingDaysUtil.java @@ -57,7 +57,7 @@ public static LocalDate getOffSetDateIfNonWorkingDay(final LocalDate date, final } public static boolean isWorkingDay(final WorkingDays workingDays, final LocalDate date) { - return CalendarUtils.isValidRedurringDate(workingDays.getRecurrence(), date, date); + return CalendarUtils.isValidRecurringDate(workingDays.getRecurrence(), date, date); } public static boolean isNonWorkingDay(final WorkingDays workingDays, final LocalDate date) { diff --git a/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java b/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java index 8426c3b971d..b8c1fd4638f 100644 --- a/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java +++ b/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/data/CalendarData.java @@ -391,7 +391,7 @@ public boolean isBetweenStartAndEndDate(final LocalDate compareDate) { public boolean isValidRecurringDate(final LocalDate compareDate, final Boolean isSkipMeetingOnFirstDay, final Integer numberOfDays) { if (isBetweenStartAndEndDate(compareDate)) { - return CalendarUtils.isValidRedurringDate(this.getRecurrence(), this.getStartDate(), compareDate, isSkipMeetingOnFirstDay, + return CalendarUtils.isValidRecurringDate(this.getRecurrence(), this.getStartDate(), compareDate, isSkipMeetingOnFirstDay, numberOfDays); } return false; diff --git a/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java b/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java index 54ed8ae669f..de4ac71d292 100644 --- a/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java +++ b/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/domain/Calendar.java @@ -558,14 +558,14 @@ private static String constructRecurrence(final CalendarFrequencyType frequencyT public boolean isValidRecurringDate(final LocalDate compareDate, Boolean isSkipRepaymentOnFirstMonth, Integer numberOfDays) { if (isBetweenStartAndEndDate(compareDate)) { - return CalendarUtils.isValidRedurringDate(getRecurrence(), getStartDateLocalDate(), compareDate, isSkipRepaymentOnFirstMonth, + return CalendarUtils.isValidRecurringDate(getRecurrence(), getStartDateLocalDate(), compareDate, isSkipRepaymentOnFirstMonth, numberOfDays); } // validate with history details. for (CalendarHistory history : history()) { if (history.isBetweenStartAndEndDate(compareDate)) { - return CalendarUtils.isValidRedurringDate(history.getRecurrence(), history.getStartDate(), compareDate, + return CalendarUtils.isValidRecurringDate(history.getRecurrence(), history.getStartDate(), compareDate, isSkipRepaymentOnFirstMonth, numberOfDays); } } diff --git a/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java b/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java index 1b4f568b534..f1eac5c7368 100644 --- a/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java +++ b/fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java @@ -355,7 +355,7 @@ public static String getRRuleReadable(final LocalDate startDate, final String re return humanReadable; } - public static boolean isValidRedurringDate(final String recurringRule, final LocalDate seedDate, final LocalDate date) { + public static boolean isValidRecurringDate(final String recurringRule, final LocalDate seedDate, final LocalDate date) { final Recur recur = CalendarUtils.getICalRecur(recurringRule); if (recur == null) { return false; @@ -365,7 +365,7 @@ public static boolean isValidRedurringDate(final String recurringRule, final Loc return isValidRecurringDate(recur, seedDate, date, isSkipRepaymentonFirstDayOfMonth, numberOfDays); } - public static boolean isValidRedurringDate(final String recurringRule, final LocalDate seedDate, final LocalDate date, + public static boolean isValidRecurringDate(final String recurringRule, final LocalDate seedDate, final LocalDate date, boolean isSkipRepaymentonFirstDayOfMonth, final Integer numberOfDays) { final Recur recur = CalendarUtils.getICalRecur(recurringRule); @@ -529,7 +529,7 @@ public static LocalDate getFirstRepaymentMeetingDate(final Calendar calendar, fi } LocalDate startDate = disbursementDate; final LocalDate seedDate = calendar.getStartDateLocalDate(); - if (isValidRedurringDate(calendar.getRecurrence(), seedDate, startDate, isSkipRepaymentOnFirstDayOfMonth, numberOfDays) + if (isValidRecurringDate(calendar.getRecurrence(), seedDate, startDate, isSkipRepaymentOnFirstDayOfMonth, numberOfDays) && !frequency.equals(Recur.Frequency.DAILY.name())) { startDate = startDate.plusDays(1); } @@ -728,10 +728,6 @@ public static LocalDate getNextScheduleDate(final Calendar calendar, final Local return null; } final LocalDate seedDate = calendar.getStartDateLocalDate(); - /** - * if (isValidRedurringDate(calendar.getRecurrence(), seedDate, date)) { date = date.plusDays(1); } - **/ - return getNextRecurringDate(recur, seedDate, startDate); } diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java index 2ab4058a170..940abca2e8e 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java @@ -1352,6 +1352,21 @@ public void loanStatus(String statusExpected) throws IOException { .isEqualTo(loanStatusExpectedValue); } + @Then("Loan closedon_date is {}") + public void loanClosedonDate(String date) throws IOException { + Response loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); + long loanId = loanCreateResponse.body().getLoanId(); + + Response loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "", "", "").execute(); + ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse); + testContext().set(TestContextKey.LOAN_RESPONSE, loanDetailsResponse); + if (date == null || "null".equals(date)) { + assertThat(loanDetailsResponse.body().getTimeline().getClosedOnDate()).isNull(); + } else { + assertThat(loanDetailsResponse.body().getTimeline().getClosedOnDate()).isEqualTo(date); + } + } + @Then("Admin can successfully set Fraud flag to the loan") public void setFraud() throws IOException { Response loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE); diff --git a/fineract-e2e-tests-core/src/test/resources/fineract-test-application.properties b/fineract-e2e-tests-core/src/test/resources/fineract-test-application.properties index d9d724678f9..feccf95ad56 100644 --- a/fineract-e2e-tests-core/src/test/resources/fineract-test-application.properties +++ b/fineract-e2e-tests-core/src/test/resources/fineract-test-application.properties @@ -17,7 +17,7 @@ # under the License. # -fineract-test.api.base-url=${BASE_URL:https://localhost:8443} +fineract-test.api.base-url=${BASE_URL:http://localhost:8443} fineract-test.api.username=${TEST_USERNAME:mifos} fineract-test.api.password=${TEST_PASSWORD:password} fineract-test.api.tenant-id=${TEST_TENANT_ID:default} diff --git a/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature b/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature index 60555c9b0ae..661090e3958 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/Loan.feature @@ -1244,6 +1244,20 @@ Feature: Loan | actualMaturityDate | expectedMaturityDate | | 01 July 2023 | 01 July 2023 | + Scenario: Verify that closed date is updated on repayment reversal + When Admin sets the business date to "01 June 2023" + When Admin creates a client with random data + When Admin creates a new default Loan with date: "01 June 2023" + And Admin successfully approves the loan on "01 June 2023" with "1000" amount and expected disbursement date on "01 June 2023" + When Admin successfully disburse the loan on "01 June 2023" with "1000" EUR transaction amount + Then Loan status will be "ACTIVE" + When Admin sets the business date to "20 June 2023" + And Customer makes "AUTOPAY" repayment on "20 June 2023" with 1000 EUR transaction amount + Then Loan status will be "CLOSED_OBLIGATIONS_MET" + When Admin sets the business date to "20 June 2023" + When Customer undo "1"th "Repayment" transaction made on "20 June 2023" + Then Loan status will be "ACTIVE" + Then Loan closedon_date is null Scenario: As an admin I would like to delete a loan using external id When Admin sets the business date to the actual date diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/DefaultLoanLifecycleStateMachine.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/DefaultLoanLifecycleStateMachine.java index 52b84de3572..6bc5d61bb13 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/DefaultLoanLifecycleStateMachine.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/DefaultLoanLifecycleStateMachine.java @@ -49,6 +49,17 @@ public void transition(final LoanEvent loanEvent, final Loan loan) { // in case of Loan creation, a LoanCreatedBusinessEvent is also raised, no need to send a status change businessEventNotifierService.notifyPostBusinessEvent(new LoanStatusChangedBusinessEvent(loan)); } + + // set mandatory field states based on new status after the transition + switch (newStatus) { + case ACTIVE -> { + if (loan.getClosedOnDate() != null) { + loan.setClosedOnDate(null); + } + } + default -> { + } + } } } @@ -132,6 +143,7 @@ private LoanStatus getNextStatus(LoanEvent loanEvent, Loan loan) { if (anyOfAllowedWhenComingFrom(from, LoanStatus.CLOSED_OBLIGATIONS_MET, LoanStatus.CLOSED_WRITTEN_OFF, LoanStatus.CLOSED_RESCHEDULE_OUTSTANDING_AMOUNT)) { newState = activeTransition(); + loan.setClosedOnDate(null); } break; case LOAN_INITIATE_TRANSFER: diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java index ed0813cc50a..a9a08f33524 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java @@ -797,7 +797,7 @@ public BigDecimal calculatePeriodsBetweenDates(final LocalDate startDate, final this.repaymentPeriodFrequencyType); } else { LocalDate expectedStartDate = startDate; - if (!CalendarUtils.isValidRedurringDate(loanCalendar.getRecurrence(), + if (!CalendarUtils.isValidRecurringDate(loanCalendar.getRecurrence(), loanCalendar.getStartDateLocalDate().minusMonths(getRepaymentEvery()), startDate)) { expectedStartDate = CalendarUtils.getNewRepaymentMeetingDate(loanCalendar.getRecurrence(), startDate.minusMonths(getRepaymentEvery()), startDate.minusMonths(getRepaymentEvery()), getRepaymentEvery(), diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java index 2bca76f2d1b..6e8b22d9c3b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/service/LoanScheduleAssembler.java @@ -616,7 +616,7 @@ private List fetchDisbursementData(final JsonObject command) { private void validateRepaymentsStartDateWithMeetingDates(final LocalDate repaymentsStartingFromDate, final Calendar calendar, boolean isSkipRepaymentOnFirstDayOfMonth, final Integer numberOfDays) { - if (repaymentsStartingFromDate != null && !CalendarUtils.isValidRedurringDate(calendar.getRecurrence(), + if (repaymentsStartingFromDate != null && !CalendarUtils.isValidRecurringDate(calendar.getRecurrence(), calendar.getStartDateLocalDate(), repaymentsStartingFromDate, isSkipRepaymentOnFirstDayOfMonth, numberOfDays)) { final String errorMessage = "First repayment date '" + repaymentsStartingFromDate + "' do not fall on a meeting date"; throw new LoanApplicationDateException("first.repayment.date.do.not.match.meeting.date", errorMessage, diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationValidator.java index 78cb2c94152..5542f8b366d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationValidator.java @@ -1784,7 +1784,6 @@ private void validateTransactionProcessingStrategy(final String transactionProce } public void checkForProductMixRestrictions(final JsonElement element) { - final List activeLoansLoanProductIds; final Long productId = this.fromApiJsonHelper.extractLongNamed(LoanApiConstants.productIdParameterName, element); final Long groupId = this.fromApiJsonHelper.extractLongNamed(LoanApiConstants.groupIdParameterName, element); @@ -1869,17 +1868,17 @@ private void validateSubmittedOnDate(final JsonElement element, LocalDate origin Group group = groupRepository.findOneWithNotFoundDetection(groupId); if (group != null && group.isActivatedAfter(submittedOnDate)) { - final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date."; + final String errorMessage = "The date on which a loan is submitted cannot be earlier than group's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date", errorMessage, submittedOnDate, group.getActivationDate()); } + } - if (DateUtils.isAfter(submittedOnDate, expectedDisbursementDate)) { - final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " - + expectedDisbursementDate; - throw new InvalidLoanStateTransitionException("submittal", "cannot.be.after.expected.disbursement.date", errorMessage, - submittedOnDate, expectedDisbursementDate); - } + if (DateUtils.isAfter(submittedOnDate, expectedDisbursementDate)) { + final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " + + expectedDisbursementDate; + throw new InvalidLoanStateTransitionException("submittal", "cannot.be.after.expected.disbursement.date", errorMessage, + submittedOnDate, expectedDisbursementDate); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java index de1f979221d..41ceb75902a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanTransactionValidator.java @@ -442,7 +442,7 @@ public void validateRepaymentDateWithMeetingDate(final LocalDate repaymentDate, final Calendar calendar = calendarInstance.getCalendar(); if (calendar != null && repaymentDate != null) { // Disbursement date should fall on a meeting date - if (!CalendarUtils.isValidRedurringDate(calendar.getRecurrence(), calendar.getStartDateLocalDate(), repaymentDate)) { + if (!CalendarUtils.isValidRecurringDate(calendar.getRecurrence(), calendar.getStartDateLocalDate(), repaymentDate)) { final String errorMessage = "Transaction date '" + repaymentDate.toString() + "' does not fall on a meeting date."; throw new NotValidRecurringDateException("loan.transaction.date", errorMessage, repaymentDate.toString(), calendar.getTitle()); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java index a3840007476..30ae80d3dbe 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java @@ -1942,11 +1942,8 @@ private void validateChargeToIncomeAccountMappings(final DataValidatorBuilder ba public void validateMinMaxConstraints(final JsonElement element, final DataValidatorBuilder baseDataValidator, final LoanProduct loanProduct) { - validatePrincipalMinMaxConstraint(element, loanProduct, baseDataValidator); - validateNumberOfRepaymentsMinMaxConstraint(element, loanProduct, baseDataValidator); - validateNominalInterestRatePerPeriodMinMaxConstraint(element, loanProduct, baseDataValidator); } @@ -2029,7 +2026,6 @@ public void validateMinMaxConstraints(final JsonElement element, final DataValid private void validatePrincipalMinMaxConstraint(final JsonElement element, final LoanProduct loanProduct, final DataValidatorBuilder baseDataValidator) { - boolean principalUpdated = false; boolean minPrincipalUpdated = false; boolean maxPrincipalUpdated = false; @@ -2555,11 +2551,7 @@ public void validateRepaymentPeriodWithGraceSettings(final Integer numberOfRepay } } - private Integer defaultToZeroIfNull(final Integer value) { - Integer result = value; - if (value == null) { - result = 0; - } - return result; + private Integer defaultToZeroIfNull(Integer value) { + return value != null ? value : 0; } }