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 Summary
Modifier and TypeFieldDescriptionprotected final com.broadleafcommerce.common.extension.TypeFactory
-
Constructor Summary
ConstructorDescriptionDataDrivenEnumConsolidationContributor
(com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addDataDrivenEnumId
(DataDrivenEnum dataDrivenEnum, List<String> enumIds) protected void
addDataDrivenEnumIdsForProduct
(ConsolidatedProduct product, List<String> enumIds) 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) Consolidate products with their related domain and translations.getDataDrivenEnumIds
(@NonNull Collection<? extends ConsolidatedProduct> consolidatedProducts) Gets a set of referenced data driven enum ids mapped by the product id.protected DataDrivenEnumService<DataDrivenEnum>
protected List<com.broadleafcommerce.translation.domain.Translation>
getDataDrivenEnumTranslations
(List<String> allDataDrivenEnumIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation>
protected com.broadleafcommerce.common.extension.TypeFactory
protected <P extends ConsolidatedProduct>
voidsetDataDrivenEnumIfPresent
(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 toConsolidatedProduct.getDataDrivenEnums()
.protected void
setDataDrivenEnumsForProduct
(ConsolidatedProduct product, List<DataDrivenEnum> dataDrivenEnumsForAllProducts) protected void
setDataDrivenEnumTranslationsForProduct
(ConsolidatedProduct product, List<com.broadleafcommerce.translation.domain.Translation> dataDrivenEnumTranslationsForAllProducts)
-
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 hydratingProduct
fields 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:
consolidateProducts
in 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
-
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 ofConsolidatedProduct
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
-
addDataDrivenEnumId
-
getDataDrivenEnumTranslations
-
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 toConsolidatedProduct.getDataDrivenEnums()
.- Type Parameters:
P
- The type of theConsolidatedProduct
- Parameters:
product
- product to set the data driven enum field fordataDrivenEnumsForAllProducts
- a list of data driven enums for all productsdataDrivenEnumGetter
- the getter to get the data driven enum field from the productdataDrivenEnumSetter
- 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
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-