use of org.mifos.framework.util.helpers.DoubleConversionResult 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.DoubleConversionResult 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.DoubleConversionResult in project head by mifos.
the class BaseActionFormTest method xtestParseDoubleForMoney_is_IS.
/**
* Currently broken -- incomplete support for multiple locales for numeric
* input.
*/
@Ignore
@Test
public void xtestParseDoubleForMoney_is_IS() {
LocalizationConverter converter = new LocalizationConverter();
String doubleStr = "222.12345";
Double value = 222.12345;
DoubleConversionResult result = baseActionForm.parseDoubleForInterest("222,12345");
result = baseActionForm.parseDoubleForMoney("222,4");
Assert.assertEquals(value, result.getDoubleValue());
doubleStr = "222.4";
result = baseActionForm.parseDoubleForMoney(doubleStr);
Assert.assertEquals(ConversionError.NOT_ALL_NUMBER, result.getErrors().get(0));
doubleStr = "222a4";
result = baseActionForm.parseDoubleForMoney(doubleStr);
Assert.assertEquals(ConversionError.NOT_ALL_NUMBER, result.getErrors().get(0));
doubleStr = "222,40000";
result = baseActionForm.parseDoubleForMoney(doubleStr);
Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_MONEY, result.getErrors().get(0));
doubleStr = "222222222222,4";
result = baseActionForm.parseDoubleForMoney(doubleStr);
Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY, result.getErrors().get(0));
// converter.setCurrentLocale(locale);
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class LocalizationConverterTest method testParseDoubleForInterest.
@Test
public void testParseDoubleForInterest() {
String doubleValueString = "222.59562";
Double dValue = 222.59562;
Short digitsAfterForInterestSaved = AccountingRules.getDigitsAfterDecimalForInterest();
Short digitsAfterForInterest = 5;
AccountingRules.setDigitsAfterDecimalForInterest(digitsAfterForInterest);
Locale locale = Localization.getInstance().getConfiguredLocale();
short digitsAfterDecimalForMoney = Short.valueOf("1");
short digitsBeforeDecimalForMoney = Short.valueOf("1");
short digitsAfterDecimalForInterest = Short.valueOf("5");
short digitsBeforeDecimalForInterest = Short.valueOf("6");
short digitsBeforeDecimalForCashFlowValidations = Short.valueOf("1");
short digitsAfterDecimalForCashFlowValidations = Short.valueOf("5");
converter = new LocalizationConverter(digitsAfterDecimalForMoney, digitsBeforeDecimalForMoney, digitsAfterDecimalForInterest, digitsBeforeDecimalForInterest, digitsBeforeDecimalForCashFlowValidations, digitsAfterDecimalForCashFlowValidations);
DoubleConversionResult result = converter.parseDoubleForInterest(doubleValueString);
if (locale.getCountry().equalsIgnoreCase("GB") && locale.getLanguage().equalsIgnoreCase("EN")) {
Assert.assertEquals(result.getDoubleValue(), dValue);
// if the wrong decimal separator is entered, error will be returned
doubleValueString = "222,59562";
result = converter.parseDoubleForInterest(doubleValueString);
Assert.assertEquals(result.getErrors().get(0), ConversionError.NOT_ALL_NUMBER);
doubleValueString = "2a5922";
result = converter.parseDoubleForInterest(doubleValueString);
Assert.assertEquals(result.getErrors().get(0), ConversionError.NOT_ALL_NUMBER);
doubleValueString = "222.595690";
result = converter.parseDoubleForInterest(doubleValueString);
Assert.assertEquals(result.getErrors().get(0), ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_INTEREST);
doubleValueString = "22222222222.5";
result = converter.parseDoubleForInterest(doubleValueString);
Assert.assertEquals(result.getErrors().get(0), ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_INTEREST);
}
AccountingRules.setDigitsAfterDecimalForInterest(digitsAfterForInterestSaved);
converter.setCurrentLocale(locale);
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class LocalizationConverterTest method testParseDoubleForCashFlowValidations.
@Test
public void testParseDoubleForCashFlowValidations() {
MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
LocalizationConverter localizationConverter = new LocalizationConverter(mifosCurrency);
DoubleConversionResult result = parseForCashFlow(localizationConverter, "22.59");
assertThat(result.getDoubleValue(), is(22.59));
result = parseForCashFlow(localizationConverter, "222,59562");
assertThat(result.getErrors().get(0), is(ConversionError.NOT_ALL_NUMBER));
result = parseForCashFlow(localizationConverter, "2a5922");
assertThat(result.getErrors().get(0), is(ConversionError.NOT_ALL_NUMBER));
result = parseForCashFlow(localizationConverter, "22222222222.5");
assertThat(result.getErrors().get(0), is(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_CASHFLOW_VALIDATION));
result = parseForCashFlow(localizationConverter, "222.595690");
assertThat(result.getErrors().get(0), is(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_CASHFLOW_VALIDATION));
result = parseForCashFlow(localizationConverter, "222.59");
assertThat(result.getErrors().get(0), is(ConversionError.CASH_FLOW_THRESHOLD_OUT_OF_RANGE));
}
Aggregations