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();
}
}
Aggregations