Search in sources :

Example 26 with InvalidDateException

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

the class CustomerServiceImpl method updateClientPersonalInfo.

@Override
public final void updateClientPersonalInfo(UserContext userContext, ClientPersonalInfoUpdate personalInfo) throws CustomerException {
    ClientBO client = (ClientBO) this.customerDao.findCustomerById(personalInfo.getCustomerId());
    client.validateVersion(personalInfo.getOriginalClientVersionNumber());
    client.updateDetails(userContext);
    LocalDate currentDOB = new LocalDate(client.getDateOfBirth());
    LocalDate newDOB = currentDOB;
    try {
        // updating Date of birth
        // doesn''t sound normal but it can be required in certain cases
        // see http://mifosforge.jira.com/browse/MIFOS-4368
        newDOB = new LocalDate(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
    } catch (InvalidDateException e) {
        throw new MifosRuntimeException(e);
    }
    if (!currentDOB.isEqual(newDOB)) {
        customerDao.validateClientForDuplicateNameOrGovtId(personalInfo.getClientDisplayName(), newDOB.toDateMidnight().toDate(), null);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(client);
        client.updatePersonalInfo(personalInfo);
        clientPhotoService.update(personalInfo.getCustomerId().longValue(), personalInfo.getPicture());
        customerDao.save(client);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new CustomerException(e.getKey(), e);
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.commitTransaction();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientBO(org.mifos.customers.client.business.ClientBO) LocalDate(org.joda.time.LocalDate) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 27 with InvalidDateException

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

the class LoanAccountAction method handleIndividualLoans.

void handleIndividualLoans(final LoanBO loanBO, final LoanAccountActionForm loanAccountActionForm, final boolean isRepaymentIndepOfMeetingEnabled, final List<LoanAccountDetailsDto> loanAccountDetailsList, final List<LoanBO> individualLoans, final Locale locale) throws AccountException, ServiceException {
    List<Integer> foundLoans = new ArrayList<Integer>();
    for (final LoanAccountDetailsDto loanAccountDetail : loanAccountDetailsList) {
        Predicate predicateOldGlim = new Predicate() {

            @Override
            public boolean evaluate(final Object object) {
                return ((LoanBO) object).getCustomer().getCustomerId().toString().equals(loanAccountDetail.getClientId());
            }
        };
        LoanBO individualLoan = (LoanBO) CollectionUtils.find(individualLoans, predicateOldGlim);
        if (individualLoan == null) {
        //                glimLoanUpdater.createIndividualLoan(loanAccountActionForm, loanBO, isRepaymentIndepOfMeetingEnabled,
        //                        loanAccountDetail);
        } else {
            foundLoans.add(individualLoan.getAccountId());
            try {
                if (!AccountingRules.isGroupLoanWithMembers() && loanAccountActionForm.getLoanAmount() != null) {
                    loanAccountDetail.setLoanAmount(loanAccountActionForm.getLoanAmountAsBigDecimal().divide(individualLoan.calcFactorOfEntireLoan(), 10, RoundingMode.HALF_UP).toString());
                }
                glimLoanUpdater.updateIndividualLoan(loanAccountActionForm.getDisbursementDateValue(locale), loanAccountActionForm.getInterestDoubleValue(), loanAccountActionForm.getNoOfInstallmentsValue(), loanAccountDetail, individualLoan);
            } catch (InvalidDateException e) {
                e.printStackTrace();
            }
        }
    }
    for (LoanBO loan : individualLoans) {
        if (!foundLoans.contains(loan.getAccountId())) {
            glimLoanUpdater.delete(loan);
        }
    }
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) Predicate(org.apache.commons.collections.Predicate)

Example 28 with InvalidDateException

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

the class LoanAccountActionForm method checkValidationForManagePreview.

private void checkValidationForManagePreview(ActionErrors errors, MifosCurrency currency, HttpServletRequest request) throws ApplicationException {
    Locale locale = getUserContext(request).getPreferredLocale();
    if (getState().equals(AccountState.LOAN_PARTIAL_APPLICATION) || getState().equals(AccountState.LOAN_PENDING_APPROVAL)) {
        checkValidationForPreviewBefore(errors, request);
        checkValidationForPreview(errors, currency, request);
        // approval, it cannot be edited.
        try {
            // only validate if the disbursement date has changed
            if (!getDisbursementDateValue(getUserContext(request).getPreferredLocale()).equals(getOriginalDisbursementDate())) {
                validateDisbursementDate(errors, getCustomer(request), getDisbursementDateValue(getUserContext(request).getPreferredLocale()));
            }
        } catch (InvalidDateException dateException) {
            addError(errors, LoanExceptionConstants.ERROR_INVALIDDISBURSEMENTDATE);
        }
    }
    performGlimSpecificValidations(errors, currency, request);
    validateCustomFields(request, errors);
    validateRepaymentDayRequired(errors);
    if (!configService.isNewGlimEnabled() || !configService.isGlimEnabled() || !getCustomer(request).isGroup()) {
        validatePurposeOfLoanFields(errors, getMandatoryFields(request));
    }
    validateSourceOfFundFields(errors, getMandatoryFields(request));
    validateExternalIDFields(errors, getMandatoryFields(request));
    validateLoanAmount(errors, locale, currency);
    validateInterest(errors, locale);
    validateCollateralNotes(errors, locale);
}
Also used : Locale(java.util.Locale) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException)

Example 29 with InvalidDateException

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

the class SavingsClosureActionForm method validateDate.

private ActionErrors validateDate(String date, String fieldName) {
    ActionErrors errors = new ActionErrors();
    java.sql.Date sqlDate = null;
    if (date != null && !date.equals("")) {
        try {
            sqlDate = DateUtils.getDateAsSentFromBrowser(date);
            if (DateUtils.whichDirection(sqlDate) > 0) {
                errors = new ActionErrors();
                errors.add(AccountConstants.ERROR_FUTUREDATE, new ActionMessage(AccountConstants.ERROR_FUTUREDATE, fieldName));
            }
        } catch (InvalidDateException e) {
            errors.add(AccountConstants.ERROR_INVALIDDATE, new ActionMessage(AccountConstants.ERROR_INVALIDDATE, fieldName));
        }
    } else {
        errors = new ActionErrors();
        errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, fieldName));
    }
    return errors;
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 30 with InvalidDateException

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

the class SavingsDepositWithdrawalActionForm method validateTrxnDate.

private ActionErrors validateTrxnDate(String date, String fieldName) {
    ActionErrors errors = new ActionErrors();
    try {
        if (lastTrxnDate != null && dateFallsBeforeDate(getDateAsSentFromBrowser(date), lastTrxnDate)) {
            errors = new ActionErrors();
            errors.add(AccountConstants.ERROR_PAYMENT_DATE_BEFORE_LAST_PAYMENT, new ActionMessage(AccountConstants.ERROR_PAYMENT_DATE_BEFORE_LAST_PAYMENT, fieldName));
        }
    } catch (InvalidDateException e) {
    //date format was already validated
    }
    return errors;
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) 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