Search in sources :

Example 6 with PrdOfferingBO

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

the class AdminServiceFacadeWebTier method createOrUpdateProductMix.

@Override
public void createOrUpdateProductMix(Integer productId, List<Integer> notAllowedProductIds) {
    try {
        PrdOfferingBO product = new PrdOfferingPersistence().getPrdOfferingByID(productId.shortValue());
        StaticHibernateUtil.startTransaction();
        product.setPrdMixFlag(YesNoFlag.YES.getValue());
        applicationConfigurationDao.save(product);
        StaticHibernateUtil.flushSession();
        List<PrdOfferingBO> newNotAllowedProducts = new ArrayList<PrdOfferingBO>();
        for (Integer notAllowedProductId : notAllowedProductIds) {
            PrdOfferingBO notAllowedProduct = new PrdOfferingPersistence().getPrdOfferingByID(notAllowedProductId.shortValue());
            newNotAllowedProducts.add(notAllowedProduct);
        }
        for (ProductMixBO oldNotAllowedProduct : product.getCollectionProductMix()) {
            ProductMixBO productMix = legacyProductMixDao.getPrdOfferingMixByPrdOfferingID(productId.shortValue(), oldNotAllowedProduct.getPrdOfferingNotAllowedId().getPrdOfferingId());
            if (null != productMix) {
                applicationConfigurationDao.delete(productMix);
                StaticHibernateUtil.flushSession();
            }
            ProductMixBO alternateproductmix = legacyProductMixDao.getPrdOfferingMixByPrdOfferingID(oldNotAllowedProduct.getPrdOfferingNotAllowedId().getPrdOfferingId(), productId.shortValue());
            if (null != alternateproductmix) {
                applicationConfigurationDao.delete(alternateproductmix);
                StaticHibernateUtil.flushSession();
            }
        }
        for (PrdOfferingBO notAllowedProduct : newNotAllowedProducts) {
            ProductMixBO productMix = new ProductMixBO(product, notAllowedProduct);
            productMix.setUpdatedDate(new DateTime().toDate());
            productMix.setUpdatedBy(Short.valueOf("1"));
            applicationConfigurationDao.save(productMix);
            StaticHibernateUtil.flushSession();
        }
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) PrdOfferingBO(org.mifos.accounts.productdefinition.business.PrdOfferingBO) ArrayList(java.util.ArrayList) ProductMixBO(org.mifos.accounts.productsmix.business.ProductMixBO) DateTime(org.joda.time.DateTime) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

PrdOfferingBO (org.mifos.accounts.productdefinition.business.PrdOfferingBO)6 ArrayList (java.util.ArrayList)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 PrdOfferingPersistence (org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence)3 PrdOfferingDto (org.mifos.dto.domain.PrdOfferingDto)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 ServiceException (org.mifos.framework.exceptions.ServiceException)3 ProductMixBusinessService (org.mifos.accounts.productsmix.business.service.ProductMixBusinessService)2 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 ProductCategoryBO (org.mifos.accounts.productdefinition.business.ProductCategoryBO)1 ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)1 ProductMixBO (org.mifos.accounts.productsmix.business.ProductMixBO)1 SavingsProductDto (org.mifos.dto.domain.SavingsProductDto)1 ProductCategoryTypeDto (org.mifos.dto.screen.ProductCategoryTypeDto)1 ProductDto (org.mifos.dto.screen.ProductDto)1 ProductMixDetailsDto (org.mifos.dto.screen.ProductMixDetailsDto)1 ProductMixDto (org.mifos.dto.screen.ProductMixDto)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 SystemException (org.mifos.framework.exceptions.SystemException)1