Aman-Mittal commented on code in PR #5895:
URL: https://github.com/apache/fineract/pull/5895#discussion_r3328691750
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/account/data/StandingInstructionDataValidator.java:
##########
@@ -97,113 +109,129 @@ public void validateForCreate(final JsonCommand command)
{
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new
DataValidatorBuilder(dataValidationErrors)
-
.resource(StandingInstructionApiConstants.STANDING_INSTRUCTION_RESOURCE_NAME);
+ .resource(STANDING_INSTRUCTION_RESOURCE_NAME);
this.accountTransfersDetailDataValidator.validate(command,
baseDataValidator);
final JsonElement element = command.parsedJson();
- final Integer status =
this.fromApiJsonHelper.extractIntegerNamed(StandingInstructionApiConstants.statusParamName,
element,
- Locale.getDefault());
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.statusParamName).value(status).notNull().inMinMaxRange(1,
2);
+ final Integer transferType =
this.fromApiJsonHelper.extractIntegerNamed(transferTypeParamName, element,
Locale.getDefault());
+
baseDataValidator.reset().parameter(transferTypeParamName).value(transferType).notNull().inMinMaxRange(1,
3);
- final LocalDate validFrom =
this.fromApiJsonHelper.extractLocalDateNamed(StandingInstructionApiConstants.validFromParamName,
- element);
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.validFromParamName).value(validFrom).notNull();
+ final String name =
this.fromApiJsonHelper.extractStringNamed(nameParamName, element);
+
baseDataValidator.reset().parameter(nameParamName).value(name).notBlank();
- final LocalDate validTill =
this.fromApiJsonHelper.extractLocalDateNamed(StandingInstructionApiConstants.validTillParamName,
- element);
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.validTillParamName).value(validTill)
- .validateDateAfter(validFrom);
+ final Integer priority =
this.fromApiJsonHelper.extractIntegerNamed(priorityParamName, element,
Locale.getDefault());
+
baseDataValidator.reset().parameter(priorityParamName).value(priority).notNull().inMinMaxRange(1,
4);
- final BigDecimal transferAmount = this.fromApiJsonHelper
-
.extractBigDecimalWithLocaleNamed(StandingInstructionApiConstants.amountParamName,
element);
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.amountParamName).value(transferAmount).positiveAmount();
+ final Integer instructionType =
this.fromApiJsonHelper.extractIntegerNamed(instructionTypeParamName, element,
Locale.getDefault());
+
baseDataValidator.reset().parameter(instructionTypeParamName).value(instructionType).notNull().inMinMaxRange(1,
2);
- final Integer transferType =
this.fromApiJsonHelper.extractIntegerNamed(transferTypeParamName, element,
Locale.getDefault());
-
baseDataValidator.reset().parameter(transferTypeParamName).value(transferType).notNull().inMinMaxRange(1,
3);
+ final Integer status =
this.fromApiJsonHelper.extractIntegerNamed(statusParamName, element,
Locale.getDefault());
+
baseDataValidator.reset().parameter(statusParamName).value(status).notNull().inMinMaxRange(1,
2);
+
+ final LocalDate validFrom =
this.fromApiJsonHelper.extractLocalDateNamed(validFromParamName, element);
+
baseDataValidator.reset().parameter(validFromParamName).value(validFrom).notNull();
+
+ final LocalDate validTill =
this.fromApiJsonHelper.extractLocalDateNamed(validTillParamName, element);
+
baseDataValidator.reset().parameter(validTillParamName).value(validTill).validateDateAfter(validFrom);
+
+ final Integer recurrenceType =
this.fromApiJsonHelper.extractIntegerNamed(recurrenceTypeParamName, element,
Locale.getDefault());
+
baseDataValidator.reset().parameter(recurrenceTypeParamName).value(recurrenceType).notNull().inMinMaxRange(1,
2);
- final Integer priority =
this.fromApiJsonHelper.extractIntegerNamed(StandingInstructionApiConstants.priorityParamName,
element,
+ final Integer recurrenceFrequency =
this.fromApiJsonHelper.extractIntegerNamed(recurrenceFrequencyParamName,
element,
+ Locale.getDefault());
+ final Integer recurrenceInterval =
this.fromApiJsonHelper.extractIntegerNamed(recurrenceIntervalParamName, element,
Locale.getDefault());
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.priorityParamName).value(priority).notNull().inMinMaxRange(1,
- 4);
-
- final Integer standingInstructionType = this.fromApiJsonHelper
-
.extractIntegerNamed(StandingInstructionApiConstants.instructionTypeParamName,
element, Locale.getDefault());
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.instructionTypeParamName).value(standingInstructionType)
- .notNull().inMinMaxRange(1, 2);
-
- final Integer recurrenceType =
this.fromApiJsonHelper.extractIntegerNamed(StandingInstructionApiConstants.recurrenceTypeParamName,
- element, Locale.getDefault());
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.recurrenceTypeParamName).value(recurrenceType).notNull()
- .inMinMaxRange(1, 2);
- boolean isPeriodic = false;
- if (recurrenceType != null) {
- isPeriodic =
AccountTransferRecurrenceType.fromInt(recurrenceType).isPeriodicRecurrence();
- }
- final Integer recurrenceFrequency = this.fromApiJsonHelper
-
.extractIntegerNamed(StandingInstructionApiConstants.recurrenceFrequencyParamName,
element, Locale.getDefault());
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.recurrenceFrequencyParamName).value(recurrenceFrequency)
- .inMinMaxRange(0, 3);
-
- if (recurrenceFrequency != null) {
- PeriodFrequencyType frequencyType =
PeriodFrequencyType.fromInt(recurrenceFrequency);
- if (frequencyType.isMonthly() || frequencyType.isYearly()) {
- final MonthDay monthDay = this.fromApiJsonHelper
-
.extractMonthDayNamed(StandingInstructionApiConstants.recurrenceOnMonthDayParamName,
element);
-
baseDataValidator.reset().parameter(StandingInstructionApiConstants.recurrenceOnMonthDayParamName).value(monthDay)
- .notNull();
+ if (isPeriodicRecurrence(recurrenceType)) {
+
baseDataValidator.reset().parameter(recurrenceFrequencyParamName).value(recurrenceFrequency).notNull().inMinMaxRange(0,
3);
+
baseDataValidator.reset().parameter(recurrenceIntervalParamName).value(recurrenceInterval).notNull().integerGreaterThanZero();
+
+ if (recurrenceFrequency != null && recurrenceInterval != null) {
Review Comment:
Thats a lot of nested Ifs
We can simplify more
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]