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 void
addMissingFieldData
(@NonNull ContentModel model, @NonNull List<FieldData> fieldData) 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.protected String
Get the authenticated user id from theAuthenticationUtils
.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils
protected com.broadleafcommerce.common.extension.cache.CacheStateManager
protected 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 theContentModel
associated 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 allContentFolderItem
s for the suppliedContentItem
ids.protected ContentFolderItemService<ContentFolderItem>
protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
protected com.broadleafcommerce.common.extension.cache.key.ContextKeyGen
protected ContentItemService<ContentItem>
protected Optional<ContentItem>
getNestedItemById
(List<ContentItem> nestedContentItems, String nestedItemId) Find theContentItem
with the supplied id from the list ofContentItem
s.protected List<StarredItem>
getStarredItems
(String adminUserId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read allStarredItem
s for the supplied admin user id.protected StarredItemService<StarredItem>
protected com.broadleafcommerce.common.extension.TypeFactory
hydrate
(@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 ContentItem
hydrateInternal
(@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 boolean
isContentItemStarred
(ContentItem contentItem, List<StarredItem> starredItems) Determine whether theContentItem
is starred if it's ID is found in the list ofStarredItems
.protected boolean
isValidDateValue
(@NonNull Object value) protected boolean
isValidFieldDataValue
(@NonNull ContentField contentField, @NonNull FieldData fieldData) protected boolean
isValidHexColorValue
(@NonNull Object hexColor) void
protected List<ContentModel>
recursivelyFindModels
(Set<String> modelIds, Integer depth, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Recursively find allContent Models
for 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.void
setAuthenticationUtils
(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) void
setCacheStateManager
(com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) void
setContentFieldService
(ContentFieldService<ContentField> contentFieldService) void
setFolderItemService
(ContentFolderItemService<ContentFolderItem> folderItemService) void
setHydrationByCacheByResolvedContentItemId
(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen hydrationByCacheByResolvedContentItemId) void
setHydrationCacheByResolvedContentItemIdAndPreviewToken
(com.broadleafcommerce.common.extension.cache.key.ContextKeyGen hydrationCacheByResolvedContentItemIdAndPreviewToken) void
setStarredItemService
(StarredItemService<StarredItem> starredItemService) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected boolean
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:ContentItemHydrationService
Hydrates the individualContentItem
.- Specified by:
hydrate
in 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:ContentItemHydrationService
Hydrates the page ofContentItems
.- Specified by:
hydrate
in 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:ContentItemHydrationService
Hydrates the page ofContentItems
.- Specified by:
hydrate
in 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:ContentItemHydrationService
Hydrates the list ofContentItems
.- Specified by:
hydrate
in 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 Models
for 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
-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 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
-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 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
-ContentItem
to 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 theContentModel
s that might be neededcontentItem
- TheContentItem
to 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 allStarredItem
s 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
StarredItem
s
-
getFolderItemMap
protected Map<String,List<ContentFolderItem>> getFolderItemMap(@NonNull @NonNull Collection<String> contentItemIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read allContentFolderItem
s for the suppliedContentItem
ids.- Parameters:
contentItemIds
- TheContentItem
ids to matchcontextInfo
- Context information surrounding sandboxing and multitenant state- Returns:
- A map of
ContentItem
ids to theirContentFolderItem
s
-
getNestedItemById
protected Optional<ContentItem> getNestedItemById(List<ContentItem> nestedContentItems, String nestedItemId) Find theContentItem
with the supplied id from the list ofContentItem
s.- Parameters:
nestedContentItems
- The list ofContentItem
s to searchnestedItemId
- The id of theContentItem
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 theContentModel
associated to the suppliedContentItem
.- Type Parameters:
C
- Type of the content item- Parameters:
contentItem
- TheContentItem
to matchmodels
- The list of allContentModel
s 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 theContentModel
associated to the suppliedContentItem
.- Type Parameters:
C
- Type of the content item- Parameters:
contentItem
- TheContentItem
to matchmodels
- The list of allContentModel
s in playcontextInfo
- Context information surrounding sandboxing and multitenant state- Returns:
- The associated
ContentModel
-
isContentItemStarred
Determine whether theContentItem
is starred if it's ID is found in the list ofStarredItems
.- Parameters:
contentItem
- TheContentItem
to matchstarredItems
- The list of allStarredItems
- Returns:
- boolean Whether the
ContentItem
is starred
-
addMissingFieldData
protected void addMissingFieldData(@NonNull @NonNull ContentModel model, @NonNull @NonNull List<FieldData> fieldData) -
onApplicationEvent
- Specified by:
onApplicationEvent
in 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)