Search in sources :

Example 56 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class DeleteCoaController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") CoaFormBean formBean, BindingResult result, SessionStatus status) {
    ModelAndView mav = new ModelAndView(REDIRECT_TO_COA_ADMIN_SCREEN);
    if (StringUtils.isNotBlank(cancel)) {
        status.setComplete();
    } else {
        try {
            coaServiceFacade.delete(formBean.getAccountId());
            status.setComplete();
        } catch (BusinessRuleException ex) {
            ObjectError error = new ObjectError("formBean", new String[] { ex.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            mav.setViewName(DELETE_COA);
            mav.addObject("formBean", formBean);
        }
    }
    return mav;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class ClearOverpaymentController method applyOverpaymentClear.

// called by spring webflow
public String applyOverpaymentClear(final String overpaymentId, ClearOverpaymentFormBean clearOverpaymentFormBean, MessageContext messageContext) {
    String returnCode = "";
    try {
        BigDecimal overpaymentAmount = null;
        if (clearOverpaymentFormBean.getActualOverpaymentAmount() != null) {
            overpaymentAmount = BigDecimal.valueOf(clearOverpaymentFormBean.getActualOverpaymentAmount().doubleValue());
        }
        this.loanAccountServiceFacade.applyOverpaymentClear(overpaymentId, overpaymentAmount);
        returnCode = "success";
    } catch (BusinessRuleException e) {
        MessageBuilder builder = new MessageBuilder().error().source("overpaymentAmount").codes(Arrays.asList(e.getMessageKey()).toArray(new String[1])).defaultText(e.getMessage()).args(e.getMessageValues());
        messageContext.addMessage(builder.build());
        returnCode = "error";
    }
    return returnCode;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) MessageBuilder(org.springframework.binding.message.MessageBuilder) BigDecimal(java.math.BigDecimal)

Example 58 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class CenterServiceFacadeWebTier method waiveChargesDue.

@Override
public void waiveChargesDue(Integer accountId, Integer waiveType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        account.updateDetails(userContext);
        PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
        WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        try {
            this.transactionHelper.startTransaction();
            if (account instanceof LoanBO) {
                ((LoanBO) account).waiveAmountDue(waiveEnum);
            } else if (account instanceof SavingsBO) {
                ((SavingsBO) account).waiveNextDepositAmountDue(loggedInUser);
            } else {
                ((CustomerAccountBO) account).waiveAmountDue();
            }
            this.customerDao.save(account);
            this.transactionHelper.commitTransaction();
        } catch (Exception e) {
            this.transactionHelper.rollbackTransaction();
            throw new BusinessRuleException(account.getAccountId().toString(), e);
        } finally {
            this.transactionHelper.closeSession();
        }
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 59 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class CenterServiceFacadeWebTier method removeAccountFee.

@Override
public void removeAccountFee(Integer accountId, Short feeId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        if (account instanceof LoanBO) {
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    individual.removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeId, userContext.getId());
                    this.customerDao.save(individual);
                }
            }
        }
        account.updateDetails(userContext);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForRemoveFees(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForRemoveFees(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        account.removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(feeId, userContext.getId());
        this.customerDao.save(account);
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (AccountException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 60 with BusinessRuleException

use of org.mifos.service.BusinessRuleException in project head by mifos.

the class CheckListServiceFacadeWebTier method createCustomerChecklist.

@Override
public void createCustomerChecklist(Short levelId, Short stateId, String checklistName, List<String> checklistDetails) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    CustomerLevel level = CustomerLevel.getLevel(levelId);
    CustomerLevelEntity customerLevelEntity = new CustomerLevelEntity(level);
    CustomerStatusEntity customerStatusEntity = new CustomerStatusEntity(stateId);
    try {
        hibernateTransactionHelper.startTransaction();
        CustomerCheckListBO customerCheckListBO = new CustomerCheckListBO(customerLevelEntity, customerStatusEntity, checklistName, CheckListConstants.STATUS_ACTIVE, checklistDetails, userContext.getLocaleId(), userContext.getId());
        customerDao.save(customerCheckListBO);
        hibernateTransactionHelper.commitTransaction();
    } catch (CheckListException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : CustomerLevel(org.mifos.customers.api.CustomerLevel) CustomerCheckListBO(org.mifos.customers.checklist.business.CustomerCheckListBO) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) CustomerLevelEntity(org.mifos.customers.business.CustomerLevelEntity) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException)

Aggregations

BusinessRuleException (org.mifos.service.BusinessRuleException)140 MifosRuntimeException (org.mifos.core.MifosRuntimeException)68 UserContext (org.mifos.security.util.UserContext)63 MifosUser (org.mifos.security.MifosUser)61 AccountException (org.mifos.accounts.exceptions.AccountException)46 PersistenceException (org.mifos.framework.exceptions.PersistenceException)43 ApplicationException (org.mifos.framework.exceptions.ApplicationException)33 LocalDate (org.joda.time.LocalDate)31 ServiceException (org.mifos.framework.exceptions.ServiceException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)26 ArrayList (java.util.ArrayList)23 CustomerBO (org.mifos.customers.business.CustomerBO)22 Money (org.mifos.framework.util.helpers.Money)22 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)20 CustomerException (org.mifos.customers.exceptions.CustomerException)19 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)16 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)16 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)16 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)16