final String variationParameterName, final String defaultParameterName, final String minParameterName,
final String maxParameterName, final String valueUsageConditionParamName, final String cycleNumbersParamName) {
final JsonObject topLevelJsonElement = element.getAsJsonObject();
final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
Integer lastCycleNumber = 0;
LoanProductValueConditionType lastConditionType = LoanProductValueConditionType.EQUAL;
if (this.fromApiJsonHelper.parameterExists(variationParameterName, element)) {
final JsonArray variationArray = this.fromApiJsonHelper.extractJsonArrayNamed(variationParameterName, element);
if (variationArray != null && variationArray.size() > 0) {
int i = 0;
do {
final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
BigDecimal defaultValue = this.fromApiJsonHelper.extractBigDecimalNamed(LoanProductConstants.defaultValueParameterName,
jsonObject, locale);
BigDecimal minValue = this.fromApiJsonHelper.extractBigDecimalNamed(LoanProductConstants.minValueParameterName,
jsonObject, locale);
BigDecimal maxValue = this.fromApiJsonHelper.extractBigDecimalNamed(LoanProductConstants.maxValueParameterName,
jsonObject, locale);
Integer cycleNumber = this.fromApiJsonHelper.extractIntegerNamed(LoanProductConstants.borrowerCycleNumberParamName,
jsonObject, locale);
Integer valueUsageCondition = this.fromApiJsonHelper.extractIntegerNamed(
LoanProductConstants.valueConditionTypeParamName, jsonObject, locale);
baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue).notBlank();
if (minValue != null) {
baseDataValidator.reset().parameter(minParameterName).value(minValue).notGreaterThanMax(maxValue);
}
if (maxValue != null) {
baseDataValidator.reset().parameter(maxParameterName).value(maxValue).notLessThanMin(minValue);
}
if ((minValue != null && minValue.compareTo(BigDecimal.ZERO) == 1)
&& (maxValue != null && maxValue.compareTo(BigDecimal.ZERO) == 1)) {
baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue)
.inMinAndMaxAmountRange(minValue, maxValue);
} else {
if (minValue != null && minValue.compareTo(BigDecimal.ZERO) == 1) {
baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue).notLessThanMin(minValue);
} else if (maxValue != null && maxValue.compareTo(BigDecimal.ZERO) == 1) {
baseDataValidator.reset().parameter(defaultParameterName).value(defaultValue).notGreaterThanMax(maxValue);
}
}
LoanProductValueConditionType conditionType = LoanProductValueConditionType.INVALID;
if (valueUsageCondition != null) {
conditionType = LoanProductValueConditionType.fromInt(valueUsageCondition);
}
baseDataValidator
.reset()
.parameter(valueUsageConditionParamName)
.value(valueUsageCondition)
.notNull()
.inMinMaxRange(LoanProductValueConditionType.EQUAL.getValue(),
LoanProductValueConditionType.GRETERTHAN.getValue());
if (lastConditionType.equals(LoanProductValueConditionType.EQUAL)
&& conditionType.equals(LoanProductValueConditionType.GRETERTHAN)) {
if (lastCycleNumber == 0) {
baseDataValidator.reset().parameter(cycleNumbersParamName)
.failWithCode(LoanProductConstants.VALUE_CONDITION_START_WITH_ERROR);
lastCycleNumber = 1;
}