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