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:
AllAssetsProductConsolidationContributor,CategoryProductConsolidationContributor,OptionTemplateProductConsolidationContributor,PrimaryAssetProductConsolidationContributor,ProductCharacteristicsConsolidationContributor,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
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected final com.broadleafcommerce.common.extension.TypeFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedContextualProductConsolidationContributor(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protectedContextualProductConsolidationContributor(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 TypeMethodDescriptionprotected cz.jirutka.rsql.parser.ast.NodevoidconsolidateProducts(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 booleancontextStatesMatch(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 ConsolidatedProductcreateOverrideProductForContext(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, and set the appropriate relationship values for it.protected ConsolidatedProductcreateUnmodifiedOverrideProductForContext(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState unmatchedContextState, ConsolidatedProduct implicitProduct) Generate a placeholder consolidated product to represent the unmatched context override.protected <T> TdeepCopy(T source) 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 <T extends com.broadleafcommerce.data.tracking.core.ContextStateAware>
Stream<T>findImplicitMatchVisibleCandidates(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) For the given context, filter the givenentitiesToMatchto only return the candidate items that would be considered potentially visible in that context.protected List<ConsolidatedProduct>generateNewOverriddenProducts(List<ConsolidatedProduct> products, List<P> relations, List<P> unmatchedRelations, BiConsumer<ConsolidatedProduct, List<P>> setRelation, Function<P, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) For relations in contexts which do not exactly match any existing products, generate new product placeholders with those contexts to hold the overrides.protected org.modelmapper.ModelMapperDeprecated.static intgetInheritanceLevel(String catalogId, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) Get the inheritance level of the catalog in the inheritance lines.protected StringgetMostSpecificCatalogId(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context) protected ObjectDeepCopyUtilitygetObjectsToConsolidate(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 ProductConsolidationRequestgetProductConsolidationRequest(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductConsolidationRequestfrom the givenContextInfo.protected cz.jirutka.rsql.parser.RSQLParserprotected com.broadleafcommerce.common.extension.TypeFactoryidGetter()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.NodeignoreArchived(cz.jirutka.rsql.parser.ast.Node filters) static booleanisInheriting(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 voidsetListValue(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.voidsetObjectDeepCopyUtility(ObjectDeepCopyUtility objectDeepCopyUtility) protected voidsetSingleValue(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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.catalog.service.product.consolidation.ProductConsolidationContributor
shouldConsolidate
-
Field Details
-
IGNORE_ARCHIVED_FILTER
-
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:ProductConsolidationContributorConsolidate products with their related domain and translations. This includes both hydratingProductfields 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:
consolidateProductsin 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
-
generateNewOverriddenProducts
protected List<ConsolidatedProduct> generateNewOverriddenProducts(List<ConsolidatedProduct> products, List<P> relations, List<P> unmatchedRelations, BiConsumer<ConsolidatedProduct, List<P>> setRelation, Function<P, String> idGetter, com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines) For relations in contexts which do not exactly match any existing products, generate new product placeholders with those contexts to hold the overrides.- Parameters:
products- the product in all explicit context statesrelations- the related domain in all explicit context statesunmatchedRelations- relations whose contexts don't match a product alreadysetRelation- 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:
- the new generated products
-
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
-
findImplicitMatchVisibleCandidates
protected <T extends com.broadleafcommerce.data.tracking.core.ContextStateAware> Stream<T> findImplicitMatchVisibleCandidates(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) For the given context, filter the given
entitiesToMatchto only return the candidate items that would be considered potentially visible in that context. This method does not reduce the input down to only the 'most derived' instance for any given entity context ID - multiple results will still be returned for each context ID (ex: multiple sandbox representations, multiple catalog representations, etc).The main responsibilities of this method are to:
- Filter the input to only include results from the same catalog as the provided context, or any of its ancestor catalogs
- Filter the input to only include results whose sandbox level is the same as the provided context, or greater (ex: production context should not see a sandbox-level entity)
- Filter the input such that user-level sandbox records are only included if the author matches the one in the 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:
- a filtered representation of the input
entitiesToMatch, discarding any entities that would never be visible from the provided 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, and set the appropriate relationship values for it.- 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
-
createUnmodifiedOverrideProductForContext
protected ConsolidatedProduct createUnmodifiedOverrideProductForContext(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState unmatchedContextState, ConsolidatedProduct implicitProduct) Generate a placeholder consolidated product to represent the unmatched context override.- Parameters:
unmatchedContextState- the context state to create an override product forimplicitProduct- the implicitly resolved product for the relation's context. This product will be used as the basis to create the clone.- Returns:
- new consolidated product in the relation's overridden context
-
deepCopy
protected <T> T deepCopy(T source) -
ignoreArchived
protected cz.jirutka.rsql.parser.ast.Node ignoreArchived(@Nullable cz.jirutka.rsql.parser.ast.Node filters) -
buildIgnoreArchivedFilter
protected cz.jirutka.rsql.parser.ast.Node buildIgnoreArchivedFilter() -
getProductConsolidationRequest
protected ProductConsolidationRequest getProductConsolidationRequest(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductConsolidationRequestfrom the givenContextInfo.- Parameters:
contextInfo- theContextInfoto get the theProductConsolidationRequest- Returns:
- the
ProductConsolidationRequestfor the product consolidation flow
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getCloneMapper
Deprecated.please seegetObjectDeepCopyUtility()for performance -
getRsqlParser
protected cz.jirutka.rsql.parser.RSQLParser getRsqlParser() -
getObjectDeepCopyUtility
-
setObjectDeepCopyUtility
-
getObjectDeepCopyUtility()for performance