Class DefaultContentItemHydrationService

java.lang.Object
com.broadleafcommerce.content.service.hydration.DefaultContentItemHydrationService
All Implemented Interfaces:
ContentItemHydrationService, EventListener, org.springframework.context.ApplicationListener<ContentCacheInvalidationEvent>

public class DefaultContentItemHydrationService extends Object implements ContentItemHydrationService, org.springframework.context.ApplicationListener<ContentCacheInvalidationEvent>
  • Field Details

  • Constructor Details

  • Method Details

    • hydrate

      public ContentItem hydrate(@NonNull @NonNull ContentItem unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemHydrationService
      Hydrates the individual ContentItem.
      Specified by:
      hydrate in interface ContentItemHydrationService
      Parameters:
      unhydrated - The unhydrated item.
      contextInfo - Sandbox and multitenant info
      Returns:
      The hydrated ContentItem
    • hydrate

      public <C extends ContentItem> org.springframework.data.domain.Page<C> hydrate(@NonNull @NonNull org.springframework.data.domain.Page<C> unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, boolean hydrateNested)
      Description copied from interface: ContentItemHydrationService
      Hydrates the page of ContentItems.
      Specified by:
      hydrate in interface ContentItemHydrationService
      Parameters:
      unhydrated - The unhydrated items.
      contextInfo - Sandbox and multitenant info
      hydrateNested - Whether to hydrate nested items
      Returns:
      The hydrated ContentItem
    • hydrate

      public <C extends ContentItem> org.springframework.data.domain.Page<C> hydrate(@NonNull @NonNull org.springframework.data.domain.Page<C> unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemHydrationService
      Hydrates the page of ContentItems.
      Specified by:
      hydrate in interface ContentItemHydrationService
      Parameters:
      unhydrated - The unhydrated items.
      contextInfo - Sandbox and multitenant info
      Returns:
      The hydrated ContentItem
    • hydrate

      public <C extends ContentItem> List<C> hydrate(@NonNull @NonNull List<C> unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ContentItemHydrationService
      Hydrates the list of ContentItems.
      Specified by:
      hydrate in interface ContentItemHydrationService
      Parameters:
      unhydrated - The unhydrated items.
      contextInfo - Sandbox and multitenant info
      Returns:
      The hydrated ContentItem
    • hydrateInternal

      protected ContentItem hydrateInternal(@NonNull @NonNull ContentItem unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Performs the actual hydration of the ContentItem. This method is meant to be called internally by hydrate(ContentItem, ContextInfo) methods processing a single item. The caller method may cache the result
      Parameters:
      unhydrated - the content item to hydrate
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      the hydrated ContentItem
      Since:
      2.1.0-GA
    • hydrateInternal

      protected <C extends ContentItem> List<C> hydrateInternal(@NonNull @NonNull List<C> unhydrated, boolean hydrateNested, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Performs the actual hydration of a list of ContentItems. This method is meant to be called internally by hydrate(List, ContextInfo) or hydrate(Page, ContextInfo) methods processing a collection of content items. The caller method may cache the result.
      Parameters:
      unhydrated - the list of content items to hydrate
      contextInfo - context surrounding sandboxing and multitenant state
      Returns:
      the hydrated list of ContentItems
      Since:
      2.1.0-GA
    • recursivelyFindModels

      protected List<ContentModel> recursivelyFindModels(Set<String> modelIds, Integer depth, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Recursively find all Content Models for the passed in list of content model ids.
      Parameters:
      modelIds - the ids of the models to traverse
      depth - the current depth traversed
      contextInfo - Context information surrounding sandboxing and multitenant state
      Returns:
      The list of all models
    • hydrateContentItem

      @Deprecated protected <C extends ContentItem> void hydrateContentItem(@NonNull @NonNull List<ContentModel> models, @NonNull @NonNull Map<String,List<FieldData>> fieldMap, @NonNull C contentItem)
      Hydrates the ContentItem.getModel() and adds missing ContentItem.getFields() if model has new fields.
      Type Parameters:
      C - Type of the content item
      Parameters:
      models - Models that might match the content item.
      fieldMap - Map of content item field data
      contentItem - ContentItem to hydrate
    • hydrateContentItem

      @Deprecated(since="2.0.1", forRemoval=true) protected <C extends ContentItem> void hydrateContentItem(@NonNull @NonNull List<ContentModel> models, @NonNull @NonNull Map<String,List<FieldData>> fieldMap, @NonNull @NonNull List<StarredItem> starredItems, @NonNull C contentItem)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Hydrates the ContentItem.getModel(), ContentItem.isStarred() and adds missing ContentItem.getFields() if model has new fields.
      Type Parameters:
      C - Type of the content item
      Parameters:
      models - Models that might match the content item
      fieldMap - Map of content item field data
      starredItems - Starred items by the user
      contentItem - ContentItem to hydrate
    • hydrateContentItem

      protected <C extends ContentItem> void hydrateContentItem(@NonNull @NonNull List<ContentModel> models, @NonNull @NonNull Map<String,List<FieldData>> fieldMap, @NonNull @NonNull List<StarredItem> starredItems, @NonNull C contentItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Hydrates the ContentItem.getModel(), ContentItem.isStarred() and adds missing ContentItem.getFields() if model has new fields.
      Type Parameters:
      C - Type of the content item
      Parameters:
      models - Models that might match the content item
      fieldMap - Map of content item field data
      starredItems - Starred items by the user
      contentItem - ContentItem to hydrate
      contextInfo - Context information surrounding sandboxing and multitenant state
    • getFieldsByName

      protected Map<String,FieldData> getFieldsByName(@NonNull @NonNull List<ContentField> contentFields, @NonNull @NonNull List<FieldData> fields)
    • isValidFieldDataValue

      protected boolean isValidFieldDataValue(@NonNull @NonNull ContentField contentField, @NonNull @NonNull FieldData fieldData)
    • isValidDateValue

      protected boolean isValidDateValue(@NonNull @NonNull Object value)
    • isValidHexColorValue

      protected boolean isValidHexColorValue(@NonNull @NonNull Object hexColor)
    • chooseMoreDerivedField

      protected FieldData chooseMoreDerivedField(FieldData field1, FieldData field2)
      If we have fields with the same name, then we should choose the one in the more derived catalog. This can happen when a field is added at the application level and then later added at the tenant level.
      Parameters:
      field1 - First field with conflicting name
      field2 - Second field with conflicting name
      Returns:
      The more derived field (from a Catalog perspective).
    • recursivelyFindNestedContentItems

      protected <C extends ContentItem> void recursivelyFindNestedContentItems(List<ContentModel> models, @NonNull C contentItem, Integer depth, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Recursively find and hydrate all nested content items within the supplied item.
      Type Parameters:
      C - Type of the content item
      Parameters:
      models - All the ContentModels that might be needed
      contentItem - The ContentItem to traverse
      contextInfo - Context information surrounding sandboxing and multitenant state
    • getAuthenticatedUserId

      protected String getAuthenticatedUserId()
      Get the authenticated user id from the AuthenticationUtils.
      Returns:
      The authenticated user id
    • getStarredItems

      protected List<StarredItem> getStarredItems(@Nullable String adminUserId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Read all StarredItems for the supplied admin user id.
      Parameters:
      adminUserId - The admin user id to match
      contextInfo - Context information surrounding sandboxing and multitenant state
      Returns:
      A list of StarredItems
    • getFolderItemMap

      protected Map<String,List<ContentFolderItem>> getFolderItemMap(@NonNull @NonNull Collection<String> contentItemIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Read all ContentFolderItems for the supplied ContentItem ids.
      Parameters:
      contentItemIds - The ContentItem ids to match
      contextInfo - Context information surrounding sandboxing and multitenant state
      Returns:
      A map of ContentItem ids to their ContentFolderItems
    • getNestedItemById

      protected Optional<ContentItem> getNestedItemById(List<ContentItem> nestedContentItems, String nestedItemId)
      Find the ContentItem with the supplied id from the list of ContentItems.
      Parameters:
      nestedContentItems - The list of ContentItems to search
      nestedItemId - The id of the ContentItem to match
      Returns:
      The ContentItem if found
    • getContentModelForContentItem

      @Deprecated(since="2.0.1", forRemoval=true) protected <C extends ContentItem> ContentModel getContentModelForContentItem(C contentItem, List<ContentModel> models)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Find the ContentModel associated to the supplied ContentItem.
      Type Parameters:
      C - Type of the content item
      Parameters:
      contentItem - The ContentItem to match
      models - The list of all ContentModels in play
      Returns:
      The associated ContentModel
    • getContentModelForContentItem

      protected <C extends ContentItem> ContentModel getContentModelForContentItem(C contentItem, List<ContentModel> models, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Find the ContentModel associated to the supplied ContentItem.
      Type Parameters:
      C - Type of the content item
      Parameters:
      contentItem - The ContentItem to match
      models - The list of all ContentModels in play
      contextInfo - Context information surrounding sandboxing and multitenant state
      Returns:
      The associated ContentModel
    • isContentItemStarred

      protected boolean isContentItemStarred(ContentItem contentItem, List<StarredItem> starredItems)
      Determine whether the ContentItem is starred if it's ID is found in the list of StarredItems.
      Parameters:
      contentItem - The ContentItem to match
      starredItems - The list of all StarredItems
      Returns:
      boolean Whether the ContentItem is starred
    • addMissingFieldData

      protected void addMissingFieldData(@NonNull @NonNull ContentModel model, @NonNull @NonNull List<FieldData> fieldData)
    • onApplicationEvent

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

      protected boolean shouldInvalidateCache(ContentCacheInvalidationEvent event)
    • getContentModelService

      protected ContentModelService<ContentModel> getContentModelService()
    • getItemService

      protected ContentItemService<ContentItem> getItemService()
    • getFieldDataService

      protected FieldDataService<FieldData> getFieldDataService()
    • getContentFieldService

      protected ContentFieldService<ContentField> getContentFieldService()
    • setContentFieldService

      @Autowired public void setContentFieldService(ContentFieldService<ContentField> contentFieldService)
    • getStarredItemService

      protected StarredItemService<StarredItem> getStarredItemService()
    • setStarredItemService

      @Autowired public void setStarredItemService(StarredItemService<StarredItem> starredItemService)
    • getFolderItemService

      protected ContentFolderItemService<ContentFolderItem> getFolderItemService()
    • setFolderItemService

      @Autowired public void setFolderItemService(ContentFolderItemService<ContentFolderItem> folderItemService)
    • getAuthenticationUtils

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

      @Autowired public void setAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
    • getTypeFactory

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

      @Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • getCacheStateManager

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

      @Autowired public void setCacheStateManager(@Nullable com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager)
    • setHydrationByCacheByResolvedContentItemId

      @Autowired(required=false) @Qualifier("hydrationCacheByContentItemId") public void setHydrationByCacheByResolvedContentItemId(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen hydrationByCacheByResolvedContentItemId)
    • getHydrationByCacheByResolvedContentItemId

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getHydrationByCacheByResolvedContentItemId()
    • setHydrationCacheByResolvedContentItemIdAndPreviewToken

      @Autowired(required=false) @Qualifier("hydrationCacheByContentItemIdAndPreviewToken") public void setHydrationCacheByResolvedContentItemIdAndPreviewToken(@Nullable com.broadleafcommerce.common.extension.cache.key.ContextKeyGen hydrationCacheByResolvedContentItemIdAndPreviewToken)
    • getHydrationCacheByResolvedContentItemIdAndPreviewToken

      @Nullable protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen getHydrationCacheByResolvedContentItemIdAndPreviewToken()