Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private InterestRateChart(InterestRateChartFields chartFields, Set<InterestRateC
this.throwExceptionIfValidationWarningsExist(dataValidationErrors);

this.addChartSlabs(interestRateChartSlabs);

}

public void validateChartSlabs(DataValidatorBuilder baseDataValidator) {
Expand All @@ -102,20 +101,25 @@ public void validateChartSlabs(DataValidatorBuilder baseDataValidator) {

for (int i = 0; i < chartSlabsList.size(); i++) {
InterestRateChartSlab iSlabs = chartSlabsList.get(i);
String slabContext = "(Slab " + (i + 1) + ") ";
if (!iSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)) {
if (isPrimaryGroupingByAmount) {
baseDataValidator.parameter(InterestRateChartSlabApiConstants.amountRangeFromParamName).failWithCode("cannot.be.blank");
baseDataValidator.parameter(InterestRateChartSlabApiConstants.amountRangeFromParamName).failWithCode("cannot.be.blank",
slabContext + "Amount range start is required.");
} else {
baseDataValidator.parameter(InterestRateChartSlabApiConstants.fromPeriodParamName).failWithCode("cannot.be.blank");
baseDataValidator.parameter(InterestRateChartSlabApiConstants.fromPeriodParamName).failWithCode("cannot.be.blank",
slabContext + "Period start is required.");
}

} else if (i > 0) {
if (isPeriodChart ^ iSlabs.slabFields().fromPeriod() != null) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.incomplete");
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.incomplete",
slabContext + "Period range is incomplete. Please check the start and end periods.");
isPeriodChart = isPeriodChart || iSlabs.slabFields().fromPeriod() != null;
}
if (isAmountChart ^ iSlabs.slabFields().getAmountRangeFrom() != null) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.incomplete");
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.incomplete",
slabContext + "Amount range is incomplete. Please check the start and end amounts.");
isAmountChart = isAmountChart || iSlabs.slabFields().getAmountRangeFrom() != null;
}
}
Expand All @@ -124,26 +128,30 @@ public void validateChartSlabs(DataValidatorBuilder baseDataValidator) {
tmpPeriodType = iSlabs.slabFields().periodType();
if (iSlabs.slabFields().isNotProperChartStart()) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.start.incorrect",
iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().getAmountRangeFrom());
slabContext + "The first slab must start from the minimum period/amount.", iSlabs.slabFields().fromPeriod(),
iSlabs.slabFields().getAmountRangeFrom());
}
isAmountChart = isAmountChart || iSlabs.slabFields().getAmountRangeFrom() != null;
isPeriodChart = isPeriodChart || iSlabs.slabFields().fromPeriod() != null;
} else if (iSlabs.slabFields().periodType() != null && !iSlabs.slabFields().periodType().equals(tmpPeriodType)) {
baseDataValidator.parameter(periodTypeParamName).value(iSlabs.slabFields().periodType())
.failWithCode("period.type.is.not.same", tmpPeriodType);
baseDataValidator.parameter(periodTypeParamName).value(iSlabs.slabFields().periodType()).failWithCode(
"period.type.is.not.same", slabContext + "Period type must be the same for all slabs.", tmpPeriodType);
}
if (i + 1 < chartSlabsList.size()) {
InterestRateChartSlab nextSlabs = chartSlabsList.get(i + 1);
String nextSlabContext = "(Slab " + (i + 2) + ") ";
if (iSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)
&& nextSlabs.slabFields().isValidChart(isPrimaryGroupingByAmount)) {
if (iSlabs.slabFields().isRateChartOverlapping(nextSlabs.slabFields(), isPrimaryGroupingByAmount)) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.overlapping",
slabContext + " and " + nextSlabContext + "There is an overlap between these slabs. Please ensure slabs do not overlap.",
iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().toPeriod(), nextSlabs.slabFields().fromPeriod(),
nextSlabs.slabFields().toPeriod(), iSlabs.slabFields().getAmountRangeFrom(),
iSlabs.slabFields().getAmountRangeTo(), nextSlabs.slabFields().getAmountRangeFrom(),
nextSlabs.slabFields().getAmountRangeTo());
} else if (iSlabs.slabFields().isRateChartHasGap(nextSlabs.slabFields(), isPrimaryGroupingByAmount)) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.has.gap",
slabContext + " and " + nextSlabContext + "There is a gap between these slabs. Please ensure slabs are continuous.",
iSlabs.slabFields().fromPeriod(), iSlabs.slabFields().toPeriod(), nextSlabs.slabFields().fromPeriod(),
nextSlabs.slabFields().toPeriod(), iSlabs.slabFields().getAmountRangeFrom(),
iSlabs.slabFields().getAmountRangeTo(), nextSlabs.slabFields().getAmountRangeFrom(),
Expand All @@ -153,28 +161,29 @@ public void validateChartSlabs(DataValidatorBuilder baseDataValidator) {
if (!iSlabs.slabFields().isAmountSame(nextSlabs.slabFields())) {
if (InterestRateChartSlabFields.isNotProperPeriodStart(nextSlabs.slabFields())) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.start.incorrect",
nextSlabs.slabFields().toPeriod());
nextSlabContext + "The start period of this slab is incorrect.", nextSlabs.slabFields().toPeriod());
}
if (iSlabs.slabFields().toPeriod() != null) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.period.range.end.incorrect",
iSlabs.slabFields().toPeriod());
slabContext + "The end period of this slab is incorrect.", iSlabs.slabFields().toPeriod());
}

}
} else if (!iSlabs.slabFields().isPeriodsSame(nextSlabs.slabFields())) {
if (InterestRateChartSlabFields.isNotProperAmountStart(nextSlabs.slabFields())) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.start.incorrect",
nextSlabs.slabFields().getAmountRangeFrom());
nextSlabContext + "The start amount of this slab is incorrect.", nextSlabs.slabFields().getAmountRangeFrom());
}
if (iSlabs.slabFields().getAmountRangeTo() != null) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.amount.range.end.incorrect",
iSlabs.slabFields().getAmountRangeTo());
slabContext + "The end amount of this slab is incorrect.", iSlabs.slabFields().getAmountRangeTo());
}

}
}
} else if (iSlabs.slabFields().isNotProperPriodEnd()) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.end.incorrect", iSlabs.slabFields().toPeriod(),
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("chart.slabs.range.end.incorrect",
slabContext + "The last slab must end at the maximum period/amount.", iSlabs.slabFields().toPeriod(),
iSlabs.slabFields().getAmountRangeTo());
}
}
Expand Down Expand Up @@ -208,7 +217,6 @@ public void update(JsonCommand command, final Map<String, Object> actualChanges)
this.update(command, actualChanges, baseDataValidator, null, null);

throwExceptionIfValidationWarningsExist(dataValidationErrors);

}

public void update(JsonCommand command, final Map<String, Object> actualChanges, final DataValidatorBuilder baseDataValidator,
Expand Down
Loading