Search in sources :

Example 6 with SandBoxManagementImpl

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);
    }
}
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 7 with SandBoxManagementImpl

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();
}
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 8 with SandBoxManagementImpl

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

Example 9 with SandBoxManagementImpl

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

Example 10 with SandBoxManagementImpl

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

Aggregations

SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)11 SandBoxManagementImpl (org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl)11 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 ArrayList (java.util.ArrayList)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 HashMap (java.util.HashMap)1