use of org.mifos.framework.hibernate.helper.HibernateTransactionHelper in project head by mifos.
the class AdminServiceFacadeWebTier method createSavingsProduct.
@Override
public PrdOfferingDto createSavingsProduct(SavingsProductDto savingsProductRequest) {
// enforced by integrity constraints on table also.
this.savingsProductDao.validateProductWithSameNameDoesNotExist(savingsProductRequest.getProductDetails().getName());
this.savingsProductDao.validateProductWithSameShortNameDoesNotExist(savingsProductRequest.getProductDetails().getShortName());
// domain rule validation - put on domain entity
validateStartDateIsNotBeforeToday(savingsProductRequest.getProductDetails().getStartDate());
validateStartDateIsNotOverOneYearFromToday(savingsProductRequest.getProductDetails().getStartDate());
validateEndDateIsPastStartDate(savingsProductRequest.getProductDetails().getStartDate(), savingsProductRequest.getProductDetails().getEndDate());
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
SavingsOfferingBO savingsProduct = new SavingsProductAssembler(this.loanProductDao, this.savingsProductDao, this.generalLedgerDao).fromDto(user, savingsProductRequest);
HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
try {
transactionHelper.startTransaction();
this.savingsProductDao.save(savingsProduct);
transactionHelper.commitTransaction();
return savingsProduct.toDto();
} catch (Exception e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
Aggregations