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 Details

  • 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
    • 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 states
      relations - the related domain in all explicit context states
      unmatchedRelations - relations whose contexts don't match a product already
      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:
      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 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
    • 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 entitiesToMatch to 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 state
      entitiesToMatch - versions of an entity from multiple contexts
      inheritanceLines - 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 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, and set the appropriate relationship values for it.
      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
    • 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 for
      implicitProduct - 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 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

      @Deprecated protected org.modelmapper.ModelMapper getCloneMapper()
      Deprecated.
      please see getObjectDeepCopyUtility() for performance
    • getRsqlParser

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

      protected ObjectDeepCopyUtility getObjectDeepCopyUtility()
    • setObjectDeepCopyUtility

      @Autowired public void setObjectDeepCopyUtility(ObjectDeepCopyUtility objectDeepCopyUtility)