Merge pull request #1508 from rajuan/MIFOSX-2259
MIFOSX-2259 : Added parameter validation
This commit is contained in:
+4
@@ -44,6 +44,10 @@ public enum ChargeCalculationType {
|
|||||||
return new Integer[] { ChargeCalculationType.FLAT.getValue() };
|
return new Integer[] { ChargeCalculationType.FLAT.getValue() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object[] validValuesForTrancheDisbursement(){
|
||||||
|
return new Integer[] { ChargeCalculationType.FLAT.getValue(), ChargeCalculationType.PERCENT_OF_DISBURSEMENT_AMOUNT.getValue()};
|
||||||
|
}
|
||||||
|
|
||||||
public static ChargeCalculationType fromInt(final Integer chargeCalculation) {
|
public static ChargeCalculationType fromInt(final Integer chargeCalculation) {
|
||||||
ChargeCalculationType chargeCalculationType = ChargeCalculationType.INVALID;
|
ChargeCalculationType chargeCalculationType = ChargeCalculationType.INVALID;
|
||||||
switch (chargeCalculation) {
|
switch (chargeCalculation) {
|
||||||
|
|||||||
+23
-1
@@ -105,6 +105,10 @@ public final class ChargeDefinitionCommandFromApiJsonDeserializer {
|
|||||||
.isOneOfTheseValues(ChargeCalculationType.validValuesForLoan());
|
.isOneOfTheseValues(ChargeCalculationType.validValuesForLoan());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(chargeTimeType != null && chargeCalculationType != null){
|
||||||
|
performChargeTimeNCalculationTypeValidation(baseDataValidator, chargeTimeType, chargeCalculationType);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (appliesTo.isSavingsCharge()) {
|
} else if (appliesTo.isSavingsCharge()) {
|
||||||
// savings applicable validation
|
// savings applicable validation
|
||||||
final Integer chargeTimeType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed("chargeTimeType", element);
|
final Integer chargeTimeType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed("chargeTimeType", element);
|
||||||
@@ -302,7 +306,25 @@ public final class ChargeDefinitionCommandFromApiJsonDeserializer {
|
|||||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
public void validateChargeTimeNCalculationType(Integer chargeTimeType, Integer ChargeCalculationType) {
|
||||||
|
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||||
|
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charge");
|
||||||
|
performChargeTimeNCalculationTypeValidation(baseDataValidator, chargeTimeType, ChargeCalculationType);
|
||||||
|
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void performChargeTimeNCalculationTypeValidation(DataValidatorBuilder baseDataValidator,
|
||||||
|
final Integer chargeTimeType, final Integer chargeCalculationType){
|
||||||
|
if (chargeTimeType == ChargeTimeType.TRANCHE_DISBURSEMENT.getValue()){
|
||||||
|
baseDataValidator.reset().parameter("chargeCalculationType").value(chargeCalculationType)
|
||||||
|
.isOneOfTheseValues(ChargeCalculationType.validValuesForTrancheDisbursement());
|
||||||
|
} else {
|
||||||
|
baseDataValidator.reset().parameter("chargeCalculationType").value(chargeCalculationType)
|
||||||
|
.isNotOneOfTheseValues(ChargeCalculationType.PERCENT_OF_DISBURSEMENT_AMOUNT.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
@@ -112,6 +112,9 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
|
|||||||
|
|
||||||
final Map<String, Object> changes = chargeForUpdate.update(command);
|
final Map<String, Object> changes = chargeForUpdate.update(command);
|
||||||
|
|
||||||
|
this.fromApiJsonDeserializer.validateChargeTimeNCalculationType(chargeForUpdate.getChargeTimeType(),
|
||||||
|
chargeForUpdate.getChargeCalculation());
|
||||||
|
|
||||||
// MIFOSX-900: Check if the Charge has been active before and now is
|
// MIFOSX-900: Check if the Charge has been active before and now is
|
||||||
// deactivated:
|
// deactivated:
|
||||||
if (changes.containsKey("active")) {
|
if (changes.containsKey("active")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user