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 Details

    • DefaultCategoryAncestryHydrationService

      public DefaultCategoryAncestryHydrationService(CategoryService<Category> categoryService)
  • 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 interface CategoryAncestryHydrationService
      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 complete
      completionResultForCategory - the result that the category should be completed with
      categoryIdsToRemoveFromInProgress - a set containing ids of categories that should no longer be considered in-progress. The given categoryIdToMarkComplete will be added to this set.
      completed - a map of completed category ids to their results. The given categoryIdToMarkComplete will be put into this map with the value of completionResultForCategory.
    • 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 given categoryIdsToFind. Categories that are found will be added to the cacheToAddFoundTo. Any ids for which categories were not found will be returned.
      Parameters:
      categoryIdsToFind - the set of category ids to find in the data store
      cacheToAddFoundTo - a map of category id to category, which all found categories will be added to
      contextInfo - 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 requested
      highestAncestorThusFar - the highest-level ancestor that has been successfully found for the inProgressCategoryToHydrate thus far. Guaranteed to have a non-empty CategoryRef.id in its Category.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 the inProgressCategoryToHydrate thus far. The very last id in this list will belong to highestAncestorThusFar. 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 found
      foundCategoriesCache - all categories that have already been successfully found in the data store, mapped by their id
      categoryIdsToRemoveFromInProgress - a set of category ids that will be removed from the group of categories for which ancestor hydration is considered unfinished. The inProgressCategoryToHydrate 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 to completed).
      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 in failedToFindCategoryIds and foundCategoriesCache on the next invocation of this method for inProgressCategoryToHydrate.
      completed - the final map of category ids for which ancestor hydration is finished, to the result of performing that hydration. If this method determines that inProgressCategoryToHydrate should be marked completed, it should be added to this map (in addition to being added to categoryIdsToRemoveFromInProgress)
    • getSuccessfulAndLogErrors

      public Map<String,CategoryAncestorList> getSuccessfulAndLogErrors(@NonNull @NonNull Map<String,CategoryAncestryHydrationResponse> responses)
      Description copied from interface: CategoryAncestryHydrationService
      A convenient method to process the response from CategoryAncestryHydrationService.getWithAllAncestors(Collection, ContextInfo) by logging errors on all categories which failed hydration and returning only the successful responses.
      Specified by:
      getSuccessfulAndLogErrors in interface CategoryAncestryHydrationService
      Parameters:
      responses - the responses returned by CategoryAncestryHydrationService.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 interface CategoryAncestryHydrationService
      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

      protected CategoryService<Category> getCategoryService()