Class CategoryProductConsolidationContributor

java.lang.Object
com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor<CategoryProductRef>
com.broadleafcommerce.catalog.service.product.consolidation.CategoryProductConsolidationContributor
All Implemented Interfaces:
ProductConsolidationContributor

public class CategoryProductConsolidationContributor extends ContextualProductConsolidationContributor<CategoryProductRef>
Consolidates all directly linked and ancestor CategoryProducts into products.
  • Constructor Details

    • CategoryProductConsolidationContributor

      public CategoryProductConsolidationContributor(CategoryProductService<CategoryProduct> categoryProductService, CategoryService<Category> categoryService, com.broadleafcommerce.data.tracking.core.tenant.service.CommonCatalogService<com.broadleafcommerce.data.tracking.core.tenant.domain.Catalog> catalogService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • clearAncestorsCache

      public void clearAncestorsCache()
      Clear the cache of category ancestors when a category change is made.
    • shouldConsolidate

      public boolean shouldConsolidate(Set<String> productIds, List<ConsolidatedProduct> products, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ProductConsolidationContributor
      Determines whether this contributor should be executed based on the given parameters and context.

      Returns true by default.

      Parameters:
      productIds - the IDs of the products to consolidate
      products - the product in all explicit context states
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - context information surrounding sandboxing/multitenant state
    • getObjectsToConsolidate

      protected List<CategoryProductRef> getObjectsToConsolidate(Set<String> productIds, List<ConsolidatedProduct> products, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from class: ContextualProductConsolidationContributor
      Retrieve the full list of domain objects of this type to be consolidated into the products.
      Specified by:
      getObjectsToConsolidate in class ContextualProductConsolidationContributor<CategoryProductRef>
      Parameters:
      productIds - the IDs of the products to consolidate
      products - the products in all explicit context states
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - context information surrounding sandboxing/multitenant state
      Returns:
      all domain objects of this type to consolidate into the products
    • hydrateCategoriesAndGenerateOverrides

      protected void hydrateCategoriesAndGenerateOverrides(List<CategoryProductRef> categoryProducts, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Populate the correct category information on the category product relationship objects. For categories in contexts which do not exactly match any existing category product relationship context, generate new category product relationship placeholders with those contexts to hold the overrides.
      Parameters:
      categoryProducts - the category product relationship objects
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - the context to perform the operation in
    • handleNotFoundCategories

      protected void handleNotFoundCategories(List<String> categoryIds, Map<String,List<Category>> categoriesById)
      For category IDs which were not found and stored in the map, create a warning and store an empty list for that ID.
      Parameters:
      categoryIds - the IDs of all categories which should be in the categoriesById
      categoriesById - the retrieved categories for the requested IDs
    • getFullCategoryLines

      protected Map<Category,List<Category>> getFullCategoryLines(List<Category> categories, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Retrieve the full category ancestry lines for each of the categories, including itself.

      This does not support catalog composition. Only ancestor categories within the original category's catalog will be found.

      Parameters:
      categories - categories to retrieve category ancestry lines for
      context - the original context in which the categories were retrieved
      Returns:
      a map of categories to their full category ancestry lines
    • getFullCategoryLine

      protected List<Category> getFullCategoryLine(Category category, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Retrieve the full category ancestry line for the category, including itself. This will use the cache first, and fall back to fetch the data if necessary.

      This does not support catalog composition. Only ancestor categories within the original category's catalog will be found.

      Parameters:
      category - category to retrieve category ancestry lines for
      context - the original context in which the categories were retrieved
      Returns:
      a list of the full category line for this category, including itself
    • getCategoryAncestors

      protected List<Category> getCategoryAncestors(Category category, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Retrieve all ancestor categories for the given category. This will use the cache first, and fall back to fetch the data if necessary.

      This does not support catalog composition. Only ancestor categories within the original category's catalog will be found.

      Parameters:
      category - category to retrieve category ancestry lines for
      context - the original context in which the categories were retrieved
      Returns:
      a list of the category's ancestors
    • hydrateCategories

      protected List<Category> hydrateCategories(List<CategoryProductRef> categoryProducts, Map<String,List<Category>> categoriesById, Map<Category,List<Category>> fullCategoryLines, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Populate the correct category information on the category product relationship objects.
      Parameters:
      categoryProducts - the category product relationship objects which share an ID
      categoriesById - categories mapped by ID
      fullCategoryLines - map of categories to their full category ancestry lines
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - the original context in which the categories were retrieved
      Returns:
      a list of categories whose contexts don't match a category product already
    • findImplicitCategoryMatchInOtherApplicationCatalog

      protected Optional<Category> findImplicitCategoryMatchInOtherApplicationCatalog(CategoryProductRef categoryProduct, List<Category> potentialCategories, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Looks for implicit category matches for the categoryProduct from the potentialCategories which aren't directly in its catalog inheritance line.

      Used when a category product is in an application-owned catalog, and connects to a category in a separate catalog owned by the same application. The usual ContextualProductConsolidationContributor.findImplicitMatches(ContextState, List, Function, InheritanceLines) will only find matches within the category product's inheritance line, which will not include this category.

      If the categoryProduct's catalog is application-owned, this checks if the category is in that application through a separate application-assigned catalog. If found, inheritance lines are gathered for this other application-assigned catalog, and used to find the implicit match for the category within the application.

      Parameters:
      categoryProduct - the category product to find a matching category for
      potentialCategories - all categories matching the category ID from the category product
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - the original context in which the categories were retrieved
      Returns:
      the category implicitly matched from a different application-assigned catalog
    • inheritanceLinesContain

      public static boolean inheritanceLinesContain(String catalogId, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines)
      Check if the inheritance lines already contain the catalog.
      Parameters:
      catalogId - The id of the catalog
      inheritanceLines - The catalog inheritance lines
      Returns:
      True if the catalog is in the inheritnace lines, otherwise false
    • setCategoryForCategoryProductRef

      protected void setCategoryForCategoryProductRef(CategoryProductRef categoryProduct, Category category, Map<Category,List<Category>> fullCategoryLines)
    • generateNewOverriddenCategoryProducts

      protected List<CategoryProductRef> generateNewOverriddenCategoryProducts(List<CategoryProductRef> categoryProducts, List<Category> unmatchedCategories, Map<Category,List<Category>> fullCategoryLines, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines)
      For categories in contexts which do not exactly match any existing category product relationship context, generate new category product relationship placeholders with those contexts to hold the overrides.
      Parameters:
      categoryProducts - the category product relationships in all explicit context states
      unmatchedCategories - categories whose contexts don't match a category product already
      fullCategoryLines - map of categories to their full category ancestry lines
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      Returns:
      the new generated category product relationships
    • productIdGetter

      protected Function<CategoryProductRef,String> productIdGetter()
      Description copied from class: ContextualProductConsolidationContributor
      Defines the function which retrieves the Product ID from the domain object to consolidate, in order to group it with the appropriate product for processing.
      Specified by:
      productIdGetter in class ContextualProductConsolidationContributor<CategoryProductRef>
      Returns:
      function to retrieve Product ID of the domain object
    • idGetter

      protected Function<CategoryProductRef,String> idGetter()
      Description copied from class: ContextualProductConsolidationContributor
      Defines the function which retrieves the contextId of the domain object in order to recognize it in different contexts.
      Specified by:
      idGetter in class ContextualProductConsolidationContributor<CategoryProductRef>
      Returns:
      function to retrieve contextId of the domain object
    • setter

      Description copied from class: ContextualProductConsolidationContributor
      Defines the function which should be used to set the domain objects on the consolidated product.
      Specified by:
      setter in class ContextualProductConsolidationContributor<CategoryProductRef>
      Returns:
      function to set domain objects on the consolidated product
    • setCategories

      protected void setCategories(ConsolidatedProduct product, List<CategoryProductRef> categoryProducts)
      Set all the directly linked explicit categories, as well as all categories, including ancestors.
      Parameters:
      product - the product to set the values on
      categoryProducts - direct product category relationships
    • setPrimaryCategory

      protected void setPrimaryCategory(ConsolidatedProduct product, List<CategoryProductRef> categoryProducts)
      Set the primary category on the product from the available category products.
      Parameters:
      product - the product to set the primary category for
      categoryProducts - all the categories for the product
    • getCategoryProductService

      protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getCategoryService

      protected CategoryService<Category> getCategoryService()
    • getCatalogService

      protected com.broadleafcommerce.data.tracking.core.tenant.service.CommonCatalogService<com.broadleafcommerce.data.tracking.core.tenant.domain.Catalog> getCatalogService()
    • getCategoryAncestorsCache

      protected Map<Category,List<Category>> getCategoryAncestorsCache()