MIFOSX-2259 : Added parameter validation
This commit is contained in:
+4
@@ -43,6 +43,10 @@ public enum ChargeCalculationType {
|
||||
public static Object[] validValuesForClients() {
|
||||
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) {
|
||||
ChargeCalculationType chargeCalculationType = ChargeCalculationType.INVALID;
|
||||
|
||||
+23
-1
@@ -105,6 +105,10 @@ public final class ChargeDefinitionCommandFromApiJsonDeserializer {
|
||||
.isOneOfTheseValues(ChargeCalculationType.validValuesForLoan());
|
||||
}
|
||||
|
||||
if(chargeTimeType != null && chargeCalculationType != null){
|
||||
performChargeTimeNCalculationTypeValidation(baseDataValidator, chargeTimeType, chargeCalculationType);
|
||||
}
|
||||
|
||||
} else if (appliesTo.isSavingsCharge()) {
|
||||
// savings applicable validation
|
||||
final Integer chargeTimeType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed("chargeTimeType", element);
|
||||
@@ -301,8 +305,26 @@ public final class ChargeDefinitionCommandFromApiJsonDeserializer {
|
||||
|
||||
throwExceptionIfValidationWarningsExist(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) {
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -112,6 +112,9 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
|
||||
|
||||
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
|
||||
// deactivated:
|
||||
if (changes.containsKey("active")) {
|
||||
@@ -130,7 +133,7 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
|
||||
if (isChargeExistWithLoans) { throw new ChargeCannotBeUpdatedException(
|
||||
"error.msg.charge.frequency.cannot.be.updated.it.is.used.in.loan",
|
||||
"This charge frequency cannot be updated, it is used in loan"); }
|
||||
}
|
||||
}
|
||||
|
||||
// Has account Id been changed ?
|
||||
if (changes.containsKey(ChargesApiConstants.glAccountIdParamName)) {
|
||||
|
||||
Reference in New Issue
Block a user