use of org.broadleafcommerce.cms.structure.domain.StructuredContent 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.cms.structure.domain.StructuredContent 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);
}
use of org.broadleafcommerce.cms.structure.domain.StructuredContent in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentDaoImpl method findAllContentItems.
@Override
public List<StructuredContent> findAllContentItems() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<StructuredContent> criteria = builder.createQuery(StructuredContent.class);
Root<StructuredContentImpl> sc = criteria.from(StructuredContentImpl.class);
criteria.select(sc);
try {
TypedQuery<StructuredContent> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
} catch (NoResultException e) {
return new ArrayList<StructuredContent>();
}
}
use of org.broadleafcommerce.cms.structure.domain.StructuredContent in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentTypeCustomPersistenceHandler method fetchDynamicEntity.
@Override
public Entity fetchDynamicEntity(Serializable root, List<String> dirtyFields, boolean includeId) throws Exception {
StructuredContent structuredContent = (StructuredContent) root;
Map<String, StructuredContentFieldXref> structuredContentFieldMap = structuredContent.getStructuredContentFieldXrefs();
Entity entity = new Entity();
entity.setType(new String[] { StructuredContentType.class.getName() });
List<Property> propertiesList = new ArrayList<Property>();
for (FieldGroup fieldGroup : structuredContent.getStructuredContentType().getStructuredContentFieldTemplate().getFieldGroups()) {
for (FieldDefinition def : fieldGroup.getFieldDefinitions()) {
Property property = new Property();
property.setName(def.getName());
String value = null;
if (!MapUtils.isEmpty(structuredContentFieldMap)) {
StructuredContentFieldXref structuredContentFieldXref = structuredContentFieldMap.get(def.getName());
if (structuredContentFieldXref != null) {
StructuredContentField structuredContentField = structuredContentFieldXref.getStructuredContentField();
if (structuredContentField != null) {
value = structuredContentField.getValue();
}
}
}
property.setValue(value);
if (!CollectionUtils.isEmpty(dirtyFields) && dirtyFields.contains(property.getName())) {
property.setIsDirty(true);
}
propertiesList.add(property);
}
}
if (includeId) {
Property property = new Property();
propertiesList.add(property);
property.setName("id");
property.setValue(String.valueOf(structuredContent.getId()));
}
entity.setProperties(propertiesList.toArray(new Property[] {}));
return entity;
}
use of org.broadleafcommerce.cms.structure.domain.StructuredContent in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentTypeCustomPersistenceHandler method fetchEntityBasedOnId.
@Override
public Entity fetchEntityBasedOnId(String structuredContentId, List<String> dirtyFields) throws Exception {
StructuredContent structuredContent = structuredContentService.findStructuredContentById(Long.valueOf(structuredContentId));
// Make sure the fieldmap is refreshed from the database based on any changes introduced in addOrUpdate()
em.refresh(structuredContent);
return fetchDynamicEntity(structuredContent, dirtyFields, true);
}
Aggregations