Search in sources :

Example 6 with ProductCategoryBusinessService

use of org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService 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 7 with ProductCategoryBusinessService

use of org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService in project head by mifos.

the class ProductCategoryBOIntegrationTest method testCreateProductCategory.

@Test
public void testCreateProductCategory() throws SystemException, ApplicationException {
    UserContext userContext = TestUtils.makeUser();
    List<ProductTypeEntity> productTypeList = new ProductCategoryBusinessService().getProductTypes();
    Assert.assertEquals(2, productTypeList.size());
    TestObjectFactory.updateObject(new ProductCategoryBO(userContext, productTypeList.get(0), "product category", null));
    ProductCategoryBO productCategoryBO = getProductCategory().get(2);
    Assert.assertEquals("1-003", productCategoryBO.getGlobalPrdCategoryNum());
    Assert.assertEquals("product category", productCategoryBO.getProductCategoryName());
    Assert.assertNull(productCategoryBO.getProductCategoryDesc());
    Assert.assertNotNull(productCategoryBO.getProductType());
    try {
        TestObjectFactory.updateObject(new ProductCategoryBO(userContext, productTypeList.get(0), "product category", null));
        Assert.fail();
    } catch (ProductDefinitionException expected) {
        Assert.assertEquals(ProductDefinitionConstants.DUPLICATE_CATEGORY_NAME, expected.getKey());
    }
    deleteProductCategory(productCategoryBO);
}
Also used : UserContext(org.mifos.security.util.UserContext) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) ProductCategoryBusinessService(org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService) Test(org.junit.Test)

Example 8 with ProductCategoryBusinessService

use of org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService in project head by mifos.

the class ProductCategoryBOIntegrationTest method testUpdateProductCategory.

@Test
public void testUpdateProductCategory() throws SystemException, ApplicationException {
    UserContext userContext = TestUtils.makeUser();
    List<ProductTypeEntity> productTypeList = new ProductCategoryBusinessService().getProductTypes();
    Assert.assertEquals(2, productTypeList.size());
    TestObjectFactory.updateObject(new ProductCategoryBO(userContext, productTypeList.get(0), "product category", null));
    ProductCategoryBO productCategoryBO = getProductCategory().get(2);
    PrdCategoryStatusEntity prdCategoryStatusEntity = (PrdCategoryStatusEntity) TestObjectFactory.getObject(PrdCategoryStatusEntity.class, PrdCategoryStatus.INACTIVE.getValue());
    productCategoryBO.updateProductCategory("Category", "Name changed", prdCategoryStatusEntity);
    TestObjectFactory.updateObject(productCategoryBO);
    productCategoryBO = getProductCategory().get(2);
    Assert.assertEquals("1-003", productCategoryBO.getGlobalPrdCategoryNum());
    Assert.assertEquals("Category", productCategoryBO.getProductCategoryName());
    Assert.assertNotNull(productCategoryBO.getProductCategoryDesc());
    Assert.assertNotNull(productCategoryBO.getProductType());
    Assert.assertNotNull("Name changed", productCategoryBO.getProductCategoryDesc());
    productCategoryBO.updateProductCategory("Category", "Name changed", prdCategoryStatusEntity);
    // TODO: assert that it got updated.
    deleteProductCategory(productCategoryBO);
}
Also used : UserContext(org.mifos.security.util.UserContext) ProductCategoryBusinessService(org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService) Test(org.junit.Test)

Aggregations

ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 ServiceException (org.mifos.framework.exceptions.ServiceException)6 UserContext (org.mifos.security.util.UserContext)4 ArrayList (java.util.ArrayList)3 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)3 ProductTypeEntity (org.mifos.accounts.productdefinition.business.ProductTypeEntity)3 ProductCategoryTypeDto (org.mifos.dto.screen.ProductCategoryTypeDto)3 Test (org.junit.Test)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)2 AccountCheckListBO (org.mifos.customers.checklist.business.AccountCheckListBO)2 CheckListException (org.mifos.customers.checklist.exceptions.CheckListException)2 MifosUser (org.mifos.security.MifosUser)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 PrdOfferingBO (org.mifos.accounts.productdefinition.business.PrdOfferingBO)1 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)1 ProductMixBusinessService (org.mifos.accounts.productsmix.business.service.ProductMixBusinessService)1 CheckListPersistence (org.mifos.customers.checklist.persistence.CheckListPersistence)1 SavingsProductDto (org.mifos.dto.domain.SavingsProductDto)1