use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method createUserSandBox.
@Override
public SandBox createUserSandBox(Long authorId, SandBox approvalSandBox) {
TransactionStatus status = TransactionUtils.createTransaction("createSandBox", TransactionDefinition.PROPAGATION_REQUIRES_NEW, transactionManager);
try {
SandBox userSandBox = new SandBoxImpl();
userSandBox.setName(approvalSandBox.getName());
userSandBox.setAuthor(authorId);
userSandBox.setParentSandBox(approvalSandBox);
userSandBox.setSandBoxType(SandBoxType.USER);
userSandBox = persist(userSandBox);
SandBoxManagement mgmt = new SandBoxManagementImpl();
mgmt.setSandBox(userSandBox);
sandBoxEntityManager.persist(mgmt);
sandBoxEntityManager.flush();
TransactionUtils.finalizeTransaction(status, transactionManager, false);
return userSandBox;
} catch (Exception ex) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw new RuntimeException(ex);
}
}
use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method retrieveSandBoxesForAuthor.
@Override
public List<SandBox> retrieveSandBoxesForAuthor(Long authorId, SandBoxType sandBoxType) {
CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder();
CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class);
Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class);
criteria.select(sandbox.get("sandBox").as(SandBox.class));
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(sandbox.get("sandBox").get("author"), authorId));
restrictions.add(builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")));
if (sandBoxType != null) {
restrictions.add(builder.equal(sandbox.get("sandBox").get("sandboxType"), sandBoxType.getType()));
}
restrictions.add(builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y')));
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria);
return query.getResultList();
}
use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method retrieveChildSandBoxesByParentId.
@Override
public List<SandBox> retrieveChildSandBoxesByParentId(Long parentSandBoxId) {
CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder();
CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class);
Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class);
criteria.select(sandbox.get("sandBox").as(SandBox.class));
criteria.where(builder.and(sandbox.get("sandBox").get("parentSandBox").in(parentSandBoxId), builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")), builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y'))));
TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria);
return query.getResultList();
}
use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method retrieveAllSandBoxes.
@Override
public List<SandBox> retrieveAllSandBoxes() {
CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder();
CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class);
Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class);
criteria.select(sandbox.get("sandBox").as(SandBox.class));
criteria.where(builder.and(builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")), builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y'))));
TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria);
return query.getResultList();
}
use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method retrieveUserSandBoxForParent.
@Override
public SandBox retrieveUserSandBoxForParent(Long authorId, Long parentSandBoxId) {
CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder();
CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class);
Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class);
criteria.select(sandbox.get("sandBox").as(SandBox.class));
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(sandbox.get("sandBox").get("sandboxType"), SandBoxType.USER.getType()));
restrictions.add(builder.or(builder.equal(sandbox.get("sandBox").get("author"), authorId), builder.isNull(sandbox.get("sandBox").get("author"))));
restrictions.add(builder.equal(sandbox.get("sandBox").get("parentSandBox").get("id"), parentSandBoxId));
restrictions.add(builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")));
restrictions.add(builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y')));
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria);
List<SandBox> results = query.getResultList();
SandBox response;
if (results == null || results.size() == 0) {
response = null;
} else {
response = results.get(0);
}
return response;
}
Aggregations