Search in sources :

Example 31 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class CenterUpdateTest method cannotUpdateCenterWithDifferentVersion.

@Test
public void cannotUpdateCenterWithDifferentVersion() {
    // setup
    int differentVersionNum = -1;
    CenterBO existingCenter = new CenterBuilder().withLoanOfficer(PersonnelBuilder.anyLoanOfficer()).withVersion(differentVersionNum).build();
    UserContext userContext = TestUtils.makeUser();
    CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
    // stub
    when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(existingCenter);
    // exercise test
    try {
        customerService.updateCenter(userContext, centerUpdate);
        fail("cannotUpdateCenterWithDifferentVersion");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(Constants.ERROR_VERSION_MISMATCH));
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) Test(org.junit.Test)

Example 32 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException 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 33 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException 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 34 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class AdminServiceFacadeWebTier method retrieveLoanProductFormReferenceData.

@Override
public LoanProductFormDto retrieveLoanProductFormReferenceData() {
    try {
        LoanPrdBusinessService service = new LoanPrdBusinessService();
        List<ListElement> productCategoryOptions = new ArrayList<ListElement>();
        List<ProductCategoryBO> productCategories = service.getActiveLoanProductCategories();
        for (ProductCategoryBO category : productCategories) {
            productCategoryOptions.add(new ListElement(category.getProductCategoryID().intValue(), category.getProductCategoryName()));
        }
        List<ListElement> applicableForOptions = new ArrayList<ListElement>();
        List<PrdApplicableMasterEntity> applicableCustomerTypes = this.loanProductDao.retrieveLoanApplicableProductCategories();
        for (PrdApplicableMasterEntity entity : applicableCustomerTypes) {
            applicableForOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> gracePeriodTypeOptions = new ArrayList<ListElement>();
        List<GracePeriodTypeEntity> gracePeriodTypes = this.loanProductDao.retrieveGracePeriodTypes();
        for (GracePeriodTypeEntity gracePeriodTypeEntity : gracePeriodTypes) {
            gracePeriodTypeOptions.add(new ListElement(gracePeriodTypeEntity.getId().intValue(), gracePeriodTypeEntity.getName()));
        }
        List<ListElement> interestCalcTypesOptions = new ArrayList<ListElement>();
        List<InterestTypesEntity> interestCalcTypes = this.loanProductDao.retrieveInterestTypes();
        for (InterestTypesEntity entity : interestCalcTypes) {
            interestCalcTypesOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> sourceOfFunds = new ArrayList<ListElement>();
        List<FundBO> funds = this.fundDao.findAllFunds();
        for (FundBO fund : funds) {
            sourceOfFunds.add(new ListElement(fund.getFundId().intValue(), fund.getFundName()));
        }
        List<ListElement> loanFee = new ArrayList<ListElement>();
        List<FeeBO> fees = feeDao.getAllAppllicableFeeForLoanCreation();
        for (FeeBO fee : fees) {
            loanFee.add(new ListElement(fee.getFeeId().intValue(), fee.getFeeName()));
        }
        List<ListElement> principalGlCodes = new ArrayList<ListElement>();
        List<GLCodeEntity> principalGlCodeEntities = new FinancialBusinessService().getGLCodes(FinancialActionConstants.PRINCIPALPOSTING, FinancialConstants.CREDIT);
        for (GLCodeEntity glCode : principalGlCodeEntities) {
            principalGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode()));
        }
        List<ListElement> interestGlCodes = new ArrayList<ListElement>();
        List<GLCodeEntity> interestGlCodeEntities = new FinancialBusinessService().getGLCodes(FinancialActionConstants.INTERESTPOSTING, FinancialConstants.CREDIT);
        for (GLCodeEntity glCode : interestGlCodeEntities) {
            interestGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode()));
        }
        List<ListElement> statusOptions = new ArrayList<ListElement>();
        List<PrdStatusEntity> applicableStatuses = service.getApplicablePrdStatus(Short.valueOf("1"));
        for (PrdStatusEntity entity : applicableStatuses) {
            statusOptions.add(new ListElement(entity.getOfferingStatusId().intValue(), entity.getPrdState().getName()));
        }
        boolean multiCurrencyEnabled = AccountingRules.isMultiCurrencyEnabled();
        List<ListElement> currencyOptions = new ArrayList<ListElement>();
        if (multiCurrencyEnabled) {
            LinkedList<MifosCurrency> currencies = AccountingRules.getCurrencies();
            for (MifosCurrency mifosCurrency : currencies) {
                currencyOptions.add(new ListElement(mifosCurrency.getCurrencyId().intValue(), mifosCurrency.getCurrencyCode()));
            }
        }
        return new LoanProductFormDto(productCategoryOptions, gracePeriodTypeOptions, sourceOfFunds, loanFee, principalGlCodes, interestGlCodes, interestCalcTypesOptions, applicableForOptions, statusOptions, currencyOptions, multiCurrencyEnabled);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (SystemException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) LoanPrdBusinessService(org.mifos.accounts.productdefinition.business.service.LoanPrdBusinessService) ArrayList(java.util.ArrayList) FinancialBusinessService(org.mifos.accounts.financial.business.service.FinancialBusinessService) LoanProductFormDto(org.mifos.dto.screen.LoanProductFormDto) BusinessRuleException(org.mifos.service.BusinessRuleException) SystemException(org.mifos.framework.exceptions.SystemException) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) FundBO(org.mifos.accounts.fund.business.FundBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 35 with ApplicationException

use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.

the class CenterServiceFacadeWebTier method updateCenter.

@Override
public void updateCenter(CenterUpdate centerUpdate) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        customerService.updateCenter(userContext, centerUpdate);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser)

Aggregations

ApplicationException (org.mifos.framework.exceptions.ApplicationException)76 BusinessRuleException (org.mifos.service.BusinessRuleException)34 MifosRuntimeException (org.mifos.core.MifosRuntimeException)29 UserContext (org.mifos.security.util.UserContext)25 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 ArrayList (java.util.ArrayList)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)16 MifosUser (org.mifos.security.MifosUser)16 SystemException (org.mifos.framework.exceptions.SystemException)14 CustomerBO (org.mifos.customers.business.CustomerBO)10 ServiceException (org.mifos.framework.exceptions.ServiceException)10 Test (org.junit.Test)9 AccountException (org.mifos.accounts.exceptions.AccountException)9 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)9 CustomerException (org.mifos.customers.exceptions.CustomerException)9 HibernateException (org.hibernate.HibernateException)8 Session (org.hibernate.Session)7 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)7 CenterBO (org.mifos.customers.center.business.CenterBO)7