Class CategoryProductConsolidationContributor
- All Implemented Interfaces:
ProductConsolidationContributor
CategoryProduct
s into products.-
Field Summary
Fields inherited from class com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor
IGNORE_ARCHIVED_FILTER, typeFactory
-
Constructor Summary
ConstructorDescriptionCategoryProductConsolidationContributor
(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 Summary
Modifier and TypeMethodDescriptionvoid
Clear the cache of category ancestors when a category change is made.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 thecategoryProduct
from thepotentialCategories
which aren't directly in its catalog inheritance line.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.protected com.broadleafcommerce.data.tracking.core.tenant.service.CommonCatalogService<com.broadleafcommerce.data.tracking.core.tenant.domain.Catalog>
getCategoryAncestors
(Category category, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve all ancestor categories for the given category.protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
getFullCategoryLine
(Category category, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve the full category ancestry line for the category, including itself.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.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) Retrieve the full list of domain objects of this type to be consolidated into the products.protected void
For category IDs which were not found and stored in the map, create a warning and store an empty list for that ID.hydrateCategories
(List<CategoryProductRef> categoryProducts, Map<String, List<Category>> categoriesById, Map<Category, List<Category>> fullCategoryLines, 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.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.protected Function<CategoryProductRef,
String> idGetter()
Defines the function which retrieves the contextId of the domain object in order to recognize it in different contexts.static boolean
inheritanceLinesContain
(String catalogId, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Check if the inheritance lines already contain the catalog.protected Function<CategoryProductRef,
String> 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.protected void
setCategories
(ConsolidatedProduct product, List<CategoryProductRef> categoryProducts) Set all the directly linked explicit categories, as well as all categories, including ancestors.protected void
setCategoryForCategoryProductRef
(CategoryProductRef categoryProduct, Category category, Map<Category, List<Category>> fullCategoryLines) protected void
setPrimaryCategory
(ConsolidatedProduct product, List<CategoryProductRef> categoryProducts) Set the primary category on the product from the available category products.protected BiConsumer<ConsolidatedProduct,
List<CategoryProductRef>> setter()
Defines the function which should be used to set the domain objects on the consolidated product.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) Determines whether this contributor should be executed based on the given parameters and context.Methods inherited from class com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor
consolidateProducts, consolidateRelations, contextCompositeKey, contextCompositeKey, contextStatesMatch, createOverrideProductForContext, findImplicitMatches, getCloneMapper, getInheritanceLevel, getMostSpecificCatalogId, getProductConsolidationRequest, getRsqlParser, getTypeFactory, ignoreArchived, isInheriting, setListValue, setSingleValue
-
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 consolidateproducts
- the product in all explicit context statesinheritanceLines
- the catalog inheritance lines top-down from all of the productscontext
- 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 classContextualProductConsolidationContributor<CategoryProductRef>
- Parameters:
productIds
- the IDs of the products to consolidateproducts
- the products in all explicit context statesinheritanceLines
- the catalog inheritance lines top-down from all of the productscontext
- 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 objectsinheritanceLines
- the catalog inheritance lines top-down from all of the productscontext
- 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 categoriesByIdcategoriesById
- 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 forcontext
- 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 forcontext
- 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 forcontext
- 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 IDcategoriesById
- categories mapped by IDfullCategoryLines
- map of categories to their full category ancestry linesinheritanceLines
- the catalog inheritance lines top-down from all of the productscontext
- 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 thecategoryProduct
from thepotentialCategories
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 forpotentialCategories
- all categories matching the category ID from the category productinheritanceLines
- the catalog inheritance lines top-down from all of the productscontext
- 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 cataloginheritanceLines
- The catalog inheritance lines- Returns:
- True if the catalog is in the inheritnace lines, otherwise false
-
setCategoryForCategoryProductRef
-
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 statesunmatchedCategories
- categories whose contexts don't match a category product alreadyfullCategoryLines
- map of categories to their full category ancestry linesinheritanceLines
- the catalog inheritance lines top-down from all of the products- Returns:
- the new generated category product relationships
-
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 classContextualProductConsolidationContributor<CategoryProductRef>
- Returns:
- function to retrieve Product ID of the domain object
-
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 classContextualProductConsolidationContributor<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 classContextualProductConsolidationContributor<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 oncategoryProducts
- 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 forcategoryProducts
- all the categories for the product
-
getCategoryProductService
-
getCategoryService
-
getCatalogService
protected com.broadleafcommerce.data.tracking.core.tenant.service.CommonCatalogService<com.broadleafcommerce.data.tracking.core.tenant.domain.Catalog> getCatalogService() -
getCategoryAncestorsCache
-