Search in sources :

Example 11 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class BreadcrumbVariableExpression method getParams.

protected Map<String, String[]> getParams() {
    Map<String, String[]> paramMap = new HashMap<>();
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null) {
        paramMap = BroadleafRequestContext.getRequestParameterMap();
        if (paramMap != null) {
            paramMap = new HashMap<>(paramMap);
        }
    }
    return paramMap;
}
Also used : HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 12 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class AssetURLVariableExpression method fixUrl.

/**
 * This method will resolve image urls located in HTML.
 * @see StaticAssetPathService#convertAllAssetPathsInContent(String, boolean)
 * @param content
 * @return
 */
public String fixUrl(String content) {
    boolean isSecure = false;
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null) {
        isSecure = brc.getRequest().isSecure();
    }
    return staticAssetPathService.convertAllAssetPathsInContent(content, isSecure);
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 13 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class SolrIndexDaoImpl method populateProductCatalogStructure.

@Override
public void populateProductCatalogStructure(List<Long> productIds, CatalogStructure catalogStructure) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Boolean oldIgnoreFilters = context.getInternalIgnoreFilters();
    context.setInternalIgnoreFilters(false);
    try {
        Map<Long, Set<Long>> parentCategoriesByProduct = new HashMap<>();
        Map<Long, Set<Long>> parentCategoriesByCategory = new HashMap<>();
        Long[] products = productIds.toArray(new Long[productIds.size()]);
        BiMap<Long, Long> sandBoxProductToOriginalMap = sandBoxHelper.getSandBoxToOriginalMap(ProductImpl.class, products);
        int batchSize = 800;
        int count = 0;
        int pos = 0;
        while (pos < products.length) {
            int remaining = products.length - pos;
            int mySize = remaining > batchSize ? batchSize : remaining;
            Long[] temp = new Long[mySize];
            System.arraycopy(products, pos, temp, 0, mySize);
            // context.getAdditionalProperties().put("constrainedFilterGroups", Arrays.asList("archivedFilter"));
            TypedQuery<ParentCategoryByProduct> query = em.createNamedQuery("BC_READ_PARENT_CATEGORY_IDS_BY_PRODUCTS", ParentCategoryByProduct.class);
            query.setParameter("productIds", sandBoxHelper.mergeCloneIds(ProductImpl.class, temp));
            List<ParentCategoryByProduct> results = query.getResultList();
            // context.getAdditionalProperties().remove("constrainedFilterGroups");
            for (ParentCategoryByProduct item : results) {
                Long sandBoxProductVal = item.getProduct();
                BiMap<Long, Long> reverse = sandBoxProductToOriginalMap.inverse();
                if (reverse.containsKey(sandBoxProductVal)) {
                    sandBoxProductVal = reverse.get(sandBoxProductVal);
                }
                if (!catalogStructure.getParentCategoriesByProduct().containsKey(sandBoxProductVal)) {
                    if (!parentCategoriesByProduct.containsKey(sandBoxProductVal)) {
                        parentCategoriesByProduct.put(sandBoxProductVal, new HashSet<Long>());
                    }
                    // We only want the sandbox parent - if applicable
                    // Long sandBoxVal = sandBoxHelper.getCombinedSandBoxVersionId(CategoryImpl.class, item.getParent());
                    Long sandBoxVal = sandBoxHelper.getSandBoxVersionId(CategoryImpl.class, item.getCategory());
                    if (sandBoxVal == null) {
                        sandBoxVal = item.getCategory();
                    }
                    parentCategoriesByProduct.get(sandBoxProductVal).add(sandBoxVal);
                }
                // Cache the display order bigdecimals
                BigDecimal displayOrder = (item.getDisplayOrder() == null) ? new BigDecimal("1.00000") : item.getDisplayOrder();
                catalogStructure.getDisplayOrdersByCategoryProduct().put(item.getCategory() + "-" + item.getProduct(), displayOrder);
            }
            for (Map.Entry<Long, Set<Long>> entry : parentCategoriesByProduct.entrySet()) {
                for (Long categoryId : entry.getValue()) {
                    if (!catalogStructure.getParentCategoriesByCategory().containsKey(categoryId)) {
                        Set<Long> hierarchy = new HashSet<>();
                        parentCategoriesByCategory.put(categoryId, hierarchy);
                    }
                }
            }
            count++;
            pos = (count * batchSize) < products.length ? (count * batchSize) : products.length;
        }
        readFullCategoryHierarchy(parentCategoriesByCategory, new HashSet<Long>());
        catalogStructure.getParentCategoriesByProduct().putAll(parentCategoriesByProduct);
        catalogStructure.getParentCategoriesByCategory().putAll(parentCategoriesByCategory);
    } finally {
        context.setInternalIgnoreFilters(oldIgnoreFilters);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) BigDecimal(java.math.BigDecimal) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 14 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class StructuredContentServiceImpl method lookupStructuredContentItemsByType.

@Override
public List<StructuredContentDTO> lookupStructuredContentItemsByType(StructuredContentType contentType, Locale locale, Integer count, Map<String, Object> ruleDTOs, boolean secure) {
    List<StructuredContentDTO> contentDTOList = null;
    Locale languageOnlyLocale = findLanguageOnlyLocale(locale);
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Long site = (context.getNonPersistentSite() != null) ? context.getNonPersistentSite().getId() : null;
    String cacheKey = buildTypeKeyWithSecure(context.getSandBox(), site, languageOnlyLocale, contentType.getName(), secure);
    if (context.isProductionSandBox()) {
        contentDTOList = getStructuredContentListFromCache(cacheKey);
    }
    if (contentDTOList == null) {
        List<StructuredContent> contentList = structuredContentDao.findActiveStructuredContentByType(contentType, locale, languageOnlyLocale);
        contentDTOList = buildStructuredContentDTOList(contentList, secure);
        if (context.isProductionSandBox()) {
            addStructuredContentListToCache(cacheKey, contentDTOList);
        }
    }
    return evaluateAndPriortizeContent(contentDTOList, count, ruleDTOs);
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) StructuredContentDTO(org.broadleafcommerce.common.structure.dto.StructuredContentDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent)

Example 15 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class StructuredContentServiceImpl method lookupStructuredContentItemsByName.

@Override
public List<StructuredContentDTO> lookupStructuredContentItemsByName(StructuredContentType contentType, String contentName, Locale locale, Integer count, Map<String, Object> ruleDTOs, boolean secure) {
    List<StructuredContentDTO> contentDTOList = null;
    Locale languageOnlyLocale = findLanguageOnlyLocale(locale);
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Long site = (context.getNonPersistentSite() != null) ? context.getNonPersistentSite().getId() : null;
    String cacheKey = buildNameKey(context.getSandBox(), site, languageOnlyLocale, contentType.getName(), contentName, secure);
    if (context.isProductionSandBox()) {
        contentDTOList = getStructuredContentListFromCache(cacheKey);
    }
    if (contentDTOList == null) {
        List<StructuredContent> productionContentList = structuredContentDao.findActiveStructuredContentByNameAndType(contentType, contentName, locale, languageOnlyLocale);
        contentDTOList = buildStructuredContentDTOList(productionContentList, secure);
        if (context.isProductionSandBox()) {
            addStructuredContentListToCache(cacheKey, contentDTOList);
        }
    }
    return evaluateAndPriortizeContent(contentDTOList, count, ruleDTOs);
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) StructuredContentDTO(org.broadleafcommerce.common.structure.dto.StructuredContentDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2