Search in sources :

Example 1 with SandBoxManagementImpl

use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.

the class SandBoxDaoImpl method retrieveSandboxNamesForSandBoxes.

@Override
public Map<Long, String> retrieveSandboxNamesForSandBoxes(Set<Long> sandBoxIds) {
    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.in(sandbox.get("sandBox").get("id")).value(sandBoxIds), 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);
    List<SandBox> results = query.getResultList();
    Map<Long, String> map = new HashMap<Long, String>();
    for (SandBox result : results) {
        map.put(result.getId(), result.getName());
    }
    return map;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) HashMap(java.util.HashMap) SandBoxManagementImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl)

Example 2 with SandBoxManagementImpl

use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.

the class SandBoxDaoImpl method retrieveNamedSandBox.

@Override
public SandBox retrieveNamedSandBox(SandBoxType sandBoxType, String sandboxName, Long authorId) {
    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.getType()));
    restrictions.add(builder.equal(sandbox.get("sandBox").get("name"), sandboxName));
    if (authorId != null) {
        restrictions.add(builder.equal(sandbox.get("sandBox").get("author"), authorId));
    }
    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);
    if (query.getResultList() != null && query.getResultList().size() == 1) {
        return query.getSingleResult();
    } else {
        return null;
    }
}
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 3 with SandBoxManagementImpl

use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.

the class SandBoxDaoImpl method createDefaultSandBox.

@Override
public SandBox createDefaultSandBox() {
    TransactionStatus status = TransactionUtils.createTransaction("createSandBox", TransactionDefinition.PROPAGATION_REQUIRES_NEW, transactionManager);
    try {
        SandBox defaultSB = new SandBoxImpl();
        defaultSB.setName("Default");
        defaultSB.setSandBoxType(SandBoxType.DEFAULT);
        defaultSB.setColor("#20C0F0");
        defaultSB = persist(defaultSB);
        SandBoxManagement mgmt = new SandBoxManagementImpl();
        mgmt.setSandBox(defaultSB);
        sandBoxEntityManager.persist(mgmt);
        sandBoxEntityManager.flush();
        TransactionUtils.finalizeTransaction(status, transactionManager, false);
        return defaultSB;
    } 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 4 with SandBoxManagementImpl

use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.

the class SandBoxDaoImpl method retrieveSandBoxesByType.

@Override
public List<SandBox> retrieveSandBoxesByType(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));
    criteria.where(builder.and(builder.equal(sandbox.get("sandBox").get("sandboxType"), sandboxType.getType()), 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 5 with SandBoxManagementImpl

use of org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl in project BroadleafCommerce by BroadleafCommerce.

the class SandBoxDaoImpl method retrieveSandBoxManagementById.

public SandBox retrieveSandBoxManagementById(Long sandBoxId) {
    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.equal(sandbox.get("sandBox").get("id"), sandBoxId), 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);
    List<SandBox> results = query.getResultList();
    if (results == null || results.size() == 0) {
        return null;
    }
    return results.get(0);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) SandBoxManagementImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxManagementImpl)

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