Search in sources :

Example 26 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class LoanPrdActionForm method validateMinMaxDefInterestRates.

private void validateMinMaxDefInterestRates(ActionErrors errors, Locale locale, HttpServletRequest request) {
    DoubleConversionResult minInterestResult = null;
    DoubleConversionResult maxInterestResult = null;
    DoubleConversionResult defInterestResult = null;
    List<ConversionError> errorList = null;
    Double maxInterest = null;
    Double minInterest = null;
    Double defInterest = null;
    String label = getLabel(ConfigurationConstants.INTEREST);
    String prdrate = getLocalizedMessage("product.prdrate");
    String min = getLocalizedMessage("product.min");
    String max = getLocalizedMessage("product.max");
    String defaultString = getLocalizedMessage("product.default");
    if (!StringUtils.isNotBlank(minInterestRate)) {
        addError(errors, "minInterestRate", ProductDefinitionConstants.ERRORS_MANDATORY_MIN_INTEREST);
    } else {
        minInterestResult = parseDoubleForInterest(minInterestRate);
        errorList = minInterestResult.getErrors();
        if (errorList.size() > 0) {
            for (int i = 0; i < errorList.size(); i++) {
                addError(errors, ProductDefinitionConstants.ERRORMININTERESTINVALIDFORMAT, ProductDefinitionConstants.ERRORMININTERESTINVALIDFORMAT, getConversionErrorText(errorList.get(i)));
            }
        } else {
            minInterest = minInterestResult.getDoubleValue();
        }
    }
    if (!StringUtils.isNotBlank(maxInterestRate)) {
        addError(errors, "maxInterestRate", ProductDefinitionConstants.ERRORS_MANDATORY_MAX_INTEREST);
    } else {
        maxInterestResult = parseDoubleForInterest(maxInterestRate);
        errorList = maxInterestResult.getErrors();
        if (errorList.size() > 0) {
            for (ConversionError anErrorList : errorList) {
                addError(errors, ProductDefinitionConstants.ERRORMAXINTERESTINVALIDFORMAT, ProductDefinitionConstants.ERRORMAXINTERESTINVALIDFORMAT, getConversionErrorText(anErrorList));
            }
        } else {
            maxInterest = maxInterestResult.getDoubleValue();
        }
    }
    if (!StringUtils.isNotBlank(defInterestRate)) {
        addError(errors, "defInterestRate", ProductDefinitionConstants.ERRORS_MANDATORY_DEFAULT_INTEREST);
    } else {
        defInterestResult = parseDoubleForInterest(defInterestRate);
        errorList = defInterestResult.getErrors();
        if (errorList.size() > 0) {
            for (int i = 0; i < errorList.size(); i++) {
                addError(errors, ProductDefinitionConstants.ERRORDEFINTERESTINVALIDFORMAT, ProductDefinitionConstants.ERRORDEFINTERESTINVALIDFORMAT, getConversionErrorText(errorList.get(i)));
            }
        } else {
            defInterest = defInterestResult.getDoubleValue();
        }
    }
    if ((minInterest != null) && (maxInterest != null)) {
        if (minInterest > maxInterest) {
            addError(errors, "MinMaxInterestRate", ProductDefinitionConstants.ERRORSMINMAXINTCONFIG, max, label, prdrate, min);
        }
        if (defInterest != null) {
            if ((defInterest < minInterest) || (defInterest > maxInterest)) {
                addError(errors, "DefInterestRate", ProductDefinitionConstants.ERRORSDEFINTCONFIG, defaultString, label, prdrate, min, max);
            } else {
                minInterestRateValue = minInterest;
                maxInterestRateValue = maxInterest;
                defInterestRateValue = defInterest;
            }
        }
    }
}
Also used : ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 27 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class SavingsActionForm method validateAmount.

protected DoubleConversionResult validateAmount(String amountString, String fieldPropertyKey, ActionErrors errors, Locale locale, String propertyfileName) {
    DoubleConversionResult conversionResult = parseDoubleForMoney(amountString);
    String arg = getLocalizedMessage(fieldPropertyKey);
    addConversionResultErrors(fieldPropertyKey, arg, errors, locale, conversionResult);
    return conversionResult;
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 28 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class LoanAccountActionForm method validateIndividualLoanFieldsForGlim.

private void validateIndividualLoanFieldsForGlim(ActionErrors errors, Locale locale, MifosCurrency currency) {
    int errorsBeforeLoanAmountsValidation = errors.size();
    for (LoanAccountDetailsDto listDetail : clientDetails) {
        if (getClients().contains(listDetail.getClientId())) {
            DoubleConversionResult conversionResult = validateAmount(listDetail.getLoanAmount(), currency, LoanConstants.LOAN_AMOUNT_KEY, errors, "");
            if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
                addError(errors, LoanConstants.LOAN_AMOUNT_KEY, LoanConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(LoanConstants.LOAN_AMOUNT_KEY));
            }
        } else {
            if (!listDetail.isEmpty()) {
                addError(errors, "", LoanExceptionConstants.LOAN_DETAILS_ENTERED_WITHOUT_SELECTING_INDIVIDUAL, "");
                break;
            }
        }
    }
    int amountValidationErrors = errors.size() - errorsBeforeLoanAmountsValidation;
    if (amountValidationErrors == 0) {
        validateSumOfTheAmountsSpecified(errors);
    }
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto)

Example 29 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class LoanAccountActionForm method validateLoanAmount.

protected void validateLoanAmount(ActionErrors errors, Locale locale, MifosCurrency currency) {
    DoubleConversionResult conversionResult = validateAmount(getLoanAmount(), currency, LoanConstants.LOAN_AMOUNT_KEY, errors, "");
    Double loanAmountValue = conversionResult.getDoubleValue();
    if (conversionResult.getErrors().size() == 0) {
        if (loanAmountValue <= 0.0) {
            addError(errors, LoanConstants.LOAN_AMOUNT_KEY, LoanConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, getLocalizedMessage(LoanConstants.LOAN_AMOUNT_KEY));
        } else {
            this.loanAmountValue = new Money(currency, loanAmountValue);
        }
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 30 with DoubleConversionResult

use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.

the class BaseActionForm method validateAmount.

protected DoubleConversionResult validateAmount(String amountString, MifosCurrency currency, String fieldPropertyKey, ActionErrors errors, String installmentNo) {
    String fieldName = getLocalizedMessage(fieldPropertyKey);
    DoubleConversionResult conversionResult = parseDoubleForMoney(amountString, currency);
    for (ConversionError error : conversionResult.getErrors()) {
        String errorText = error.toLocalizedMessage(currency);
        addError(errors, fieldPropertyKey, "errors.generic", fieldName, errorText);
    }
    return conversionResult;
}
Also used : ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Aggregations

DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)43 ConversionError (org.mifos.framework.util.helpers.ConversionError)20 Locale (java.util.Locale)9 ArrayList (java.util.ArrayList)7 ActionErrors (org.apache.struts.action.ActionErrors)7 ActionMessage (org.apache.struts.action.ActionMessage)7 Test (org.junit.Test)7 ResourceBundle (java.util.ResourceBundle)6 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)5 MifosCurrency (org.mifos.application.master.business.MifosCurrency)4 LocalizationConverter (org.mifos.framework.util.LocalizationConverter)4 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 List (java.util.List)1 Map (java.util.Map)1 FeeDto (org.mifos.accounts.fees.business.FeeDto)1 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)1 Money (org.mifos.framework.util.helpers.Money)1