Search in sources :

Example 1 with ServiceException

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

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

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

the class CenterServiceFacadeWebTier method retrieveChangeLogs.

@Override
public List<AuditLogDto> retrieveChangeLogs(Integer centerId) {
    try {
        List<AuditLogDto> auditLogs = new ArrayList<AuditLogDto>();
        Short entityType = EntityType.CENTER.getValue();
        AuditBusinessService auditBusinessService = new AuditBusinessService();
        List<AuditLogView> centerAuditLogs = auditBusinessService.getAuditLogRecords(entityType, centerId);
        for (AuditLogView auditLogView : centerAuditLogs) {
            auditLogs.add(auditLogView.toDto());
        }
        return auditLogs;
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AuditBusinessService(org.mifos.framework.components.audit.business.service.AuditBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ArrayList(java.util.ArrayList) AuditLogView(org.mifos.framework.components.audit.util.helpers.AuditLogView) AuditLogDto(org.mifos.dto.domain.AuditLogDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with ServiceException

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

the class CheckListServiceFacadeWebTier method retreiveAllCustomerCheckLists.

@Override
public List<CustomerCheckBoxItemDto> retreiveAllCustomerCheckLists() {
    try {
        List<CustomerCheckListBO> customerCheckLists = new CheckListBusinessService().retreiveAllCustomerCheckLists();
        List<CustomerCheckBoxItemDto> dtoList = new ArrayList<CustomerCheckBoxItemDto>();
        for (CustomerCheckListBO bo : customerCheckLists) {
            String lookUpName = bo.getCustomerStatus().getLookUpValue() != null ? bo.getCustomerStatus().getLookUpValue().getLookUpName() : null;
            CustomerCheckBoxItemDto dto = new CustomerCheckBoxItemDto(bo.getChecklistId(), bo.getChecklistName(), bo.getChecklistStatus(), null, lookUpName, bo.getCustomerStatus().getId(), bo.getCustomerLevel().getId());
            if (dto.getLookUpName() != null) {
                dto.setName(ApplicationContextProvider.getBean(MessageLookup.class).lookup(dto.getLookUpName()));
            }
            dtoList.add(dto);
        }
        return dtoList;
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : CustomerCheckListBO(org.mifos.customers.checklist.business.CustomerCheckListBO) ServiceException(org.mifos.framework.exceptions.ServiceException) ArrayList(java.util.ArrayList) CheckListBusinessService(org.mifos.customers.checklist.business.service.CheckListBusinessService) CustomerCheckBoxItemDto(org.mifos.dto.screen.CustomerCheckBoxItemDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with ServiceException

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

the class CheckListServiceFacadeWebTier method createAccountChecklist.

@Override
public void createAccountChecklist(Short productId, Short stateId, String checklistName, List<String> checklistDetails) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        ProductTypeEntity productTypeEntity = null;
        for (ProductTypeEntity prdTypeEntity : new ProductCategoryBusinessService().getProductTypes()) {
            if (productId.equals(prdTypeEntity.getProductTypeID())) {
                productTypeEntity = prdTypeEntity;
                break;
            }
        }
        hibernateTransactionHelper.startTransaction();
        AccountStateEntity accountStateEntity = new AccountStateEntity(AccountState.fromShort(stateId));
        AccountCheckListBO accountCheckListBO = new AccountCheckListBO(productTypeEntity, accountStateEntity, checklistName, CheckListConstants.STATUS_ACTIVE, checklistDetails, userContext.getLocaleId(), userContext.getId());
        customerDao.save(accountCheckListBO);
        hibernateTransactionHelper.commitTransaction();
    } catch (ServiceException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (CheckListException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountCheckListBO(org.mifos.customers.checklist.business.AccountCheckListBO) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) ProductTypeEntity(org.mifos.accounts.productdefinition.business.ProductTypeEntity) ProductCategoryBusinessService(org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

ServiceException (org.mifos.framework.exceptions.ServiceException)93 PersistenceException (org.mifos.framework.exceptions.PersistenceException)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)39 Test (org.junit.Test)34 ExpectedException (org.springframework.test.annotation.ExpectedException)29 ArrayList (java.util.ArrayList)24 UserContext (org.mifos.security.util.UserContext)19 AccountBO (org.mifos.accounts.business.AccountBO)17 MifosUser (org.mifos.security.MifosUser)16 LoanBO (org.mifos.accounts.loan.business.LoanBO)15 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)14 AccountException (org.mifos.accounts.exceptions.AccountException)13 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)13 BusinessRuleException (org.mifos.service.BusinessRuleException)11 Date (java.util.Date)8 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)7 BigDecimal (java.math.BigDecimal)6 ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)6 DateTimeService (org.mifos.framework.util.DateTimeService)6 LocalDate (org.joda.time.LocalDate)5