Search in sources :

Example 36 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class DateUtilsTest method testGetDateFromBrowser.

public void testGetDateFromBrowser() throws Exception {
    // test that day and month order is correct
    long expectedDate = new DateMidnight(2005, 03, 04).getMillis();
    java.sql.Date result = DateUtils.getDateAsSentFromBrowser("04/03/2005");
    Assert.assertEquals(expectedDate, result.getTime());
    expectedDate = new DateMidnight(2005, 04, 03).getMillis();
    result = DateUtils.getDateAsSentFromBrowser("3/4/2005");
    Assert.assertEquals(expectedDate, result.getTime());
    // test non-lenient day/month parsing (must be in the normal range, i.e.
    // 1-12 for months)
    String badDate = "3/15/2006";
    try {
        result = DateUtils.getDateAsSentFromBrowser(badDate);
        Assert.fail();
    } catch (InvalidDateException e) {
        Assert.assertEquals(badDate, e.getDateString());
    }
    // test acceptance of two-digit years
    expectedDate = new DateMidnight(2005, 5, 5).getMillis();
    result = DateUtils.getDateAsSentFromBrowser("5/5/05");
    Assert.assertEquals(expectedDate, result.getTime());
}
Also used : DateMidnight(org.joda.time.DateMidnight) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException)

Example 37 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class DateUtilsTest method testParseBrowserDateFields.

