Interface CategoryAncestryHydrationService

All Known Implementing Classes:
DefaultCategoryAncestryHydrationService

public interface CategoryAncestryHydrationService
A Category can have ancestors, starting with its direct parent defined in Category.parentCategory up to the top-level ancestor.

This component enables efficient retrieval of all of a category's ancestors from the data store, while accounting for the possibility of cycles and broken references.

Author:
Samarth Dhruva (samarthd)
  • Method Details

    • getWithAllAncestors

      CategoryAncestryHydrationResponse getWithAllAncestors(Category category, @Nullable 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.

      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.

      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:
    • getWithAllAncestors

      Map<String,CategoryAncestryHydrationResponse> getWithAllAncestors(Collection<Category> categories, @Nullable 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.

      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.

      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:
    • getSuccessfulAndLogErrors

      A convenient method to process the response from getWithAllAncestors(Collection, ContextInfo) by logging errors on all categories which failed hydration and returning only the successful responses.
      Parameters:
      responses - the responses returned by getWithAllAncestors(Collection, ContextInfo). Cannot be null.
      Returns:
      a map only containing entries for successfully hydrated categories