Class OptionTemplateProductConsolidationContributor

java.lang.Object
com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor<OptionTemplate>
com.broadleafcommerce.catalog.service.product.consolidation.OptionTemplateProductConsolidationContributor
All Implemented Interfaces:
ProductConsolidationContributor

public class OptionTemplateProductConsolidationContributor extends ContextualProductConsolidationContributor<OptionTemplate>
Contributor responsible for consolidating OptionTemplates referenced by Products' Options.
Author:
Susana Cruz (susanaccruz)
  • Field Details

  • Constructor Details

    • OptionTemplateProductConsolidationContributor

      public OptionTemplateProductConsolidationContributor(com.broadleafcommerce.common.extension.TypeFactory typeFactory, OptionTemplateService<OptionTemplate> optionTemplateService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService)
  • Method Details

    • 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 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
    • consolidateProducts

      public void consolidateProducts(@NonNull @NonNull Set<String> productIds, @NonNull @NonNull List<ConsolidatedProduct> products, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @NonNull @NonNull 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
      Overrides:
      consolidateProducts in class ContextualProductConsolidationContributor<OptionTemplate>
      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 List<OptionTemplate> getObjectsToConsolidate(@NonNull @NonNull Set<String> optionTemplateIds, @NonNull @NonNull List<ConsolidatedProduct> products, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @NonNull @NonNull 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 class ContextualProductConsolidationContributor<OptionTemplate>
      Parameters:
      optionTemplateIds - the IDs of the products to consolidate
      products - the products in all explicit context states
      inheritanceLines - the catalog inheritance lines top-down from all of the products
      context - context information surrounding sandboxing/multitenant state
      Returns:
      all domain objects of this type to consolidate into the products
    • productIdGetter

      protected Function<OptionTemplate,String> 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 class ContextualProductConsolidationContributor<OptionTemplate>
      Returns:
      function to retrieve Product ID 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 class ContextualProductConsolidationContributor<OptionTemplate>
      Returns:
      function to set domain objects on the consolidated product
    • idGetter

      protected Function<OptionTemplate,String> 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 class ContextualProductConsolidationContributor<OptionTemplate>
      Returns:
      function to retrieve contextId of the domain object
    • buildProductIdToOptionTemplateIdMap

      protected Map<String,Set<String>> buildProductIdToOptionTemplateIdMap(@NonNull @NonNull List<ConsolidatedProduct> products)
      Builds a map of OptionTemplate ids mapped to the ids of Products that reference them via them own ProductOptions.
      Parameters:
      products - Products to consolidate
      Returns:
      A map of OptionTemplate ids mapped to the Products that reference them via them own ProductOptions.
    • buildProductIdToOptionTemplates

      protected Map<String,List<OptionTemplate>> buildProductIdToOptionTemplates(@NonNull @NonNull Map<String,Set<String>> optionTemplateIdsToProductId, @NonNull @NonNull List<OptionTemplate> objectsToConsolidate)
      Builds a map of OptionTemplates mapped by the ids of Products that reference them via them own ProductOptions.
      Parameters:
      optionTemplateIdsToProductId - Map of Product ids to the ids of option templates that they reference
      objectsToConsolidate - Option Templates referenced by the products to consolidate that need to be added to the map.
      Returns:
      A map of OptionTemplates mapped by the ids of Products that reference them via them own ProductOptions.
    • setOptions

      protected void setOptions(@NonNull @NonNull ConsolidatedProduct product, @NonNull @NonNull List<? extends OptionTemplate> optionTemplates)
    • getOptionsFromTemplates

      protected List<ProductOption> getOptionsFromTemplates(@NonNull @NonNull Collection<? extends OptionTemplate> optionTemplates)
    • consolidateOptionTemplates

      protected void consolidateOptionTemplates(@NonNull @NonNull List<ConsolidatedProduct> products, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @NonNull @NonNull Map<String,List<ConsolidatedProduct>> productsById, @NonNull @NonNull Map<String,List<OptionTemplate>> objectsToConsolidateByProductId)
      Consolidates the OptionTemplates onto the related ConsolidatedProducts.
      Parameters:
      products - Products to be consolidated
      inheritanceLines - Catalog inheritance lines
      productsById - Map of products by their ids
      objectsToConsolidateByProductId - Map of option templates by their related product's id
    • consolidateTranslations

      protected void consolidateTranslations(@NonNull @NonNull List<ConsolidatedProduct> products, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Retrieves and adds option template translations to the consolidated products.
      Parameters:
      products - Products to be consolidated
      context - Additional tenant and sandbox info
    • getTranslations

      protected List<com.broadleafcommerce.translation.domain.Translation> getTranslations(List<String> entityIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getOptionTemplateService

      protected OptionTemplateService<OptionTemplate> getOptionTemplateService()
    • getTranslationEntityService

      protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService()