Class DefaultProductHydrationService
java.lang.Object
com.broadleafcommerce.catalog.service.product.hydration.DefaultProductHydrationService
- All Implemented Interfaces:
ProductHydrationService
- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorDescriptionDefaultProductHydrationService
(ProductService<Product> productService, ProductAssetService<ProductAsset> productAssetService, VariantService<Variant> variantService, CategoryService<Category> categoryService, CategoryProductService<CategoryProduct> categoryProductService, DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyHydration
(DataDrivenEnum dataDrivenEnum, String hydrationTarget, ResolvedProductReferences foundItems) protected void
applyHydration
(IncludedProduct includedProduct, ResolvedProductReferences foundItems) protected void
applyHydration
(ItemChoice itemChoice, ResolvedProductReferences foundItems) protected ProductOption
applyHydration
(ProductOption option, ResolvedProductReferences foundItems) Deprecated.protected ProductOption
applyHydration
(ProductOption option, ResolvedProductReferences foundItems, List<Variant> variants) Traverses through theoption
and replaces each item reference with the fully-populated representation of the reference as found infoundItems
.protected void
applyHydration
(SpecificItemChoice specificChoice, ResolvedProductReferences foundItems) protected Product
applyHydration
(Product product, ResolvedProductReferences foundItems) Deprecated.protected Product
applyHydration
(Product product, ResolvedProductReferences foundItems, List<Variant> variants) Traverses through theproduct
and replaces each item reference with the fully-populated representation of the reference as found infoundItems
.protected String
buildSkuAndProductIdKey
(String productId, String sku) protected void
determineReferences
(DataDrivenEnum dataDrivenEnum, ProductReferences references) protected void
determineReferences
(IncludedProduct includedProduct, ProductReferences references) protected void
determineReferences
(ItemChoice itemChoice, ProductReferences references) protected void
determineReferences
(ProductOption productOption, ProductReferences references) protected void
determineReferences
(SpecificItemChoice specificChoice, ProductReferences references) protected void
determineReferences
(Product product, ProductReferences references) Traverses through theproduct
and populates thereferences
with each referenced ID.protected void
findOptionTemplateReferences
(ProductReferences references, ResolvedProductReferences resolved) Collects the ids of all products and variants referenced by anOptionTemplate
.protected ResolvedProductReferences
findReferences
(ProductReferences references, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for all of the references inreferences
and returns the results.protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
protected DataDrivenEnumService<DataDrivenEnum>
protected OptionTemplateService<OptionTemplate>
protected ProductAssetService<ProductAsset>
getProductIds
(List<Map.Entry<String, String>> partition) protected ProductService<Product>
protected com.broadleafcommerce.common.extension.TypeFactory
protected VariantService<Variant>
hydrate
(@NonNull Product unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the IDs of items that are referenced by theunhydrated
product, finds the referenced items in the data store, and then replaces each item reference on the product with the fully-populated representation of the item.org.springframework.data.domain.Page<Product>
hydrate
(@NonNull org.springframework.data.domain.Page<Product> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the IDs of items that are referenced by each product, finds the referenced items in the data store, and then replaces each item reference on the product with the fully-populated representation of the item.hydrate
(ProductOption unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the IDs of items that are referenced by theunhydrated
option, finds the referenced items in the data store, and then replaces each item reference on the option with the fully-populated representation of the item.protected void
hydrateDefaultVariant
(ResolvedProductReferences foundItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) org.springframework.data.domain.Page<Product>
hydratePrimaryAssets
(org.springframework.data.domain.Page<Product> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Specifically finds and hydrates theProduct.primaryAsset
of each product in the given page.void
setOptionTemplateService
(OptionTemplateService<OptionTemplate> optionTemplateService) protected void
setProductDataDrivenEnumFieldsIfFound
(Product product, ResolvedProductReferences foundItems) protected void
setProductPrimaryAssetIfFound
(Product product, ResolvedProductReferences foundItems) protected void
setProductPrimaryCategoryIfFound
(Product product, ResolvedProductReferences foundItems)
-
Constructor Details
-
DefaultProductHydrationService
public DefaultProductHydrationService(ProductService<Product> productService, ProductAssetService<ProductAsset> productAssetService, VariantService<Variant> variantService, CategoryService<Category> categoryService, CategoryProductService<CategoryProduct> categoryProductService, DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
hydrate
public Product hydrate(@NonNull @NonNull Product unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationService
Gets the IDs of items that are referenced by theunhydrated
product, finds the referenced items in the data store, and then replaces each item reference on the product with the fully-populated representation of the item.The class-level javadoc above describes the references which will be hydrated by default.
- Specified by:
hydrate
in interfaceProductHydrationService
- Parameters:
unhydrated
- the unhydrated product whose references should be hydrated- Returns:
- the product after applying the hydration
-
determineReferences
Traverses through theproduct
and populates thereferences
with each referenced ID.- Parameters:
product
- the product whose references should be examinedreferences
- each item that theproduct
makes a reference to will be added to this object
-
determineReferences
protected void determineReferences(@Nullable DataDrivenEnum dataDrivenEnum, ProductReferences references) -
determineReferences
-
determineReferences
-
determineReferences
-
determineReferences
-
findReferences
protected ResolvedProductReferences findReferences(ProductReferences references, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for all of the references inreferences
and returns the results.- Parameters:
references
- all of the references that need to be found in the data storecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the results of querying for the referenced items
-
findOptionTemplateReferences
protected void findOptionTemplateReferences(ProductReferences references, ResolvedProductReferences resolved) Collects the ids of all products and variants referenced by anOptionTemplate
. These ids are needed to resolve the products and variants that later will be hydrated onto the product option byapplyHydration(SpecificItemChoice, ResolvedProductReferences)
. This method may resolve the appropriate ids once theResolvedProductReferences.optionTemplatesById
have been resolved.- Parameters:
references
- the product references to updateresolved
- the object containing the list of resolved option templates
-
applyHydration
Deprecated. -
applyHydration
protected Product applyHydration(Product product, ResolvedProductReferences foundItems, List<Variant> variants) Traverses through theproduct
and replaces each item reference with the fully-populated representation of the reference as found infoundItems
. Also goes through the existing variants for theproduct
and hydrates theProductOptions
with all possible option values.If a reference was not found, an error will be logged.
- Parameters:
product
- the product whose references should be hydratedfoundItems
- the results of querying for references in the data storevariants
- all variants for under product- Returns:
- the given
product
after hydrating its references
-
setProductPrimaryAssetIfFound
-
setProductPrimaryCategoryIfFound
protected void setProductPrimaryCategoryIfFound(Product product, ResolvedProductReferences foundItems) -
setProductDataDrivenEnumFieldsIfFound
protected void setProductDataDrivenEnumFieldsIfFound(Product product, ResolvedProductReferences foundItems) -
applyHydration
protected void applyHydration(@Nullable DataDrivenEnum dataDrivenEnum, String hydrationTarget, ResolvedProductReferences foundItems) -
applyHydration
protected void applyHydration(IncludedProduct includedProduct, ResolvedProductReferences foundItems) -
applyHydration
@Deprecated protected ProductOption applyHydration(ProductOption option, ResolvedProductReferences foundItems) Deprecated. -
applyHydration
protected ProductOption applyHydration(ProductOption option, ResolvedProductReferences foundItems, List<Variant> variants) Traverses through theoption
and replaces each item reference with the fully-populated representation of the reference as found infoundItems
.If a reference was not found, an error will be logged.
- Parameters:
option
- the product option whose references should be hydratedfoundItems
- the results of querying for references in the data store- Returns:
- the given
option
after hydrating its references
-
applyHydration
-
applyHydration
protected void applyHydration(SpecificItemChoice specificChoice, ResolvedProductReferences foundItems) -
hydrate
public org.springframework.data.domain.Page<Product> hydrate(@NonNull @NonNull org.springframework.data.domain.Page<Product> unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationService
Gets the IDs of items that are referenced by each product, finds the referenced items in the data store, and then replaces each item reference on the product with the fully-populated representation of the item.A page of those hydrated products is then returned.
The class-level javadoc above describes the references which will be hydrated by default.
- Specified by:
hydrate
in interfaceProductHydrationService
- Parameters:
unhydrated
- the page of unhydrated products whose references should be hydratedcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a page of the hydrated products
-
hydratePrimaryAssets
public org.springframework.data.domain.Page<Product> hydratePrimaryAssets(org.springframework.data.domain.Page<Product> unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationService
Specifically finds and hydrates theProduct.primaryAsset
of each product in the given page.- Specified by:
hydratePrimaryAssets
in interfaceProductHydrationService
- Parameters:
unhydrated
- the page of unhydrated products whose primary assets should be hydratedcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a page of the hydrated products
-
hydrate
public ProductOption hydrate(ProductOption unhydrated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationService
Gets the IDs of items that are referenced by theunhydrated
option, finds the referenced items in the data store, and then replaces each item reference on the option with the fully-populated representation of the item.The class-level javadoc above describes the references which will be hydrated by default.
- Specified by:
hydrate
in interfaceProductHydrationService
- Parameters:
unhydrated
- the unhydrated option whose references should be hydratedcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the option after applying the hydration
-
hydrateDefaultVariant
protected void hydrateDefaultVariant(ResolvedProductReferences foundItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getProductIds
-
getSkus
-
buildSkuAndProductIdKey
-
getProductService
-
getProductAssetService
-
getVariantService
-
getCategoryService
-
getCategoryProductService
-
getDataDrivenEnumService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getOptionTemplateService
-
setOptionTemplateService
@Autowired public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService)
-
applyHydration(ProductOption, ResolvedProductReferences, List)