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