Search in sources :

Example 6 with SandBox

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

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

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

Example 9 with SandBox

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

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

the class BroadleafRequestProcessor method process.

@Override
public void process(WebRequest request) {
    BroadleafRequestContext brc = new BroadleafRequestContext();
    brc.getAdditionalProperties().putAll(entityExtensionManagers);
    Site site = siteResolver.resolveSite(request);
    brc.setNonPersistentSite(site);
    brc.setWebRequest(request);
    if (site == null) {
        brc.setIgnoreSite(true);
    }
    brc.setAdmin(false);
    if (siteStrictValidateProductionChanges) {
        brc.setValidateProductionChangesState(ValidateProductionChangesState.SITE);
    } else {
        brc.setValidateProductionChangesState(ValidateProductionChangesState.UNDEFINED);
    }
    BroadleafRequestContext.setBroadleafRequestContext(brc);
    Locale locale = localeResolver.resolveLocale(request);
    brc.setLocale(locale);
    TimeZone timeZone = broadleafTimeZoneResolver.resolveTimeZone(request);
    BroadleafRequestedCurrencyDto currencyDto = currencyResolver.resolveCurrency(request);
    // Assumes BroadleafProcess
    RequestDTO requestDTO = (RequestDTO) request.getAttribute(REQUEST_DTO_PARAM_NAME, WebRequest.SCOPE_REQUEST);
    if (requestDTO == null) {
        requestDTO = new RequestDTOImpl(request);
    }
    SandBox currentSandbox = sandboxResolver.resolveSandBox(request, site);
    // When a user elects to switch his sandbox, we want to invalidate the current session. We'll then redirect the
    // user to the current URL so that the configured filters trigger again appropriately.
    Boolean reprocessRequest = (Boolean) request.getAttribute(BroadleafRequestProcessor.REPROCESS_PARAM_NAME, WebRequest.SCOPE_REQUEST);
    if (reprocessRequest != null && reprocessRequest) {
        LOG.debug("Reprocessing request");
        if (request instanceof ServletWebRequest) {
            HttpServletRequest hsr = ((ServletWebRequest) request).getRequest();
            clearBroadleafSessionAttrs(request);
            StringBuffer url = hsr.getRequestURL();
            HttpServletResponse response = ((ServletWebRequest) request).getResponse();
            try {
                if (!isUrlValid(url.toString())) {
                    LOG.error("SECURITY FAILURE Bad redirect location: " + StringUtil.sanitize(url.toString()));
                    response.sendError(403);
                    return;
                }
                String sandboxId = hsr.getParameter(SANDBOX_ID_PARAM);
                if (isSandboxIdValid(sandboxId)) {
                    String queryString = "?" + SANDBOX_ID_PARAM + "=" + sandboxId;
                    url.append(queryString);
                }
                response.sendRedirect(url.toString());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            throw new HaltFilterChainException("Reprocess required, redirecting user");
        }
    }
    if (!siteDisableSandboxPreview && currentSandbox != null) {
        SandBoxContext previewSandBoxContext = new SandBoxContext();
        previewSandBoxContext.setSandBoxId(currentSandbox.getId());
        previewSandBoxContext.setPreviewMode(true);
        SandBoxContext.setSandBoxContext(previewSandBoxContext);
    }
    if (currencyDto != null) {
        brc.setBroadleafCurrency(currencyDto.getCurrencyToUse());
        brc.setRequestedBroadleafCurrency(currencyDto.getRequestedCurrency());
    }
    // is used in a different session that it was initiated in. see QA#2576
    if (currentSandbox != null && currentSandbox.getChildSandBoxes() != null) {
        currentSandbox.getChildSandBoxes().size();
    }
    brc.setSandBox(currentSandbox);
    brc.setDeployBehavior(deployBehaviorUtil.isProductionSandBoxMode() ? DeployBehavior.CLONE_PARENT : DeployBehavior.OVERWRITE_PARENT);
    // Note that this must happen after the request context is set up as resolving a theme is dependent on site
    Theme theme = themeResolver.resolveTheme(request);
    brc.setTheme(theme);
    brc.setMessageSource(messageSource);
    brc.setTimeZone(timeZone);
    brc.setRequestDTO(requestDTO);
    Map<String, Object> ruleMap = (Map<String, Object>) request.getAttribute("blRuleMap", WebRequest.SCOPE_REQUEST);
    if (ruleMap == null) {
        LOG.trace("Creating ruleMap and adding in Locale.");
        ruleMap = new HashMap<String, Object>();
        request.setAttribute("blRuleMap", ruleMap, WebRequest.SCOPE_REQUEST);
    } else {
        LOG.trace("Using pre-existing ruleMap - added by non standard BLC process.");
    }
    ruleMap.put("locale", locale);
    String adminUserId = request.getParameter(BroadleafRequestFilter.ADMIN_USER_ID_PARAM_NAME);
    if (StringUtils.isNotBlank(adminUserId)) {
        // TODO: Add token logic to secure the admin user id
        brc.setAdminUserId(Long.parseLong(adminUserId));
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Locale(org.broadleafcommerce.common.locale.domain.Locale) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) BroadleafRequestedCurrencyDto(org.broadleafcommerce.common.currency.domain.BroadleafRequestedCurrencyDto) HttpServletRequest(javax.servlet.http.HttpServletRequest) TimeZone(java.util.TimeZone) RequestDTOImpl(org.broadleafcommerce.common.RequestDTOImpl) HaltFilterChainException(org.broadleafcommerce.common.web.exception.HaltFilterChainException) RequestDTO(org.broadleafcommerce.common.RequestDTO) Theme(org.broadleafcommerce.common.site.domain.Theme) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) HashMap(java.util.HashMap) Map(java.util.Map)

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