Class ContextualProductConsolidationContributor<P extends com.broadleafcommerce.data.tracking.core.ContextStateAware>
java.lang.Object
com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor<P>
- Type Parameters:
P
- the type of domain to consolidate into the product
- All Implemented Interfaces:
ProductConsolidationContributor
- Direct Known Subclasses:
CategoryProductConsolidationContributor
,PrimaryAssetProductConsolidationContributor
,ProductTagConsolidationContributor
,TranslationProductConsolidationContributor
,VariantProductConsolidationContributor
public abstract class ContextualProductConsolidationContributor<P extends com.broadleafcommerce.data.tracking.core.ContextStateAware>
extends Object
implements ProductConsolidationContributor
Supports
ProductConsolidationContributor
which consolidate ContextStateAware
domain types into the product.-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected final com.broadleafcommerce.common.extension.TypeFactory
-
Constructor Summary
ModifierConstructorDescriptionprotected
ContextualProductConsolidationContributor
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected
ContextualProductConsolidationContributor
(com.broadleafcommerce.common.extension.TypeFactory typeFactory, cz.jirutka.rsql.parser.RSQLParser rsqlParser) ContextualProductConsolidationContributor
(com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.modelmapper.ModelMapper cloneMapper, cz.jirutka.rsql.parser.RSQLParser rsqlParser) -
Method Summary
Modifier and TypeMethodDescriptionvoid
consolidateProducts
(Set<String> productIds, List<ConsolidatedProduct> products, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Consolidate products with their related domain and translations.protected List<ConsolidatedProduct>
consolidateRelations
(List<ConsolidatedProduct> products, List<P> relations, BiConsumer<ConsolidatedProduct, List<P>> setRelation, Function<P, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Hydrate the given contextual products with the given relations.contextCompositeKey
(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) contextCompositeKey
(T relation) protected boolean
contextStatesMatch
(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState productContext, com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState relationContext) Check if the two context states are in the exact same catalog and sandbox context.protected ConsolidatedProduct
createOverrideProductForContext
(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState unmatchedContextState, List<P> relations, ConsolidatedProduct implicitProduct, BiConsumer<ConsolidatedProduct, List<P>> setRelation, Function<P, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Generate a placeholder consolidated product to represent the unmatched context override.protected <T extends com.broadleafcommerce.data.tracking.core.ContextStateAware>
Stream<T>findImplicitMatches
(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context, List<T> entitiesToMatch, Function<T, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Find the appropriate versions of the provided entities which would be implicitly resolved in the given context.protected org.modelmapper.ModelMapper
static int
getInheritanceLevel
(String catalogId, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Get the inheritance level of the catalog in the inheritance lines.protected String
getMostSpecificCatalogId
(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) 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 cz.jirutka.rsql.parser.RSQLParser
protected com.broadleafcommerce.common.extension.TypeFactory
idGetter()
Defines the function which retrieves the contextId of the domain object in order to recognize it in different contexts.protected cz.jirutka.rsql.parser.ast.Node
ignoreArchived
(cz.jirutka.rsql.parser.ast.Node filters) static boolean
isInheriting
(String reference, String candidate, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Determine if the candidate catalog id represents a catalog that inherits from a catalog represented by the reference catalog id.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
setListValue
(ConsolidatedProduct product, List<P> toSet, BiConsumer<ConsolidatedProduct, List<P>> setter) Setter function provider which uses the provided setter to set a list value in the consolidated product.protected void
setSingleValue
(ConsolidatedProduct product, List<P> toSet, BiConsumer<ConsolidatedProduct, P> setter) Setter function provider which uses the provided setter to set a single value in the consolidated product.protected abstract BiConsumer<ConsolidatedProduct,
List<P>> setter()
Defines the function which should be used to set the domain objects on the consolidated product.
-
Field Details
-
IGNORE_ARCHIVED_FILTER
- See Also:
-
typeFactory
protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory
-
-
Constructor Details
-
ContextualProductConsolidationContributor
protected ContextualProductConsolidationContributor(com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
ContextualProductConsolidationContributor
protected ContextualProductConsolidationContributor(com.broadleafcommerce.common.extension.TypeFactory typeFactory, cz.jirutka.rsql.parser.RSQLParser rsqlParser) -
ContextualProductConsolidationContributor
public ContextualProductConsolidationContributor(com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.modelmapper.ModelMapper cloneMapper, cz.jirutka.rsql.parser.RSQLParser rsqlParser)
-
-
Method Details
-
consolidateProducts
public void consolidateProducts(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
Consolidate products with their related domain and translations. This includes both hydratingProduct
fields and combining external references likeCategoryProduct
. Any catalog or sandbox overrides made to external references for non-overridden products will generate new placeholder products to store those overrides.- Specified by:
consolidateProducts
in interfaceProductConsolidationContributor
- 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 abstract List<P> 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.- Parameters:
productIds
- the IDs of the products to consolidateproducts
- the products in all explicit context statescontext
- context information surrounding sandboxing/multitenant stateinheritanceLines
- the catalog inheritance lines top-down from all of the products- Returns:
- all domain objects of this type to consolidate into the products
-
productIdGetter
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.- Returns:
- function to retrieve Product ID of the domain object
-
setter
Defines the function which should be used to set the domain objects on the consolidated product.- Returns:
- function to set domain objects on the consolidated product
-
idGetter
Defines the function which retrieves the contextId of the domain object in order to recognize it in different contexts.- Returns:
- function to retrieve contextId of the domain object
-
setSingleValue
protected void setSingleValue(ConsolidatedProduct product, List<P> toSet, BiConsumer<ConsolidatedProduct, P> setter) Setter function provider which uses the provided setter to set a single value in the consolidated product.- Parameters:
product
- the product to set the value ontoSet
- single-valued list with value to set on consolidated productsetter
- function to set value on consolidated product
-
setListValue
protected void setListValue(ConsolidatedProduct product, List<P> toSet, BiConsumer<ConsolidatedProduct, List<P>> setter) Setter function provider which uses the provided setter to set a list value in the consolidated product.- Parameters:
product
- the product to set the values ontoSet
- list with values to set on consolidated productsetter
- function to set values on consolidated product
-
consolidateRelations
protected List<ConsolidatedProduct> consolidateRelations(List<ConsolidatedProduct> products, List<P> relations, BiConsumer<ConsolidatedProduct, List<P>> setRelation, Function<P, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Hydrate the given contextual products with the given relations. If there are any relations in a context which does not exactly match any existing products, then generate a new product placeholder with that context to hold the override.- Parameters:
products
- the product in all explicit context statesrelations
- the related domain in all explicit context statessetRelation
- the operator to set the related domain value on the productidGetter
- the operator to get the ID from the related domaininheritanceLines
- the catalog inheritance lines top-down from all of the products- Returns:
- newly generated products which didn't match an existing product context
-
contextStatesMatch
protected boolean contextStatesMatch(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState productContext, com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState relationContext) Check if the two context states are in the exact same catalog and sandbox context.- Parameters:
productContext
- a context state to check against anotherrelationContext
- a context state to check against another- Returns:
- whether the context states are in the same context
-
contextCompositeKey
-
contextCompositeKey
-
findImplicitMatches
protected <T extends com.broadleafcommerce.data.tracking.core.ContextStateAware> Stream<T> findImplicitMatches(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context, List<T> entitiesToMatch, Function<T, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Find the appropriate versions of the provided entities which would be implicitly resolved in the given context.- Parameters:
context
- context information surrounding sandboxing/multitenant stateentitiesToMatch
- versions of an entity from multiple contextsinheritanceLines
- the catalog inheritance lines top-down from all of the products- Returns:
- the entities implicitly resolved for the context
-
getMostSpecificCatalogId
protected String getMostSpecificCatalogId(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) -
isInheriting
public static boolean isInheriting(String reference, String candidate, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Determine if the candidate catalog id represents a catalog that inherits from a catalog represented by the reference catalog id.- Parameters:
reference
- The id of the reference catalogcandidate
- The id of the candidate cataloginheritanceLines
- the catalog inheritance lines- Returns:
- Whether or not the candidate inherits from the reference
-
getInheritanceLevel
public static int getInheritanceLevel(String catalogId, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Get the inheritance level of the catalog in the inheritance lines.- Parameters:
catalogId
- The id of the cataloginheritanceLines
- The catalog inheritance lines- Returns:
- The inheritance level, or -1 if not found
-
createOverrideProductForContext
protected ConsolidatedProduct createOverrideProductForContext(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState unmatchedContextState, List<P> relations, ConsolidatedProduct implicitProduct, BiConsumer<ConsolidatedProduct, List<P>> setRelation, Function<P, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Generate a placeholder consolidated product to represent the unmatched context override.- Parameters:
unmatchedContextState
- the context state to create an override product forrelations
- the related domain in all explicit context statesimplicitProduct
- the implicitly resolved product for the relation's contextsetRelation
- the operator to set the related domain value on the productidGetter
- the operator to get the ID from the related domaininheritanceLines
- the catalog inheritance lines top-down from all of the products- Returns:
- new consolidated product in the relation's overridden context
-
ignoreArchived
protected cz.jirutka.rsql.parser.ast.Node ignoreArchived(@Nullable cz.jirutka.rsql.parser.ast.Node filters) -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getCloneMapper
protected org.modelmapper.ModelMapper getCloneMapper() -
getRsqlParser
protected cz.jirutka.rsql.parser.RSQLParser getRsqlParser()
-