Search in sources :

Example 11 with SandBox

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

the class AbstractCacheMissAware method buildKey.

/**
 * Build the key representing this missed cache item. Will include sandbox and/or site information
 * if appropriate.
 *
 * @param params the appropriate params comprising a unique key for this cache item
 * @return the completed key
 */
protected String buildKey(String... params) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    SandBox sandBox = null;
    if (context != null) {
        sandBox = context.getSandBox();
    }
    String key = StringUtils.join(params, '_');
    if (sandBox != null) {
        key = sandBox.getId() + "_" + key;
    }
    Site site = context.getNonPersistentSite();
    if (site != null) {
        key = key + "_" + site.getId();
    }
    return key;
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 12 with SandBox

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

the class BroadleafAdminRequestProcessor method prepareSandBox.

protected void prepareSandBox(WebRequest request, BroadleafRequestContext brc) {
    AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
    if (adminUser == null) {
        // clear any sandbox
        if (BLCRequestUtils.isOKtoUseSession(request)) {
            request.removeAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
        }
    } else {
        SandBox sandBox = null;
        if (StringUtils.isNotBlank(request.getParameter(SANDBOX_REQ_PARAM))) {
            Long sandBoxId = Long.parseLong(request.getParameter(SANDBOX_REQ_PARAM));
            sandBox = sandBoxService.retrieveUserSandBoxForParent(adminUser.getId(), sandBoxId);
            if (sandBox == null) {
                SandBox approvalOrUserSandBox = sandBoxService.retrieveSandBoxManagementById(sandBoxId);
                if (approvalOrUserSandBox != null) {
                    if (approvalOrUserSandBox.getSandBoxType().equals(SandBoxType.USER)) {
                        sandBox = approvalOrUserSandBox;
                    } else {
                        sandBox = sandBoxService.createUserSandBox(adminUser.getId(), approvalOrUserSandBox);
                    }
                }
            }
            if (BLCRequestUtils.isOKtoUseSession(request)) {
                String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
                staleStateProtectionService.compareToken(token);
                staleStateProtectionService.invalidateState(true);
            }
        }
        if (sandBox == null) {
            Long previouslySetSandBoxId = null;
            if (BLCRequestUtils.isOKtoUseSession(request)) {
                previouslySetSandBoxId = (Long) request.getAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
            }
            if (previouslySetSandBoxId != null) {
                sandBox = sandBoxService.retrieveSandBoxManagementById(previouslySetSandBoxId);
            }
        }
        if (sandBox == null) {
            List<SandBox> defaultSandBoxes = sandBoxService.retrieveSandBoxesByType(SandBoxType.DEFAULT);
            if (defaultSandBoxes.size() > 1) {
                throw new IllegalStateException("Only one sandbox should be configured as default");
            }
            SandBox defaultSandBox;
            if (defaultSandBoxes.size() == 1) {
                defaultSandBox = defaultSandBoxes.get(0);
            } else {
                defaultSandBox = sandBoxService.createDefaultSandBox();
            }
            sandBox = sandBoxService.retrieveUserSandBoxForParent(adminUser.getId(), defaultSandBox.getId());
            if (sandBox == null) {
                sandBox = sandBoxService.createUserSandBox(adminUser.getId(), defaultSandBox);
            }
        }
        // If the user just changed sandboxes, we want to update the database record.
        Long previouslySetSandBoxId = null;
        if (BLCRequestUtils.isOKtoUseSession(request)) {
            previouslySetSandBoxId = (Long) request.getAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, WebRequest.SCOPE_GLOBAL_SESSION);
        }
        if (previouslySetSandBoxId != null && !sandBox.getId().equals(previouslySetSandBoxId)) {
            adminUser.setLastUsedSandBoxId(sandBox.getId());
            adminUser = adminSecurityService.saveAdminUser(adminUser);
        }
        if (BLCRequestUtils.isOKtoUseSession(request)) {
            request.setAttribute(BroadleafSandBoxResolver.SANDBOX_ID_VAR, sandBox.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
        }
        // is used in a different session that it was initiated in. see QA#2576
        if (sandBox != null && sandBox.getChildSandBoxes() != null) {
            sandBox.getChildSandBoxes().size();
        }
        brc.setSandBox(sandBox);
        brc.setDeployBehavior(deployBehaviorUtil.isProductionSandBoxMode() ? DeployBehavior.CLONE_PARENT : DeployBehavior.OVERWRITE_PARENT);
        brc.getAdditionalProperties().put("adminUser", adminUser);
    }
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser)

Example 13 with SandBox

use of org.broadleafcommerce.common.sandbox.domain.SandBox 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 14 with SandBox

use of org.broadleafcommerce.common.sandbox.domain.SandBox 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 15 with SandBox

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

the class SandBoxDaoImpl method merge.

@Override
public SandBox merge(SandBox userSandBox) {
    SandBox response = sandBoxEntityManager.merge(userSandBox);
    sandBoxEntityManager.flush();
    return response;
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox)

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