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 Summary
Fields inherited from class com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor
IGNORE_ARCHIVED_FILTER, typeFactory
-
Constructor Summary
ConstructorDescriptionOptionTemplateProductConsolidationContributor
(com.broadleafcommerce.common.extension.TypeFactory typeFactory, OptionTemplateService<OptionTemplate> optionTemplateService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService) -
Method Summary
Modifier and TypeMethodDescriptionbuildProductIdToOptionTemplateIdMap
(@NonNull List<ConsolidatedProduct> products) Builds a map ofOptionTemplate
ids mapped to the ids ofProducts
that reference them via them ownProductOptions
.protected Map<String,
List<OptionTemplate>> buildProductIdToOptionTemplates
(@NonNull Map<String, Set<String>> optionTemplateIdsToProductId, @NonNull List<OptionTemplate> objectsToConsolidate) Builds a map ofOptionTemplates
mapped by the ids ofProducts
that reference them via them ownProductOptions
.protected void
consolidateOptionTemplates
(@NonNull List<ConsolidatedProduct> products, @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @NonNull Map<String, List<ConsolidatedProduct>> productsById, @NonNull Map<String, List<OptionTemplate>> objectsToConsolidateByProductId) Consolidates theOptionTemplates
onto the relatedConsolidatedProducts
.void
consolidateProducts
(@NonNull Set<String> productIds, @NonNull List<ConsolidatedProduct> products, @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Consolidate products with their related domain and translations.protected void
consolidateTranslations
(@NonNull List<ConsolidatedProduct> products, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieves and adds option template translations to the consolidated products.protected List<OptionTemplate>
getObjectsToConsolidate
(@NonNull Set<String> optionTemplateIds, @NonNull List<ConsolidatedProduct> products, @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.InheritanceLines inheritanceLines, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve the full list of domain objects of this type to be consolidated into the products.protected List<ProductOption>
getOptionsFromTemplates
(@NonNull Collection<? extends OptionTemplate> optionTemplates) protected OptionTemplateService<OptionTemplate>
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation>
protected List<com.broadleafcommerce.translation.domain.Translation>
getTranslations
(List<String> entityIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Function<OptionTemplate,
String> idGetter()
Defines the function which retrieves the contextId of the domain object in order to recognize it in different contexts.protected Function<OptionTemplate,
String> 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.protected void
setOptions
(@NonNull ConsolidatedProduct product, @NonNull List<? extends OptionTemplate> optionTemplates) protected BiConsumer<ConsolidatedProduct,
List<OptionTemplate>> setter()
Defines the function which should be used to set the domain objects on the consolidated product.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) Determines whether this contributor should be executed based on the given parameters and context.Methods inherited from class com.broadleafcommerce.catalog.service.product.consolidation.ContextualProductConsolidationContributor
consolidateRelations, contextCompositeKey, contextCompositeKey, contextStatesMatch, createOverrideProductForContext, findImplicitMatches, getCloneMapper, getInheritanceLevel, getMostSpecificCatalogId, getProductConsolidationRequest, getRsqlParser, getTypeFactory, ignoreArchived, isInheriting, setListValue, setSingleValue
-
Field Details
-
OPTION_TRANSLATION_HINT
- See Also:
-
-
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 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
-
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 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
- Overrides:
consolidateProducts
in classContextualProductConsolidationContributor<OptionTemplate>
- 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
-
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 classContextualProductConsolidationContributor<OptionTemplate>
- Parameters:
optionTemplateIds
- the IDs of the products to consolidateproducts
- the products in all explicit context statesinheritanceLines
- the catalog inheritance lines top-down from all of the productscontext
- context information surrounding sandboxing/multitenant state- Returns:
- all domain objects of this type to consolidate into the products
-
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 classContextualProductConsolidationContributor<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 classContextualProductConsolidationContributor<OptionTemplate>
- Returns:
- function to set domain objects on the consolidated product
-
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 classContextualProductConsolidationContributor<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 ofOptionTemplate
ids mapped to the ids ofProducts
that reference them via them ownProductOptions
.- Parameters:
products
- Products to consolidate- Returns:
- A map of
OptionTemplate
ids mapped to theProducts
that reference them via them ownProductOptions
.
-
buildProductIdToOptionTemplates
protected Map<String,List<OptionTemplate>> buildProductIdToOptionTemplates(@NonNull @NonNull Map<String, Set<String>> optionTemplateIdsToProductId, @NonNull @NonNull List<OptionTemplate> objectsToConsolidate) Builds a map ofOptionTemplates
mapped by the ids ofProducts
that reference them via them ownProductOptions
.- Parameters:
optionTemplateIdsToProductId
- Map of Product ids to the ids of option templates that they referenceobjectsToConsolidate
- 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 ofProducts
that reference them via them ownProductOptions
.
-
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 theOptionTemplates
onto the relatedConsolidatedProducts
.- Parameters:
products
- Products to be consolidatedinheritanceLines
- Catalog inheritance linesproductsById
- Map of products by their idsobjectsToConsolidateByProductId
- 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 consolidatedcontext
- Additional tenant and sandbox info
-
getTranslations
-
getOptionTemplateService
-
getTranslationEntityService
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService()
-