Search in sources :

Example 56 with BroadleafRequestContext

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

the class AdminAuditableListener method setAuditValueAgent.

@Override
protected void setAuditValueAgent(Field field, Object entity) throws IllegalArgumentException, IllegalAccessException {
    try {
        BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
        if (context != null && context.getAdmin() && context.getAdminUserId() != null) {
            field.setAccessible(true);
            field.set(entity, context.getAdminUserId());
        }
    } catch (IllegalStateException e) {
    // do nothing
    } catch (Exception e) {
        LOG.error("Error setting admin audit field.", e);
    }
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 57 with BroadleafRequestContext

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

the class StructuredContentServiceImpl method buildNameKey.

protected String buildNameKey(SandBox sandBox, StructuredContent sc, Boolean secure) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = (context != null) ? context.getNonPersistentSite() : null;
    Long siteId = (site != null) ? site.getId() : null;
    Locale locale = findLanguageOnlyLocale(sc.getLocale());
    String contentType = sc.getStructuredContentType().getName();
    String contentName = sc.getContentName() + "-" + sc.getId();
    return buildNameKey(sandBox, siteId, locale, contentType, contentName, secure);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Locale(org.broadleafcommerce.common.locale.domain.Locale) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 58 with BroadleafRequestContext

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

the class StructuredContentServiceImpl method buildTypeKey.

protected String buildTypeKey(SandBox sandBox, StructuredContent sc) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = (context != null) ? context.getNonPersistentSite() : null;
    Long siteId = (site != null) ? site.getId() : null;
    Locale locale = findLanguageOnlyLocale(sc.getLocale());
    String contentType = sc.getStructuredContentType().getName();
    return buildTypeKey(sandBox, siteId, locale, contentType);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Locale(org.broadleafcommerce.common.locale.domain.Locale) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 59 with BroadleafRequestContext

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

the class StructuredContentServiceImpl method getStructuredContentItemsByContentName.

@Override
public List<StructuredContentDTO> getStructuredContentItemsByContentName(String contentName, Locale locale, 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, "any", contentName, secure);
    cacheKey = cacheKey + "-" + secure;
    if (context.isProductionSandBox()) {
        contentDTOList = getStructuredContentListFromCache(cacheKey);
    }
    if (contentDTOList == null) {
        List<StructuredContent> productionContentList = structuredContentDao.findActiveStructuredContentByName(contentName, locale, languageOnlyLocale);
        contentDTOList = buildStructuredContentDTOList(productionContentList, secure);
        if (context.isProductionSandBox()) {
            addStructuredContentListToCache(cacheKey, contentDTOList);
        }
    }
    return contentDTOList;
}
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 60 with BroadleafRequestContext

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

the class StructuredContentServiceImpl method convertToDtos.

@Override
public List<StructuredContentDTO> convertToDtos(List<StructuredContent> scs, boolean isSecure) {
    List<StructuredContentDTO> contentDTOList = new ArrayList<>();
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    SandBox sandbox = context.getSandBox();
    boolean isProductionSandbox = context.isProductionSandBox();
    StructuredContentDTO dto;
    for (StructuredContent sc : scs) {
        String cacheKey = buildNameKey(sandbox, sc, isSecure);
        dto = null;
        if (isProductionSandbox) {
            dto = getSingleStructuredContentFromCache(cacheKey);
        }
        if (dto == null) {
            dto = buildStructuredContentDTO(sc, isSecure);
            if (isProductionSandbox) {
                addSingleStructuredContentToCache(cacheKey, dto);
            }
        }
        contentDTOList.add(dto);
    }
    return contentDTOList;
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) StructuredContentDTO(org.broadleafcommerce.common.structure.dto.StructuredContentDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ArrayList(java.util.ArrayList) 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