fixing validation for loanproduct data validation
This commit is contained in:
+25
@@ -98,6 +98,31 @@ public class FromJsonHelper {
|
|||||||
if (!unsupportedParameterList.isEmpty()) { throw new UnsupportedParameterException(unsupportedParameterList); }
|
if (!unsupportedParameterList.isEmpty()) { throw new UnsupportedParameterException(unsupportedParameterList); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parentPropertyName
|
||||||
|
* The full json path to this property,the value is appended to
|
||||||
|
* the parameter name while generating an error message <br/>
|
||||||
|
* Ex: property "name" in Object "person" would be named as
|
||||||
|
* "person.name"
|
||||||
|
* @param object
|
||||||
|
* @param supportedParams
|
||||||
|
*/
|
||||||
|
public void checkForUnsupportedNestedParameters(final String parentPropertyName, final JsonObject object,
|
||||||
|
final Set<String> supportedParams) {
|
||||||
|
try {
|
||||||
|
checkForUnsupportedParameters(object, supportedParams);
|
||||||
|
} catch (UnsupportedParameterException exception) {
|
||||||
|
List<String> unsupportedParameters = exception.getUnsupportedParameters();
|
||||||
|
List<String> updatedUnsupportedParameters = new ArrayList<>();
|
||||||
|
for (String unsupportedParameter : unsupportedParameters) {
|
||||||
|
String updatedUnsupportedParameter = parentPropertyName + "." + unsupportedParameter;
|
||||||
|
updatedUnsupportedParameters.add(updatedUnsupportedParameter);
|
||||||
|
}
|
||||||
|
throw new UnsupportedParameterException(updatedUnsupportedParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public JsonElement parse(final String json) {
|
public JsonElement parse(final String json) {
|
||||||
|
|
||||||
JsonElement parsedElement = null;
|
JsonElement parsedElement = null;
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ public class LoanProductConfigurableAttributes extends AbstractPersistable<Long>
|
|||||||
|
|
||||||
public static String[] supportedloanConfigurableAttributes = { "amortizationType", "interestType", "transactionProcessingStrategyId",
|
public static String[] supportedloanConfigurableAttributes = { "amortizationType", "interestType", "transactionProcessingStrategyId",
|
||||||
"interestCalculationPeriodType", "inArrearsTolerance", "repaymentEvery", "graceOnPrincipalAndInterestPayment",
|
"interestCalculationPeriodType", "inArrearsTolerance", "repaymentEvery", "graceOnPrincipalAndInterestPayment",
|
||||||
"graceOnArrearsAging" };
|
"graceOnArrearsAgeing" };
|
||||||
|
|
||||||
public static LoanProductConfigurableAttributes createFrom(JsonCommand command) {
|
public static LoanProductConfigurableAttributes createFrom(JsonCommand command) {
|
||||||
|
|
||||||
|
|||||||
+14
-12
@@ -9,6 +9,7 @@ import java.lang.reflect.Type;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -28,11 +29,11 @@ import org.mifosplatform.portfolio.loanproduct.LoanProductConstants;
|
|||||||
import org.mifosplatform.portfolio.loanproduct.domain.InterestMethod;
|
import org.mifosplatform.portfolio.loanproduct.domain.InterestMethod;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanPreClosureInterestCalculationStrategy;
|
import org.mifosplatform.portfolio.loanproduct.domain.LoanPreClosureInterestCalculationStrategy;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProduct;
|
import org.mifosplatform.portfolio.loanproduct.domain.LoanProduct;
|
||||||
|
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductConfigurableAttributes;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductValueConditionType;
|
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductValueConditionType;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.RecalculationFrequencyType;
|
import org.mifosplatform.portfolio.loanproduct.domain.RecalculationFrequencyType;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.mifosplatform.portfolio.loanproduct.domain.LoanProductConfigurableAttributes;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -442,7 +443,7 @@ public final class LoanProductDataValidator {
|
|||||||
|
|
||||||
validateMultiDisburseLoanData(baseDataValidator, element);
|
validateMultiDisburseLoanData(baseDataValidator, element);
|
||||||
|
|
||||||
// validateLoanConfigurableAttributes(baseDataValidator,element);
|
validateLoanConfigurableAttributes(baseDataValidator, element);
|
||||||
|
|
||||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
}
|
}
|
||||||
@@ -453,22 +454,23 @@ public final class LoanProductDataValidator {
|
|||||||
|
|
||||||
final JsonObject object = element.getAsJsonObject().getAsJsonObject(LoanProductConstants.allowAttributeOverridesParamName);
|
final JsonObject object = element.getAsJsonObject().getAsJsonObject(LoanProductConstants.allowAttributeOverridesParamName);
|
||||||
|
|
||||||
Integer length = LoanProductConfigurableAttributes.supportedloanConfigurableAttributes.length;
|
// Validate that parameter names are allowed
|
||||||
|
Set<String> supportedConfigurableAttributes = new HashSet<>();
|
||||||
|
Collections.addAll(supportedConfigurableAttributes, LoanProductConfigurableAttributes.supportedloanConfigurableAttributes);
|
||||||
|
this.fromApiJsonHelper.checkForUnsupportedNestedParameters(LoanProductConstants.allowAttributeOverridesParamName, object,
|
||||||
|
supportedConfigurableAttributes);
|
||||||
|
|
||||||
Boolean bool[] = new Boolean[length];
|
Integer length = LoanProductConfigurableAttributes.supportedloanConfigurableAttributes.length;
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
/* Validate the attribute names */
|
/* Validate the attribute names */
|
||||||
if (!this.fromApiJsonHelper.parameterExists(LoanProductConfigurableAttributes.supportedloanConfigurableAttributes[i],
|
if (this.fromApiJsonHelper
|
||||||
object)) {
|
.parameterExists(LoanProductConfigurableAttributes.supportedloanConfigurableAttributes[i], object)) {
|
||||||
baseDataValidator.reset().parameter(LoanProductConstants.allowAttributeOverridesParamName)
|
Boolean loanConfigurationAttributeValue = this.fromApiJsonHelper.extractBooleanNamed(
|
||||||
.failWithCode("invalid.loan.configuration.attribute.passed");
|
|
||||||
} else {
|
|
||||||
bool[i] = this.fromApiJsonHelper.extractBooleanNamed(
|
|
||||||
LoanProductConfigurableAttributes.supportedloanConfigurableAttributes[i], object);
|
LoanProductConfigurableAttributes.supportedloanConfigurableAttributes[i], object);
|
||||||
/* Validate the boolean value */
|
/* Validate the boolean value */
|
||||||
baseDataValidator.reset().parameter(LoanProductConstants.allowAttributeOverridesParamName).value(bool[i])
|
baseDataValidator.reset().parameter(LoanProductConstants.allowAttributeOverridesParamName)
|
||||||
.ignoreIfNull().validateForBooleanValue();
|
.value(loanConfigurationAttributeValue).notNull().validateForBooleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user