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, 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 Details

    • IGNORE_ARCHIVED_FILTER

      public static final String 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 hydrating Product fields and combining external references like CategoryProduct. 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 interface ProductConsolidationContributor
      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 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 consolidate
      products - the products in all explicit context states
      context - context information surrounding sandboxing/multitenant state
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      Returns:
      all domain objects of this type to consolidate into the products
    • productIdGetter

      protected abstract Function<P,String> 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

      protected abstract BiConsumer<ConsolidatedProduct,List<P>> 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

      protected abstract Function<P,String> 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 on
      toSet - single-valued list with value to set on consolidated product
      setter - 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 on
      toSet - list with values to set on consolidated product
      setter - 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 states
      relations - the related domain in all explicit context states
      setRelation - the operator to set the related domain value on the product
      idGetter - the operator to get the ID from the related domain
      inheritanceLines - 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 another
      relationContext - a context state to check against another
      Returns:
      whether the context states are in the same context
    • contextCompositeKey

      protected <T extends com.broadleafcommerce.data.tracking.core.ContextStateAware> List<Object> contextCompositeKey(T relation)
    • contextCompositeKey

      protected List<Object> contextCompositeKey(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState context)
    • 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 state
      entitiesToMatch - versions of an entity from multiple contexts
      inheritanceLines - 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 catalog
      candidate - The id of the candidate catalog
      inheritanceLines - 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 catalog
      inheritanceLines - 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 for
      relations - the related domain in all explicit context states
      implicitProduct - the implicitly resolved product for the relation's context
      setRelation - the operator to set the related domain value on the product
      idGetter - the operator to get the ID from the related domain
      inheritanceLines - 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)
    • getProductConsolidationRequest

      protected ProductConsolidationRequest getProductConsolidationRequest(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Gets the ProductConsolidationRequest from the given ContextInfo.
      Parameters:
      contextInfo - the ContextInfo to get the the ProductConsolidationRequest
      Returns:
      the ProductConsolidationRequest for the product consolidation flow
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getCloneMapper

      protected org.modelmapper.ModelMapper getCloneMapper()
    • getRsqlParser

      protected cz.jirutka.rsql.parser.RSQLParser getRsqlParser()