public void testParseBrowserDateFields() throws Exception {
    long expectedDate = new DateMidnight(2005, 03, 04).getMillis();
    java.sql.Date result = DateUtils.parseBrowserDateFields("2005", "3", "4");
    Assert.assertEquals(expectedDate, result.getTime());
    result = DateUtils.parseBrowserDateFields("05", "03", "04");
    Assert.assertEquals(expectedDate, result.getTime());
    expectedDate = new DateMidnight(2005, 03, 20).getMillis();
    result = DateUtils.parseBrowserDateFields("05", "03", "20");
    Assert.assertEquals(expectedDate, result.getTime());
    try {
        DateUtils.parseBrowserDateFields("2005", "20", "1");
        Assert.fail("didn't parse month correctly");
    } catch (InvalidDateException e) {
        Assert.assertEquals(e.getDateString(), "1/20/2005");
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException)

Example 38 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class LoanBO method handleArrears.

public void handleArrears() throws AccountException {
    AccountStateEntity stateEntity;
    try {
        stateEntity = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_BADSTANDING);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
    AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), stateEntity, this.getPersonnel(), this);
    this.addAccountStatusChangeHistory(historyEntity);
    this.setAccountState(stateEntity);
    try {
        String systemDate = DateUtils.getCurrentDate();
        Date currrentDate = DateUtils.getLocaleDate(systemDate);
        this.setUpdatedDate(currrentDate);
    } catch (InvalidDateException ide) {
        throw new AccountException(ide);
    }
    try {
        getlegacyLoanDao().createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 39 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class SavingsServiceFacadeWebTier method updateSavingsAccountDetails.

@Override
public void updateSavingsAccountDetails(Long savingsId, String recommendedOrMandatoryAmount, List<CustomFieldDto> customFields) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
    savingsAccount.updateDetails(userContext);
    Set<AccountCustomFieldEntity> accountCustomFields = savingsAccount.getAccountCustomFields();
    for (CustomFieldDto view : customFields) {
        boolean fieldPresent = false;
        if (CustomFieldType.DATE.getValue().equals(view.getFieldType()) && org.apache.commons.lang.StringUtils.isNotBlank(view.getFieldValue())) {
            try {
                SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, userContext.getPreferredLocale());
                String userfmt = DateUtils.convertToCurrentDateFormat(format.toPattern());
                view.setFieldValue(DateUtils.convertUserToDbFmt(view.getFieldValue(), userfmt));
            } catch (InvalidDateException e) {
                throw new BusinessRuleException(e.getMessage(), e);
            }
        }
        for (AccountCustomFieldEntity customFieldEntity : accountCustomFields) {
            if (customFieldEntity.getFieldId().equals(view.getFieldId())) {
                fieldPresent = true;
                customFieldEntity.setFieldValue(view.getFieldValue());
            }
        }
        if (!fieldPresent) {
            accountCustomFields.add(new AccountCustomFieldEntity(savingsAccount, view.getFieldId(), view.getFieldValue()));
        }
    }
    Money amount = new Money(savingsAccount.getCurrency(), recommendedOrMandatoryAmount);
    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        savingsAccount.update(amount, accountCustomFields);
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) SimpleDateFormat(java.text.SimpleDateFormat) AccountCustomFieldEntity(org.mifos.accounts.business.AccountCustomFieldEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 40 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class InterOfficeTransferActionForm method mandatoryCheck.

private ActionErrors mandatoryCheck(UserContext userContext) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);
    String trxn_Date = resources.getString(SimpleAccountingConstants.TRXNDATE);
    String trxn_Type = resources.getString(SimpleAccountingConstants.TRXNTYPE);
    String office_Hierarchy = resources.getString(SimpleAccountingConstants.OFFICE_HIERARCHY);
    String officeId = resources.getString(SimpleAccountingConstants.OFFICE);
    String main_Account = resources.getString(SimpleAccountingConstants.MAIN_ACCOUNT);
    String subAccount = resources.getString(SimpleAccountingConstants.ACCOUNT_HEAD);
    String Amount = resources.getString(SimpleAccountingConstants.AMOUNT);
    String Notes = resources.getString(SimpleAccountingConstants.TRXN_NOTES);
    ActionErrors errors = new ActionErrors();
    java.sql.Date currentDate = null;
    try {
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(SimpleAccountingConstants.INVALIDDATE, new ActionMessage(SimpleAccountingConstants.INVALIDDATE));
    }
    java.sql.Date trxnDate = null;
    if (getTrxnDate() == null || "".equals(getTrxnDate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, trxn_Date));
    } else if (getTrxnDate() != null && !getTrxnDate().equals("") && !DateUtils.isValidDate(getTrxnDate())) {
        errors = trxnDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getTrxnDate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getTrxnDate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, trxn_Date));
        }
        if (trxnDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE, new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, trxn_Date));
        }
    }
    if (fromOfficeHierarchy == null || "".equals(fromOfficeHierarchy.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, office_Hierarchy));
    }
    if (fromOffice == null || "".equals(fromOffice.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, officeId));
    }
    if (toOfficeHierarchy == null || "".equals(toOfficeHierarchy.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, office_Hierarchy));
    }
    if (toOffice == null || "".equals(toOffice.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, officeId));
    }
    if (debitAccountHead == null || "".equals(debitAccountHead.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, main_Account));
    }
    if (creditAccountHead == null || "".equals(creditAccountHead.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, subAccount));
    }
    if (amount == null || "".equals(amount.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Amount));
    }
    if (StringUtils.isNotBlank(getAmount())) {
        DoubleConversionResult conversionResult = validateAmount(getAmount(), Amount, errors);
        if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
            addError(errors, SimpleAccountingConstants.AMOUNT, SimpleAccountingConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, Amount);
        }
    }
    if (notes == null || "".equals(notes.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Notes));
    }
    if (getChequeDate() != null && !getChequeDate().equals("") && !DateUtils.isValidDate(getChequeDate()))
        errors = chequeDateValidate(errors, locale);
    return errors;
}
Also used : Locale(java.util.Locale) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ResourceBundle(java.util.ResourceBundle) DoubleConversionResult(org.mifos.framework.util.helpers.DoubleConversionResult) ActionErrors(org.apache.struts.action.ActionErrors)

Aggregations

InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)46 ActionMessage (org.apache.struts.action.ActionMessage)22 ActionErrors (org.apache.struts.action.ActionErrors)20 Locale (java.util.Locale)12 Date (java.sql.Date)9 ResourceBundle (java.util.ResourceBundle)9 PersistenceException (org.mifos.framework.exceptions.PersistenceException)6 Date (java.util.Date)5 AccountException (org.mifos.accounts.exceptions.AccountException)5 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)5 SimpleDateFormat (java.text.SimpleDateFormat)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 CustomerException (org.mifos.customers.exceptions.CustomerException)4 ParseException (java.text.ParseException)3 LocalDate (org.joda.time.LocalDate)3 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)3 BusinessRuleException (org.mifos.service.BusinessRuleException)3 ArrayList (java.util.ArrayList)2 DateMidnight (org.joda.time.DateMidnight)2 DateTime (org.joda.time.DateTime)2