Class DataDrivenEnumConsolidationContributor

java.lang.Object
com.broadleafcommerce.catalog.service.product.consolidation.DataDrivenEnumConsolidationContributor
All Implemented Interfaces:
ProductConsolidationContributor

public class DataDrivenEnumConsolidationContributor extends Object implements ProductConsolidationContributor
Consolidates all DataDrivenEnums and their Translations from Product.getBrand(), Product.getMerchandisingType(), and Product.getTargetDemographic() into products.

Unlike ProductAsset and Variant, DataDrivenEnum is independent of Product and doesn't have a direct relationship with Product like other entities do. Therefore, the consolidation of its Translations is done here instead of TranslationProductConsolidationContributor.

This contributor should run after TranslationProductConsolidationContributor, so that it can add the data driven enums' translations on top of all the ProductTranslations consolidated from TranslationProductConsolidationContributor.

Author:
Sunny Yu
  • Field Details

    • typeFactory

      protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory
  • Constructor Details

    • DataDrivenEnumConsolidationContributor

      public DataDrivenEnumConsolidationContributor(com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • 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
    • getDataDrivenEnumIds

      protected List<String> getDataDrivenEnumIds(@NonNull @NonNull Collection<? extends ConsolidatedProduct> consolidatedProducts)
      Gets a set of referenced data driven enum ids mapped by the product id.
      Parameters:
      consolidatedProducts - a collection of ConsolidatedProduct to get the resolved product and its referenced data driven enums from
      Returns:
      a set of referenced data driven enum ids mapped by the resolved product id
    • addDataDrivenEnumIdsForProduct

      protected void addDataDrivenEnumIdsForProduct(ConsolidatedProduct product, List<String> enumIds)
    • addDataDrivenEnumId

      protected void addDataDrivenEnumId(@Nullable DataDrivenEnum dataDrivenEnum, List<String> enumIds)
    • getDataDrivenEnumTranslations

      protected List<com.broadleafcommerce.translation.domain.Translation> getDataDrivenEnumTranslations(List<String> allDataDrivenEnumIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • setDataDrivenEnumsForProduct

      protected void setDataDrivenEnumsForProduct(ConsolidatedProduct product, List<DataDrivenEnum> dataDrivenEnumsForAllProducts)
    • setDataDrivenEnumIfPresent

      protected <P extends ConsolidatedProduct> void setDataDrivenEnumIfPresent(P product, List<DataDrivenEnum> dataDrivenEnumsForAllProducts, Function<P,DataDrivenEnum> dataDrivenEnumGetter, BiConsumer<P,DataDrivenEnum> dataDrivenEnumSetter)
      Finds and sets the product's data driven enum field if present using the given getter and setter, and add the enum to ConsolidatedProduct.getDataDrivenEnums().
      Type Parameters:
      P - The type of the ConsolidatedProduct
      Parameters:
      product - product to set the data driven enum field for
      dataDrivenEnumsForAllProducts - a list of data driven enums for all products
      dataDrivenEnumGetter - the getter to get the data driven enum field from the product
      dataDrivenEnumSetter - the setter to set the data driven enum field for the product
    • setDataDrivenEnumTranslationsForProduct

      protected void setDataDrivenEnumTranslationsForProduct(ConsolidatedProduct product, List<com.broadleafcommerce.translation.domain.Translation> dataDrivenEnumTranslationsForAllProducts)
    • getTranslationEntityService

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

      protected DataDrivenEnumService<DataDrivenEnum> getDataDrivenEnumService()
    • getTypeFactory

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