use of org.broadleafcommerce.common.sandbox.domain.SandBox 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.SandBox 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;
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxDaoImpl method createSandBox.
@Override
public SandBox createSandBox(String sandBoxName, SandBoxType sandBoxType) {
TransactionStatus status = TransactionUtils.createTransaction("createSandBox", TransactionDefinition.PROPAGATION_REQUIRES_NEW, transactionManager);
try {
SandBox approvalSandbox = retrieveNamedSandBox(sandBoxType, sandBoxName);
if (approvalSandbox == null) {
approvalSandbox = new SandBoxImpl();
approvalSandbox.setName(sandBoxName);
approvalSandbox.setSandBoxType(sandBoxType);
approvalSandbox = persist(approvalSandbox);
SandBoxManagement mgmt = new SandBoxManagementImpl();
mgmt.setSandBox(approvalSandbox);
sandBoxEntityManager.persist(mgmt);
sandBoxEntityManager.flush();
}
TransactionUtils.finalizeTransaction(status, transactionManager, false);
return approvalSandbox;
} catch (Exception ex) {
TransactionUtils.finalizeTransaction(status, transactionManager, true);
throw new RuntimeException(ex);
}
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxServiceImpl method retrievePreviewSandBoxes.
@Override
public List<SandBox> retrievePreviewSandBoxes(Long authorId) {
List<SandBox> returnList = new ArrayList<SandBox>();
List<SandBox> authorBoxes = sandBoxDao.retrieveSandBoxesForAuthor(authorId, SandBoxType.USER);
List<SandBox> approvalBoxes = sandBoxDao.retrieveSandBoxesByType(SandBoxType.APPROVAL);
List<SandBox> defaultBoxes = sandBoxDao.retrieveSandBoxesByType(SandBoxType.DEFAULT);
List<SandBox> candidateBoxes = new ArrayList<SandBox>();
candidateBoxes.addAll(approvalBoxes);
candidateBoxes.addAll(defaultBoxes);
returnList.addAll(authorBoxes);
for (SandBox cb : candidateBoxes) {
boolean match = false;
for (SandBox authorBox : authorBoxes) {
if (authorBox.getId().equals(cb.getId()) || (authorBox.getParentSandBox() != null && authorBox.getParentSandBox().getId().equals(cb.getId()))) {
match = true;
}
}
if (!match) {
returnList.add(cb);
}
}
return returnList;
}
use of org.broadleafcommerce.common.sandbox.domain.SandBox in project BroadleafCommerce by BroadleafCommerce.
the class SandBoxServiceImpl method archiveChildSandboxes.
@Override
@Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public void archiveChildSandboxes(Long parentSandBoxId) {
List<SandBox> childSandBoxes = retrieveChildSandBoxesByParentId(parentSandBoxId);
for (SandBox sandbox : childSandBoxes) {
sandbox.setArchived('Y');
sandBoxDao.merge(sandbox);
}
}
Aggregations