Search in sources :

Example 16 with SandBox

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) SandBoxManagementImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl)

Example 17 with SandBox

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) ArrayList(java.util.ArrayList) SandBoxManagementImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl) Predicate(javax.persistence.criteria.Predicate)

Example 18 with SandBox

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);
    }
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) SandBoxManagement(org.broadleafcommerce.common.sandbox.domain.SandBoxManagement) TransactionStatus(org.springframework.transaction.TransactionStatus) SandBoxImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxImpl) SandBoxManagementImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl)

Example 19 with SandBox

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;
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) ArrayList(java.util.ArrayList)

Example 20 with SandBox

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);
    }
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)24 SandBoxManagementImpl (org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl)11 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 ArrayList (java.util.ArrayList)6 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)5 Site (org.broadleafcommerce.common.site.domain.Site)4 HashMap (java.util.HashMap)3 Predicate (javax.persistence.criteria.Predicate)3 SandBoxImpl (org.broadleafcommerce.common.sandbox.domain.SandBoxImpl)3 SandBoxManagement (org.broadleafcommerce.common.sandbox.domain.SandBoxManagement)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 RequestDTOImpl (org.broadleafcommerce.common.RequestDTOImpl)2 Locale (org.broadleafcommerce.common.locale.domain.Locale)2 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1