Search in sources :

Example 1 with CheckListException

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

Example 2 with CheckListException

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

the class CheckListServiceFacadeWebTier method updateCustomerChecklist.

@Override
public void updateCustomerChecklist(Short checklistId, Short levelId, Short stateId, Short checklistStatus, String checklistName, List<String> details) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    CustomerLevelEntity customerLevelEntity = new CustomerLevelEntity(CustomerLevel.getLevel(levelId));
    CustomerStatusEntity customerStatusEntity = new CustomerStatusEntity(stateId);
    try {
        hibernateTransactionHelper.startTransaction();
        CustomerCheckListBO customerCheckList = (CustomerCheckListBO) new CheckListPersistence().getCheckList(checklistId);
        customerCheckList.update(customerLevelEntity, customerStatusEntity, checklistName, checklistStatus, details, userContext.getLocaleId(), userContext.getId());
        customerDao.save(customerCheckList);
        hibernateTransactionHelper.commitTransaction();
    } 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 : CustomerCheckListBO(org.mifos.customers.checklist.business.CustomerCheckListBO) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) CheckListPersistence(org.mifos.customers.checklist.persistence.CheckListPersistence) CustomerLevelEntity(org.mifos.customers.business.CustomerLevelEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 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 4 with CheckListException

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

the class CheckListBOIntegrationTest method testCreateCheckListExceptionForCustomer.

@Test
public void testCreateCheckListExceptionForCustomer() 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, getCheckListDetails(), (short) 1, (short) 1);
        Assert.fail();
    } catch (CheckListException ce) {
        Assert.assertTrue(true);
    }
}
Also used : CustomerLevelEntity(org.mifos.customers.business.CustomerLevelEntity) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) CheckListException(org.mifos.customers.checklist.exceptions.CheckListException) Test(org.junit.Test)

Example 5 with CheckListException

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

the class CheckListBOIntegrationTest method testUpdateCustomerCheckListInvalidState.

@Test
public void testUpdateCustomerCheckListInvalidState() throws Exception {
    CustomerCheckListBO customerCheckList1 = TestObjectFactory.createCustomerChecklist(CustomerLevel.CENTER.getValue(), CustomerStatus.CENTER_INACTIVE.getValue(), CheckListConstants.STATUS_ACTIVE);
    customerCheckList = TestObjectFactory.createCustomerChecklist(CustomerLevel.CENTER.getValue(), CustomerStatus.CENTER_ACTIVE.getValue(), CheckListConstants.STATUS_ACTIVE);
    CustomerStatusEntity customerStatusEntity = new CustomerStatusEntity(CustomerStatus.fromInt(CustomerStatus.CENTER_INACTIVE.getValue()));
    StaticHibernateUtil.flushSession();
    customerCheckList = (CustomerCheckListBO) TestObjectFactory.getObject(CustomerCheckListBO.class, customerCheckList.getChecklistId());
    try {
        customerCheckList.update(customerCheckList.getCustomerLevel(), customerStatusEntity, "Customer CheckList", CheckListConstants.STATUS_INACTIVE, getCheckListDetails(), (short) 1, (short) 1);
        Assert.fail();
    } catch (CheckListException ce) {
        Assert.assertTrue(true);
    } finally {
        TestObjectFactory.deleteChecklist(customerCheckList1);
        StaticHibernateUtil.flushSession();
    }
}
Also used : 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