use of org.mifos.framework.util.helpers.ConversionError 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;
}
}
}
}
use of org.mifos.framework.util.helpers.ConversionError 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;
}
use of org.mifos.framework.util.helpers.ConversionError in project head by mifos.
the class BaseActionForm method validateInterest.
protected DoubleConversionResult validateInterest(String interestString, String fieldPropertyKey, ActionErrors errors) {
String fieldName = getLocalizedMessage(fieldPropertyKey);
DoubleConversionResult conversionResult = parseDoubleForInterest(interestString);
for (ConversionError error : conversionResult.getErrors()) {
addError(errors, fieldPropertyKey, "errors.generic", fieldName, getConversionErrorText(error));
}
return conversionResult;
}
use of org.mifos.framework.util.helpers.ConversionError in project head by mifos.
the class LocalizationConverter method parseDoubleDecimalForMoney.
public DoubleConversionResult parseDoubleDecimalForMoney(String doubleStr) {
DoubleConversionResult result = new DoubleConversionResult();
if (doubleStr == null) {
List<ConversionError> errors = new ArrayList<ConversionError>();
errors.add(ConversionError.CONVERSION_ERROR);
result.setErrors(errors);
return result;
}
List<ConversionError> errors = checkDigits(digitsBeforeDecimalForMoney, multipleDigitsAfterDecimalForMoney, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY, ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_MONEY, doubleStr, false);
result.setErrors(errors);
if (errors.size() > 0) {
return result;
}
try {
result.setDoubleValue(getDoubleValueForCurrentLocale(doubleStr));
} catch (Exception ex) {
// after all the checkings this is not likely to happen, but just in
// case
result.getErrors().add(ConversionError.CONVERSION_ERROR);
}
return result;
}
use of org.mifos.framework.util.helpers.ConversionError in project head by mifos.
the class ViewStageTransactionActionForm method validateAmount.
protected DoubleConversionResult validateAmount(String amountString, MifosCurrency currency, String fieldPropertyKey, ActionErrors errors, String installmentNo) {
String fieldName = fieldPropertyKey;
DoubleConversionResult conversionResult = parseDoubleDecimalForMoney(amountString, currency);
for (ConversionError error : conversionResult.getErrors()) {
String errorText = error.toLocalizedMessage(currency);
addError(errors, fieldName, "errors.generic", fieldName, errorText);
}
return conversionResult;
}
Aggregations