Search in sources :

Example 21 with DoubleConversionResult

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;
}
Also used : ConversionError(org.mifos.framework.util.helpers.ConversionError) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult)

Example 22 with DoubleConversionResult

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));
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with DoubleConversionResult

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));
}
Also used : LocalizationConverter(org.mifos.framework.util.LocalizationConverter) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) Test(org.junit.Test)

Example 24 with DoubleConversionResult

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));
}
Also used : DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 25 with DoubleConversionResult

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);
    }
}
Also used : ArrayList(java.util.ArrayList) 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