Search in sources :

Example 1 with StructuredContent

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);
}
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 2 with StructuredContent

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);
}
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 3 with StructuredContent

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>();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NoResultException(javax.persistence.NoResultException) StructuredContentImpl(org.broadleafcommerce.cms.structure.domain.StructuredContentImpl) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent)

Example 4 with 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;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) StructuredContentField(org.broadleafcommerce.cms.structure.domain.StructuredContentField) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ArrayList(java.util.ArrayList) StructuredContentType(org.broadleafcommerce.cms.structure.domain.StructuredContentType) StructuredContentFieldXref(org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXref) Property(org.broadleafcommerce.openadmin.dto.Property) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent)

Example 5 with StructuredContent

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);
}
Also used : StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent)

Aggregations

StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)9 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 ArrayList (java.util.ArrayList)4 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)4 Locale (org.broadleafcommerce.common.locale.domain.Locale)3 FieldDefinition (org.broadleafcommerce.cms.field.domain.FieldDefinition)2 FieldGroup (org.broadleafcommerce.cms.field.domain.FieldGroup)2 StructuredContentField (org.broadleafcommerce.cms.structure.domain.StructuredContentField)2 StructuredContentFieldXref (org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXref)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 Property (org.broadleafcommerce.openadmin.dto.Property)2 HashMap (java.util.HashMap)1 NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 StructuredContentFieldImpl (org.broadleafcommerce.cms.structure.domain.StructuredContentFieldImpl)1 StructuredContentFieldXrefImpl (org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXrefImpl)1 StructuredContentImpl (org.broadleafcommerce.cms.structure.domain.StructuredContentImpl)1 StructuredContentType (org.broadleafcommerce.cms.structure.domain.StructuredContentType)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)1