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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultContentItemHydrationService(ContentModelService<ContentModel> contentModelService, ContentItemService<ContentItem> itemService, FieldDataService<FieldData> fieldDataService) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddMissingFieldData(@NonNull ContentModel model, @NonNull List<FieldData> fieldData) protected FieldDatachooseMoreDerivedField(FieldData field1, FieldData field2) If we have fields with the same name, then we should choose the one in the more derived catalog.protected StringGet the authenticated user id from theAuthenticationUtils.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsprotected com.broadleafcommerce.common.extension.cache.CacheStateManagerprotected ContentFieldService<ContentField>protected <C extends ContentItem>
ContentModelgetContentModelForContentItem(C contentItem, List<ContentModel> models) Deprecated, for removal: This API element is subject to removal in a future version.protected <C extends ContentItem>
ContentModelgetContentModelForContentItem(C contentItem, List<ContentModel> models, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Find theContentModelassociated to the suppliedContentItem.protected ContentModelService<ContentModel>protected FieldDataService<FieldData>getFieldsByName(@NonNull List<ContentField> contentFields, @NonNull List<FieldData> fields) protected Map<String,List<ContentFolderItem>> getFolderItemMap(@NonNull Collection<String> contentItemIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read allContentFolderItems for the suppliedContentItemids.protected ContentFolderItemService<ContentFolderItem>protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGenprotected com.broadleafcommerce.common.extension.cache.key.ContextKeyGenprotected ContentItemService<ContentItem>protected Optional<ContentItem>getNestedItemById(List<ContentItem> nestedContentItems, String nestedItemId) Find theContentItemwith the supplied id from the list ofContentItems.protected List<StarredItem>getStarredItems(String adminUserId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read allStarredItems for the supplied admin user id.protected StarredItemService<StarredItem>protected com.broadleafcommerce.common.extension.TypeFactoryhydrate(@NonNull ContentItem unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates the individualContentItem.<C extends ContentItem>
List<C>hydrate(@NonNull List<C> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates the list ofContentItems.<C extends ContentItem>
org.springframework.data.domain.Page<C>hydrate(@NonNull org.springframework.data.domain.Page<C> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates the page ofContentItems.<C extends ContentItem>
org.springframework.data.domain.Page<C>hydrate(@NonNull org.springframework.data.domain.Page<C> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, boolean hydrateNested) Hydrates the page ofContentItems.protected <C extends ContentItem>
voidhydrateContentItem(@NonNull List<ContentModel> models, @NonNull Map<String, List<FieldData>> fieldMap, @NonNull List<StarredItem> starredItems, C contentItem) Deprecated, for removal: This API element is subject to removal in a future version.protected <C extends ContentItem>
voidhydrateContentItem(@NonNull List<ContentModel> models, @NonNull Map<String, List<FieldData>> fieldMap, @NonNull List<StarredItem> starredItems, C contentItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates theContentItem.getModel(),ContentItem.isStarred()and adds missingContentItem.getFields()if model has new fields.protected <C extends ContentItem>
voidhydrateContentItem(@NonNull List<ContentModel> models, @NonNull Map<String, List<FieldData>> fieldMap, C contentItem) Deprecated.In favor ofhydrateContentItem(List, Map, List, ContentItem)protected ContentItemhydrateInternal(@NonNull ContentItem unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Performs the actual hydration of theContentItem.protected <C extends ContentItem>
List<C>hydrateInternal(@NonNull List<C> unhydrated, boolean hydrateNested, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Performs the actual hydration of a list ofContentItems.protected booleanisContentItemStarred(ContentItem contentItem, List<StarredItem> starredItems) Determine whether theContentItemis starred if it's ID is found in the list ofStarredItems.protected booleanisValidDateValue(@NonNull Object value) protected booleanisValidFieldDataValue(@NonNull ContentField contentField, @NonNull FieldData fieldData) protected booleanisValidHexColorValue(@NonNull Object hexColor) voidprotected List<ContentModel>recursivelyFindModels(Set<String> modelIds, Integer depth, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Recursively find allContent Modelsfor the passed in list of content model ids.protected <C extends ContentItem>
voidrecursivelyFindNestedContentItems(List<ContentModel> models, C contentItem, Integer depth, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Recursively find and hydrate all nested content items within the supplied item.voidsetAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) voidsetCacheStateManager(com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) voidsetContentFieldService(ContentFieldService<ContentField> contentFieldService) voidsetFolderItemService(ContentFolderItemService<ContentFolderItem> folderItemService) voidsetHydrationByCacheByResolvedContentItemId(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen hydrationByCacheByResolvedContentItemId) voidsetHydrationCacheByResolvedContentItemIdAndPreviewToken(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen hydrationCacheByResolvedContentItemIdAndPreviewToken) voidsetStarredItemService(StarredItemService<StarredItem> starredItemService) voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected booleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
MAX_RECURSIVE_DEPTH
public static final int MAX_RECURSIVE_DEPTH- See Also:
-
BY_CONTENT_ITEM_ID
- See Also:
-
BY_CONTENT_ITEM_ID_AND_PREVIEW_TOKEN
- See Also:
-
-
Constructor Details
-
DefaultContentItemHydrationService
public DefaultContentItemHydrationService(ContentModelService<ContentModel> contentModelService, ContentItemService<ContentItem> itemService, FieldDataService<FieldData> fieldDataService)
-
-
Method Details
-
hydrate
public ContentItem hydrate(@NonNull @NonNull ContentItem unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ContentItemHydrationServiceHydrates the individualContentItem.- Specified by:
hydratein interfaceContentItemHydrationService- 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:ContentItemHydrationServiceHydrates the page ofContentItems.- Specified by:
hydratein interfaceContentItemHydrationService- Parameters:
unhydrated- The unhydrated items.contextInfo- Sandbox and multitenant infohydrateNested- 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:ContentItemHydrationServiceHydrates the page ofContentItems.- Specified by:
hydratein interfaceContentItemHydrationService- 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:ContentItemHydrationServiceHydrates the list ofContentItems.- Specified by:
hydratein interfaceContentItemHydrationService- 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 theContentItem. This method is meant to be called internally byhydrate(ContentItem, ContextInfo)methods processing a single item. The caller method may cache the result- Parameters:
unhydrated- the content item to hydratecontextInfo- 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 ofContentItems. This method is meant to be called internally byhydrate(List, ContextInfo)orhydrate(Page, ContextInfo)methods processing a collection of content items. The caller method may cache the result.- Parameters:
unhydrated- the list of content items to hydratecontextInfo- 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 allContent Modelsfor the passed in list of content model ids.- Parameters:
modelIds- the ids of the models to traversedepth- the current depth traversedcontextInfo- 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) Deprecated.In favor ofhydrateContentItem(List, Map, List, ContentItem)Hydrates theContentItem.getModel()and adds missingContentItem.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 datacontentItem-ContentItemto 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 theContentItem.getModel(),ContentItem.isStarred()and adds missingContentItem.getFields()if model has new fields.- Type Parameters:
C- Type of the content item- Parameters:
models- Models that might match the content itemfieldMap- Map of content item field datastarredItems- Starred items by the usercontentItem-ContentItemto 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 theContentItem.getModel(),ContentItem.isStarred()and adds missingContentItem.getFields()if model has new fields.- Type Parameters:
C- Type of the content item- Parameters:
models- Models that might match the content itemfieldMap- Map of content item field datastarredItems- Starred items by the usercontentItem-ContentItemto hydratecontextInfo- Context information surrounding sandboxing and multitenant state
-
getFieldsByName
-
isValidFieldDataValue
protected boolean isValidFieldDataValue(@NonNull @NonNull ContentField contentField, @NonNull @NonNull FieldData fieldData) -
isValidDateValue
-
isValidHexColorValue
-
chooseMoreDerivedField
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 namefield2- 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 theContentModels that might be neededcontentItem- TheContentItemto traversecontextInfo- Context information surrounding sandboxing and multitenant state
-
getAuthenticatedUserId
Get the authenticated user id from theAuthenticationUtils.- Returns:
- The authenticated user id
-
getStarredItems
protected List<StarredItem> getStarredItems(@Nullable String adminUserId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read allStarredItems for the supplied admin user id.- Parameters:
adminUserId- The admin user id to matchcontextInfo- 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 allContentFolderItems for the suppliedContentItemids.- Parameters:
contentItemIds- TheContentItemids to matchcontextInfo- Context information surrounding sandboxing and multitenant state- Returns:
- A map of
ContentItemids to theirContentFolderItems
-
getNestedItemById
protected Optional<ContentItem> getNestedItemById(List<ContentItem> nestedContentItems, String nestedItemId) Find theContentItemwith the supplied id from the list ofContentItems.- Parameters:
nestedContentItems- The list ofContentItems to searchnestedItemId- The id of theContentItemto match- Returns:
- The
ContentItemif 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 theContentModelassociated to the suppliedContentItem.- Type Parameters:
C- Type of the content item- Parameters:
contentItem- TheContentItemto matchmodels- The list of allContentModels 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 theContentModelassociated to the suppliedContentItem.- Type Parameters:
C- Type of the content item- Parameters:
contentItem- TheContentItemto matchmodels- The list of allContentModels in playcontextInfo- Context information surrounding sandboxing and multitenant state- Returns:
- The associated
ContentModel
-
isContentItemStarred
Determine whether theContentItemis starred if it's ID is found in the list ofStarredItems.- Parameters:
contentItem- TheContentItemto matchstarredItems- The list of allStarredItems- Returns:
- boolean Whether the
ContentItemis starred
-
addMissingFieldData
protected void addMissingFieldData(@NonNull @NonNull ContentModel model, @NonNull @NonNull List<FieldData> fieldData) -
onApplicationEvent
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<ContentCacheInvalidationEvent>
-
shouldInvalidateCache
-
getContentModelService
-
getItemService
-
getFieldDataService
-
getContentFieldService
-
setContentFieldService
@Autowired public void setContentFieldService(ContentFieldService<ContentField> contentFieldService) -
getStarredItemService
-
setStarredItemService
-
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()
-
hydrateContentItem(List, Map, List, ContentItem, ContextInfo)