Search in sources :

Example 6 with CheckListException

use of org.mifos.customers.checklist.exceptions.CheckListException 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)

Example 7 with CheckListException

use of org.mifos.customers.checklist.exceptions.CheckListException in project head by mifos.

the class CheckListServiceFacadeWebTier method updateAccountChecklist.

@Override
public void updateAccountChecklist(Short checklistId, Short productId, Short stateId, Short checklistStatus, 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 accountCheckList = (AccountCheckListBO) new CheckListPersistence().getCheckList(checklistId);
        accountCheckList.update(productTypeEntity, accountStateEntity, checklistName, checklistStatus, checklistDetails, userContext.getLocaleId(), userContext.getId());
        customerDao.save(accountCheckList);
        hibernateTransactionHelper.commitTransaction();
    } catch (ServiceException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (CheckListException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (PersistenceException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) ProductCategoryBusinessService(org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService) BusinessRuleException(org.mifos.service.BusinessRuleException) ServiceException(org.mifos.framework.exceptions.ServiceException) CheckListPersistence(org.mifos.customers.checklist.persistence.CheckListPersistence) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountCheckListBO(org.mifos.customers.checklist.business.AccountCheckListBO) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException) ProductTypeEntity(org.mifos.accounts.productdefinition.business.ProductTypeEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with CheckListException

use of org.mifos.customers.checklist.exceptions.CheckListException in project head by mifos.

the class CheckListBOIntegrationTest method testCreateCheckListExceptionForCustomerZeroDetails.

@Test
public void testCreateCheckListExceptionForCustomerZeroDetails() throws Exception {
    CustomerLevelEntity customerLevelEntity = new CustomerLevelEntity(CustomerLevel.CENTER);
    CustomerStatusEntity customerStatusEntity = new CustomerStatusEntity(CustomerStatus.CENTER_ACTIVE);
    try {
        customerCheckList = new CustomerCheckListBO(customerLevelEntity, customerStatusEntity, null, CheckListConstants.STATUS_ACTIVE, new ArrayList<String>(), (short) 1, (short) 1);
        Assert.fail();
    } catch (CheckListException ce) {
        Assert.assertTrue(true);
    }
}
Also used : CustomerLevelEntity(org.mifos.customers.business.CustomerLevelEntity) ArrayList(java.util.ArrayList) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException) Test(org.junit.Test)

Aggregations

CheckListException (org.mifos.customers.checklist.exceptions.CheckListException)8 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)5 Test (org.junit.Test)4 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)4 CustomerLevelEntity (org.mifos.customers.business.CustomerLevelEntity)4 MifosUser (org.mifos.security.MifosUser)4 UserContext (org.mifos.security.util.UserContext)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 ProductTypeEntity (org.mifos.accounts.productdefinition.business.ProductTypeEntity)2 ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)2 AccountCheckListBO (org.mifos.customers.checklist.business.AccountCheckListBO)2 CustomerCheckListBO (org.mifos.customers.checklist.business.CustomerCheckListBO)2 CheckListPersistence (org.mifos.customers.checklist.persistence.CheckListPersistence)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 ServiceException (org.mifos.framework.exceptions.ServiceException)2 ArrayList (java.util.ArrayList)1 CustomerLevel (org.mifos.customers.api.CustomerLevel)1