Class DefaultContentItemService<P extends ContentItem>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.content.service.DefaultContentItemService<P>
All Implemented Interfaces:
ContentItemService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>, EventListener, org.springframework.context.ApplicationListener<ContentCacheInvalidationEvent>

public class DefaultContentItemService<P extends ContentItem> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements ContentItemService<P>, org.springframework.context.ApplicationListener<ContentCacheInvalidationEvent>
Author:
Jon Fleschler (jfleschler)
  • Field Details

  • Constructor Details

    • DefaultContentItemService

      public DefaultContentItemService(ContentItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, FieldDataService<FieldData> fieldDataService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
  • Method Details

    • getRepositoryDomain

      public String getRepositoryDomain()
      Description copied from interface: ContentItemService
      Returns the name of the repository domain corresponding to the projection domain.
      Specified by:
      getRepositoryDomain in interface ContentItemService<P extends ContentItem>
      Returns:
      The name of the repository domain corresponding to the projection domain.
    • readAll

      public List<P> readAll(cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      readAll in interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P extends ContentItem>
      Overrides:
      readAll in class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P extends ContentItem>
    • readAllByNameWithActiveFlag

      public org.springframework.data.domain.Page<P> readAllByNameWithActiveFlag(@NonNull String activeFilter, @Nullable String nameQuery, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Read all content, filtered by active date ranges, optionally filtered by name.
      Specified by:
      readAllByNameWithActiveFlag in interface ContentItemService<P extends ContentItem>
      Parameters:
      activeFilter - whether to filter by active / inactive or all
      nameQuery - (optional) the content name to filter by
      filters - additional filters to apply in the query, can be null
      page - the requested page of results from the database
      context - context information surrounding sandboxing and multitenant state
      Returns:
      all menus, optionally filtered by name
    • readAllByUriIsNotBlank

      public org.springframework.data.domain.Page<P> readAllByUriIsNotBlank(@Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemService
      Read all non-null ContentItems
      Specified by:
      readAllByUriIsNotBlank in interface ContentItemService<P extends ContentItem>
      Parameters:
      page - the requested page of results from the database
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a page of non-null content items
    • readAllByName

      public org.springframework.data.domain.Page<P> readAllByName(@Nullable String nameQuery, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Read all ContentItems, optionally filtered by name.
      Specified by:
      readAllByName in interface ContentItemService<P extends ContentItem>
      Parameters:
      nameQuery - (optional) the content name to filter by
      filters - additional filters to apply in the query, can be null
      page - the requested page of results from the database
      context - context information surrounding sandboxing and multitenant state
      Returns:
      all ContentItems, optionally filtered by name
    • readAllByNameIn

      public List<P> readAllByNameIn(@NonNull @NonNull Collection<String> names, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Reads all ContentItems matching the given names.
      Specified by:
      readAllByNameIn in interface ContentItemService<P extends ContentItem>
      Parameters:
      names - Names of the ContentItems to retrieve.
      filters - additional filters to apply in the query, can be null
      context - context information surrounding sandboxing and multitenant state
      Returns:
      All ContentItems matching the given names.
    • readPageByNameIn

      public org.springframework.data.domain.Page<P> readPageByNameIn(@NonNull @NonNull Collection<String> names, @NonNull @NonNull org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Reads all ContentItems matching the given names.
      Specified by:
      readPageByNameIn in interface ContentItemService<P extends ContentItem>
      Parameters:
      names - Names of the ContentItems to retrieve.
      page - the requested page of results from the database
      filters - additional filters to apply in the query, can be null
      context - context information surrounding sandboxing and multitenant state
      Returns:
      A page of all ContentItems matching the given names.
    • readAllByIdIn

      public List<P> readAllByIdIn(@NonNull @NonNull Collection<String> ids, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Reads all ContentItems matching the given ids.
      Specified by:
      readAllByIdIn in interface ContentItemService<P extends ContentItem>
      Parameters:
      ids - Names of the ContentItems to retrieve.
      filters - additional filters to apply in the query, can be null
      context - context information surrounding sandboxing and multitenant state
      Returns:
      All ContentItems matching the given ids.
    • readPageByIdIn

      public org.springframework.data.domain.Page<P> readPageByIdIn(@NonNull @NonNull Collection<String> ids, @NonNull @NonNull org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Reads all ContentItems matching the given ids.
      Specified by:
      readPageByIdIn in interface ContentItemService<P extends ContentItem>
      Parameters:
      ids - Names of the ContentItems to retrieve.
      page - the requested page of results from the database
      filters - additional filters to apply in the query, can be null
      context - context information surrounding sandboxing and multitenant state
      Returns:
      A page of all ContentItems matching the given ids.
    • readPageByModelId

      public org.springframework.data.domain.Page<P> readPageByModelId(String modelId, @NonNull @NonNull org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Read all content for a specific model.
      Specified by:
      readPageByModelId in interface ContentItemService<P extends ContentItem>
      Parameters:
      modelId - the content's model id
      page - the requested page of results from the database
      filters - additional filters to apply in the query, can be null
      context - context information surrounding sandboxing and multitenant state
      Returns:
      a page of content items associated with a model
    • readByNameAndNotEmbedded

      public Optional<P> readByNameAndNotEmbedded(String contentName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemService
      Finds the non-embedded content item with the given name (should only be one result, as content names are unique in non-embedded items).
      Specified by:
      readByNameAndNotEmbedded in interface ContentItemService<P extends ContentItem>
      Parameters:
      contentName - the name of the content that should be retrieved
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      an Optional containing the content with the given name, empty if not found
    • readAllByModelId

      public List<P> readAllByModelId(@NonNull @NonNull String modelId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemService
      Read all content for a specific model.
      Specified by:
      readAllByModelId in interface ContentItemService<P extends ContentItem>
      Parameters:
      modelId - the content's model id
      filters - additional filters to apply in the query, can be null
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a list of content items associated with a model
    • create

      public P create(@NonNull P content, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends ContentItem>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ContentItem>
    • replace

      public P replace(@NonNull @NonNull String id, @NonNull P content, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends ContentItem>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ContentItem>
    • update

      public P update(String id, @NonNull P content, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends ContentItem>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ContentItem>
    • delete

      public void delete(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      delete in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends ContentItem>
      Overrides:
      delete in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ContentItem>
    • readByModelIdAndUri

      public Optional<P> readByModelIdAndUri(String modelId, String uri, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemService
      Retrieves the ContentItem by matching modelId and uri.
      Specified by:
      readByModelIdAndUri in interface ContentItemService<P extends ContentItem>
      Parameters:
      modelId - ID of the model the item belongs to
      uri - URI of the item
      contextInfo - Context information surrounding sandboxing and multitenant state
      Returns:
      The ContentItem by matching modelContextId and uri.
    • readByCombinedModelAndItemUri

      public Optional<P> readByCombinedModelAndItemUri(String uri, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemService
      Takes the given uri and returns the item where the combination of its URI and its ContentModel's URI matches.
      Specified by:
      readByCombinedModelAndItemUri in interface ContentItemService<P extends ContentItem>
      Parameters:
      uri - The URI to match against
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      A ContentItem if the combination of its and its parent model's URIs match uri.
    • readAllByQuery

      public org.springframework.data.domain.Page<P> readAllByQuery(@Nullable String query, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Read all content based on the provided query.
      Specified by:
      readAllByQuery in interface ContentItemService<P extends ContentItem>
      Parameters:
      query - the query to use to filter content
      filters - additional filters to apply in the query, can be null
      page - the requested page of results from the database
      context - context information surrounding sandboxing and multitenant state
      Returns:
      a page of content items matching the query
    • replaceAllItemTranslations

      public com.broadleafcommerce.translation.service.dto.TranslationsPayload replaceAllItemTranslations(String id, @NonNull @NonNull Locale locale, @NonNull @NonNull com.broadleafcommerce.translation.service.dto.TranslationsPayload request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ContentItemService
      Handles persistence of translations related to a ContentItem or its FieldData. FieldData don't have a separate endpoint but are otherwise treated as a separate entity. Therefore, this method is responsible for parsing the TranslationsPayload and pulling out the FieldData translations to be saved separately from the translation of direct ContentItem fields.
      Specified by:
      replaceAllItemTranslations in interface ContentItemService<P extends ContentItem>
      Parameters:
      id - Id of the ContentItem
      locale - Locale the translations map to
      request - TranslationsPayload
      context - Additional multitenant and sandbox info
      Returns:
      The updated translations.
    • readAllContentItemTags

      public Collection<ContentTag> readAllContentItemTags(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemService
      Read all tags associated with content items.
      Specified by:
      readAllContentItemTags in interface ContentItemService<P extends ContentItem>
      Parameters:
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a list of tags
    • removeFieldDataForContent

      protected void removeFieldDataForContent(@NonNull P content, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • replaceOrCreateFieldDataForContent

      protected void replaceOrCreateFieldDataForContent(@NonNull P content, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Create or replace FieldData for the passed in ContentItem
      Parameters:
      content - the content item to update
      context - information surrounding sandboxing and multitenant state
    • onApplicationEvent

      public void onApplicationEvent(ContentCacheInvalidationEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<P extends ContentItem>
    • fixAssetFields

      protected void fixAssetFields(ContentItem item)
      Converts Asset ContentField data from a Map to a ContentItemAsset. This is necessary for properly determining if an Asset content field has changed. Without this change, any update to any field on a Content Item will result in any Asset fields being marked as changed, even if they were not changed. This is because ultimately the string representations of the before and after values are compared, and Maps and ContentItemAsset don't stringify the same.
      Parameters:
      item - The ContentItem being replaced or updated.
    • getRepository

      protected ContentItemRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ContentItem>
    • getFieldDataService

      protected FieldDataService<FieldData> getFieldDataService()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getAuthenticationUtils

      protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
    • getTranslationEntityService

      protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService()
    • setTranslationEntityService

      @Autowired public void setTranslationEntityService(com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService)
    • getCacheStateManager

      @Nullable protected com.broadleafcommerce.common.extension.cache.CacheStateManager getCacheStateManager()
    • setCacheStateManager

      @Autowired(required=false) public void setCacheStateManager(@Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager)
    • setContentItemCacheByNameKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheByName") public void setContentItemCacheByNameKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheByNameKeyGen)
    • getContentItemCacheByNameKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheByNameKeyGen()
    • setContentItemCacheByIdInKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheByIdIn") public void setContentItemCacheByIdInKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheByIdInKeyGen)
    • getContentItemCacheByIdInKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheByIdInKeyGen()
    • setContentItemCacheByNameInKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheByNameIn") public void setContentItemCacheByNameInKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheByNameInKeyGen)
    • getContentItemCacheByNameInKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheByNameInKeyGen()
    • setContentItemCacheByModelIdKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheByModelId") public void setContentItemCacheByModelIdKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheByModelIdKeyGen)
    • getContentItemCacheByModelIdKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheByModelIdKeyGen()
    • setContentItemCacheByUriAndModelIdKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheByUriAndModelId") public void setContentItemCacheByUriAndModelIdKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheByUriAndModelIdKeyGen)
    • getContentItemCacheByUriAndModelIdKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheByUriAndModelIdKeyGen()
    • setContentItemCachePageByNameInKeyGen

      @Autowired(required=false) @Qualifier("contentItemCachePageByNameIn") public void setContentItemCachePageByNameInKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCachePageByNameInKeyGen)
    • getContentItemCachePageByNameInKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCachePageByNameInKeyGen()
    • setContentItemCachePageByIdInKeyGen

      @Autowired(required=false) @Qualifier("contentItemCachePageByIdIn") public void setContentItemCachePageByIdInKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCachePageByIdInKeyGen)
    • getContentItemCachePageByIdInKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCachePageByIdInKeyGen()
    • setContentItemCachePageByModelIdKeyGen

      @Autowired(required=false) @Qualifier("contentItemCachePageByModelId") public void setContentItemCachePageByModelIdKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCachePageByModelIdKeyGen)
    • getContentItemCachePageByModelIdKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCachePageByModelIdKeyGen()
    • setContentItemCacheByItemAndModelUriKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheByCombinedUrl") public void setContentItemCacheByItemAndModelUriKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheByItemAndModelUriKeyGen)
    • getContentItemCacheByItemAndModelUriKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheByItemAndModelUriKeyGen()
    • setContentItemCacheAllByFilterKeyGen

      @Autowired(required=false) @Qualifier("contentItemCacheAllByFilter") public void setContentItemCacheAllByFilterKeyGen(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheAllByFilterKeyGen)
    • getContentItemCacheAllByFilterKeyGen

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheAllByFilterKeyGen()
    • setContentItemCacheAllWithTags

      @Autowired(required=false) @Qualifier("contentItemCacheAllWithTags") public void setContentItemCacheAllWithTags(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen contentItemCacheAllWithTags)
    • getContentItemCacheAllWithTags

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getContentItemCacheAllWithTags()
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • setObjectMapper

      @Autowired public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)