use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class OpenBalanceActionForm 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;
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class BaseActionFormTest method xtestParseDoubleForInterest_is_IS.
/**
* Currently broken -- incomplete support for multiple locales for numeric
* input.
*/
@Ignore
@Test
public void xtestParseDoubleForInterest_is_IS() {
LocalizationConverter converter = new LocalizationConverter();
String doubleStr = "222.12345";
Double value = 222.12345;
DoubleConversionResult result = baseActionForm.parseDoubleForInterest("222,12345");
Assert.assertEquals(value, result.getDoubleValue());
doubleStr = "222.12345";
result = baseActionForm.parseDoubleForInterest(doubleStr);
Assert.assertEquals(ConversionError.NOT_ALL_NUMBER, result.getErrors().get(0));
doubleStr = "2a2";
result = baseActionForm.parseDoubleForInterest(doubleStr);
Assert.assertEquals(ConversionError.NOT_ALL_NUMBER, result.getErrors().get(0));
doubleStr = "222,123456";
result = baseActionForm.parseDoubleForInterest(doubleStr);
Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_AFTER_DECIMAL_SEPARATOR_FOR_INTEREST, result.getErrors().get(0));
doubleStr = "12345678910,12345";
result = baseActionForm.parseDoubleForInterest(doubleStr);
Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_INTEREST, result.getErrors().get(0));
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class BaseActionFormTest method testParseDoubleForMoney.
@Test
public void testParseDoubleForMoney() {
LocalizationConverter converter = new LocalizationConverter();
String doubleStr = "222.4";
Double value = 222.4;
DoubleConversionResult result = baseActionForm.parseDoubleForMoney(doubleStr);
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 = "222222222222222.4";
result = baseActionForm.parseDoubleForMoney(doubleStr);
Assert.assertEquals(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY, result.getErrors().get(0));
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class LocalizationConverterTest method testParseDoubleForInstallmentTotalAmount.
@Test
public void testParseDoubleForInstallmentTotalAmount() {
MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
LocalizationConverter localizationConverter = new LocalizationConverter(mifosCurrency);
DoubleConversionResult result = localizationConverter.parseDoubleForInstallmentTotalAmount("-478.2");
assertThat(result.getDoubleValue(), is(-478.2));
result = localizationConverter.parseDoubleForInstallmentTotalAmount("478.2");
assertThat(result.getDoubleValue(), is(478.2));
result = localizationConverter.parseDoubleForInstallmentTotalAmount("2,59");
assertThat(result.getErrors().get(0), is(ConversionError.NOT_ALL_NUMBER));
result = localizationConverter.parseDoubleForInstallmentTotalAmount("222222222111111.5");
assertThat(result.getErrors().get(0), is(ConversionError.EXCEEDING_NUMBER_OF_DIGITS_BEFORE_DECIMAL_SEPARATOR_FOR_MONEY));
}
use of org.mifos.framework.util.helpers.DoubleConversionResult in project head by mifos.
the class ApplyChargeActionForm method validateHashMap.
private void validateHashMap(ActionErrors errors) {
ArrayList<String> mapValue = new ArrayList<String>(individualValues.values());
double total = 0.0;
for (int i = 0; i < individualValues.size(); i++) {
DoubleConversionResult conversionResult = validateAmount(mapValue.get(i), getChargeCurrency(), AccountConstants.ACCOUNT_AMOUNT, errors, "");
if (conversionResult.getErrors().size() > 0 || conversionResult.getDoubleValue() < 0.0) {
addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_BE_GREATER_OR_EQUAL_ZERO, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT));
} else {
total += conversionResult.getDoubleValue();
}
}
if (!isRateType() && total != getDoubleValue(charge)) {
addError(errors, AccountConstants.ACCOUNT_AMOUNT, AccountConstants.ERRORS_MUST_SUM_TO_VALID_AMOUNT, getLocalizedMessage(AccountConstants.ACCOUNT_AMOUNT), charge);
}
}
Aggregations