Class DefaultCategoryAncestryHydrationService
java.lang.Object
com.broadleafcommerce.catalog.service.category.hydration.DefaultCategoryAncestryHydrationService
- All Implemented Interfaces:
CategoryAncestryHydrationService
public class DefaultCategoryAncestryHydrationService
extends Object
implements CategoryAncestryHydrationService
- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorDescriptionDefaultCategoryAncestryHydrationService
(CategoryService<Category> categoryService) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
attemptHydrationOfNextAncestor
(String inProgressCategoryToHydrate, Category highestAncestorThusFar, List<String> ancestorIdsSeenThusFar, Set<String> failedToFindCategoryIds, Map<String, Category> foundCategoriesCache, Set<String> categoryIdsToRemoveFromInProgress, Set<String> categoryIdsToFindInDataStore, Map<String, CategoryAncestryHydrationResponse> completed) findInDataStoreAndReturnMissingIds
(Set<String> categoryIdsToFind, Map<String, Category> cacheToAddFoundTo, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Searches the data store for categories matching the givencategoryIdsToFind
.protected CategoryService<Category>
getSuccessfulAndLogErrors
(@NonNull Map<String, CategoryAncestryHydrationResponse> responses) A convenient method to process the response fromCategoryAncestryHydrationService.getWithAllAncestors(Collection, ContextInfo)
by logging errors on all categories which failed hydration and returning only the successful responses.getWithAllAncestors
(@NonNull Category category, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Fetches all of the given category's ancestors from the data store and returns a result containing them and the given category.getWithAllAncestors
(Collection<Category> categories, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Fetches all of the given categories' ancestors from the data store and returns a result containing them and the given categories themselves.protected void
markComplete
(String categoryIdToMarkComplete, CategoryAncestryHydrationResponse completionResultForCategory, Set<String> categoryIdsToRemoveFromInProgress, Map<String, CategoryAncestryHydrationResponse> completed)
-
Constructor Details
-
DefaultCategoryAncestryHydrationService
-
-
Method Details
-
getWithAllAncestors
public Map<String,CategoryAncestryHydrationResponse> getWithAllAncestors(Collection<Category> categories, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CategoryAncestryHydrationService
Fetches all of the given categories' ancestors from the data store and returns a result containing them and the given categories themselves.If a category does not have any ancestors, it will be returned by itself.
If any broken references or cycles are found in the ancestry of a category, its response will not be
CategoryAncestryHydrationResponse.successful
.- Specified by:
getWithAllAncestors
in interfaceCategoryAncestryHydrationService
- Parameters:
categories
- the categories whose ancestors should be fetched. These should be instances with their fields already fully populated (as they would be from the data store). Categories provided here are considered to be already-found and will re-appear in the result.contextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a map from each given category's id to the hydration response for it. There is guaranteed to be an entry in this map for each given category. The response for a particular category will have it along with all of its ancestors if successful, or a description of any error that was encountered. Do note that if multiple categories share the same ancestor, each of their ancestry lists will contain the same instance of that ancestor.
- See Also:
-
markComplete
protected void markComplete(String categoryIdToMarkComplete, CategoryAncestryHydrationResponse completionResultForCategory, Set<String> categoryIdsToRemoveFromInProgress, Map<String, CategoryAncestryHydrationResponse> completed) - Parameters:
categoryIdToMarkComplete
- the id of the category which should be marked completecompletionResultForCategory
- the result that the category should be completed withcategoryIdsToRemoveFromInProgress
- a set containing ids of categories that should no longer be considered in-progress. The givencategoryIdToMarkComplete
will be added to this set.completed
- a map of completed category ids to their results. The givencategoryIdToMarkComplete
will be put into this map with the value ofcompletionResultForCategory
.
-
findInDataStoreAndReturnMissingIds
protected Set<String> findInDataStoreAndReturnMissingIds(Set<String> categoryIdsToFind, Map<String, Category> cacheToAddFoundTo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Searches the data store for categories matching the givencategoryIdsToFind
. Categories that are found will be added to thecacheToAddFoundTo
. Any ids for which categories were not found will be returned.- Parameters:
categoryIdsToFind
- the set of category ids to find in the data storecacheToAddFoundTo
- a map of category id to category, which all found categories will be added tocontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a set containing any ids for which categories were not found in the data store
-
attemptHydrationOfNextAncestor
protected void attemptHydrationOfNextAncestor(String inProgressCategoryToHydrate, Category highestAncestorThusFar, List<String> ancestorIdsSeenThusFar, Set<String> failedToFindCategoryIds, Map<String, Category> foundCategoriesCache, Set<String> categoryIdsToRemoveFromInProgress, Set<String> categoryIdsToFindInDataStore, Map<String, CategoryAncestryHydrationResponse> completed) - Parameters:
inProgressCategoryToHydrate
- the id of a category whose ancestor hydration was originally requestedhighestAncestorThusFar
- the highest-level ancestor that has been successfully found for theinProgressCategoryToHydrate
thus far. Guaranteed to have a non-emptyCategoryRef.id
in itsCategory.parentCategory
representing the next ancestor to find.ancestorIdsSeenThusFar
- the list (in order of lowest to highest-level) of ids of ancestors that have been successfully found for theinProgressCategoryToHydrate
thus far. The very last id in this list will belong tohighestAncestorThusFar
. If the next ancestor is found, it should be appended to this list.failedToFindCategoryIds
- the ids of categories for which a query to the data store has already been attempted, but no corresponding record was foundfoundCategoriesCache
- all categories that have already been successfully found in the data store, mapped by their idcategoryIdsToRemoveFromInProgress
- a set of category ids that will be removed from the group of categories for which ancestor hydration is considered unfinished. TheinProgressCategoryToHydrate
is currently a member of that group, so if this method determines that it should be marked completed, it should be added to this set (in addition to being added tocompleted
).categoryIdsToFindInDataStore
- a set of category ids that will be queried for in the data store. If a category id needs to be found in the data store, it should be added to this set. The query will be performed and the results will be reflected infailedToFindCategoryIds
andfoundCategoriesCache
on the next invocation of this method forinProgressCategoryToHydrate
.completed
- the final map of category ids for which ancestor hydration is finished, to the result of performing that hydration. If this method determines thatinProgressCategoryToHydrate
should be marked completed, it should be added to this map (in addition to being added tocategoryIdsToRemoveFromInProgress
)
-
getSuccessfulAndLogErrors
public Map<String,CategoryAncestorList> getSuccessfulAndLogErrors(@NonNull @NonNull Map<String, CategoryAncestryHydrationResponse> responses) Description copied from interface:CategoryAncestryHydrationService
A convenient method to process the response fromCategoryAncestryHydrationService.getWithAllAncestors(Collection, ContextInfo)
by logging errors on all categories which failed hydration and returning only the successful responses.- Specified by:
getSuccessfulAndLogErrors
in interfaceCategoryAncestryHydrationService
- Parameters:
responses
- the responses returned byCategoryAncestryHydrationService.getWithAllAncestors(Collection, ContextInfo)
. Cannot be null.- Returns:
- a map only containing entries for
successfully hydrated
categories
-
getWithAllAncestors
public CategoryAncestryHydrationResponse getWithAllAncestors(@NonNull @NonNull Category category, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CategoryAncestryHydrationService
Fetches all of the given category's ancestors from the data store and returns a result containing them and the given category.If the category does not have any ancestors, it will be returned by itself with an empty
CategoryAncestorList.ancestors
.If any broken references or cycles are found in the ancestry of the category, its response will not be
CategoryAncestryHydrationResponse.successful
.- Specified by:
getWithAllAncestors
in interfaceCategoryAncestryHydrationService
- Parameters:
category
- the category whose ancestors should be fetched. This should be an instance with its fields already fully populated (as it would be from the data store). The category provided here is considered already-found and will re-appear in the result.contextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a response containing the category and its ancestors if successfully found, or details about the error that was encountered
- See Also:
-
getCategoryService
-