Class DefaultProductHydrationService
- All Implemented Interfaces:
ProductHydrationService
- Author:
- Samarth Dhruva (samarthd)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultProductHydrationService
(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
(ProductCharacteristic productCharacteristic, 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) protected Product
applyHydration
(Product product, ResolvedProductReferences foundItems, List<Variant> variants, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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
(Characteristic characteristic, 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 String
getAttributeChoiceTypeFromCharacteristic
(@NonNull Characteristic characteristic) Determines theAttributeChoice type
from the configurableCharacteristic
.protected BusinessTypeService<BusinessType>
protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
protected CharacteristicService<Characteristic>
protected DataDrivenEnumService<DataDrivenEnum>
protected Optional<ProductOption>
getOptionMatchingCharacteristic
(@NonNull Product product, @NonNull Characteristic characteristic) protected OptionTemplateService<OptionTemplate>
protected ProductAssetService<ProductAsset>
getProductIds
(List<Map.Entry<String, String>> partition) protected String
getProductOptionTypeFromCharacteristic
(@NonNull Characteristic characteristic) DeterminesProductOption type
to represent the configurableCharacteristic
.protected ProductService<Product>
protected SkuGenerationService<Variant>
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation>
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.hydrateCharacteristics
(List<T> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Specifically finds and hydrates theProduct.characteristics
of each product in the given list, including any default values.protected void
hydrateConfigurableProductCharacteristics
(Product product, Characteristic characteristic) Generates aProductOption
for any newly discoveredCharacteristic
that isconfigurable
or adds any missingAttributeChoiceValues
if theProduct
already has a matchingProductOption
from theCharacteristicValues
.protected void
hydrateDefaultVariant
(ResolvedProductReferences foundItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
hydrateMissingProductCharacteristics
(Product product, ResolvedProductReferences foundItems, boolean initializeDefaultValues, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles hydratingProductCharacteristics
onto aProduct
.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.protected void
setAllowedValueFromCharacteristicValue
(@NonNull AttributeChoiceValue allowedValue, @NonNull CharacteristicValue characteristicValue, @NonNull Characteristic characteristic) Extension point for converting complexCharacteristic values
to strings, whichAttributeChoice values
require.void
setBusinessTypeService
(BusinessTypeService<BusinessType> businessTypeService) void
setCharacteristicService
(CharacteristicService<Characteristic> characteristicService) 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) void
setSkuGenerationService
(SkuGenerationService<Variant> skuGenerationService) void
setTranslationEntityService
(com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService)
-
Field Details
-
CHARACTERISTIC_VALUE_TRANSLATION_ENTITY_FIELD_PATTERN
-
-
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
-
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.getOptionTemplatesById()
have been resolved.- Parameters:
references
- the product references to updateresolved
- the object containing the list of resolved option templates
-
applyHydration
-
applyHydration
protected Product applyHydration(Product product, ResolvedProductReferences foundItems, List<Variant> variants, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.
For
ProductCharacteristic
hydration, this will set the associatedCharacteristic
on any product characteristic already present on the product. It will also add any missing product characteristics based on the associatedBusinessType
.Default values can be synced via Bulk Operations allowing those changes to go through the typical sandboxing change and approval workflows.
- 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
-
hydrateMissingProductCharacteristics
protected void hydrateMissingProductCharacteristics(Product product, ResolvedProductReferences foundItems, boolean initializeDefaultValues, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles hydratingProductCharacteristics
onto aProduct
. This will look up theCharacteristics
linked to theproduct's
BusinessType
and populate those that are missing.This is also responsible for hydrating any configurable product characteristics.
If the
initializeDefaultValues
is set, then it will attempt to createProductCharacteristicValue
s from the associatedCharacteristicValue
only if characteristic contains default values and there does not already exist a product characteristic value.- Parameters:
product
- Product to hydrateinitializeDefaultValues
- whether or not to initialize default Characteristic ValuesfoundItems
- Related entities referenced by theproduct
to be hydrated onto it.- Since:
- Catalog Service 2.2.0, Release Train 2.2.0
-
getOptionMatchingCharacteristic
protected Optional<ProductOption> getOptionMatchingCharacteristic(@NonNull @NonNull Product product, @NonNull @NonNull Characteristic characteristic) -
hydrateConfigurableProductCharacteristics
protected void hydrateConfigurableProductCharacteristics(Product product, Characteristic characteristic) Generates aProductOption
for any newly discoveredCharacteristic
that isconfigurable
or adds any missingAttributeChoiceValues
if theProduct
already has a matchingProductOption
from theCharacteristicValues
.- Parameters:
product
- The parentProduct
.characteristic
- The discoveredCharacteristic
from which to generate aProductOption
.- Since:
- Catalog Service 2.2.0, Release Train 2.2.0
-
getProductOptionTypeFromCharacteristic
protected String getProductOptionTypeFromCharacteristic(@NonNull @NonNull Characteristic characteristic) DeterminesProductOption type
to represent the configurableCharacteristic
.- Parameters:
characteristic
- The source configurableCharacteristic
to generate aProductOption
from.- Returns:
- The option type to use.
- Since:
- Catalog Service 2.2.0, Release Train 2.2.0
- See Also:
-
getAttributeChoiceTypeFromCharacteristic
protected String getAttributeChoiceTypeFromCharacteristic(@NonNull @NonNull Characteristic characteristic) Determines theAttributeChoice type
from the configurableCharacteristic
.- Parameters:
characteristic
- The source configurableCharacteristic
to generate aProductOption
from.- Returns:
- The choice type to use.
- Since:
- Catalog Service 2.2.0, Release Train 2.2.0
- See Also:
-
setAllowedValueFromCharacteristicValue
protected void setAllowedValueFromCharacteristicValue(@NonNull @NonNull AttributeChoiceValue allowedValue, @NonNull @NonNull CharacteristicValue characteristicValue, @NonNull @NonNull Characteristic characteristic) Extension point for converting complexCharacteristic values
to strings, whichAttributeChoice values
require. This is only applicable forconfigurable Characteristics
oftype
VARIANT_OPTION
.- Parameters:
allowedValue
- TheAttributeChoiceValue
created to represent thecharacteristicValue
for a configurableCharacteristic
.characteristicValue
- The sourceCharacteristicValue
to be converted to aProductOption's
allowedValue
.characteristic
- The parentCharacteristic
of thecharacteristicValue
.- Since:
- Catalog Service 2.2.0, Release Train 2.2.0
- See Also:
-
setProductPrimaryAssetIfFound
-
setProductPrimaryCategoryIfFound
protected void setProductPrimaryCategoryIfFound(Product product, ResolvedProductReferences foundItems) -
setProductDataDrivenEnumFieldsIfFound
protected void setProductDataDrivenEnumFieldsIfFound(Product product, ResolvedProductReferences foundItems) -
applyHydration
protected void applyHydration(ProductCharacteristic productCharacteristic, 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
-
hydrateCharacteristics
public <T extends Product> List<T> hydrateCharacteristics(List<T> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationService
Specifically finds and hydrates theProduct.characteristics
of each product in the given list, including any default values.- Specified by:
hydrateCharacteristics
in interfaceProductHydrationService
- Parameters:
unhydrated
- the list of unhydrated products whose characteristics should be hydratedcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a list of the hydrated products
-
hydrateDefaultVariant
protected void hydrateDefaultVariant(ResolvedProductReferences foundItems, @Nullable 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) -
getBusinessTypeService
-
setBusinessTypeService
@Autowired public void setBusinessTypeService(BusinessTypeService<BusinessType> businessTypeService) -
getCharacteristicService
-
setCharacteristicService
@Autowired public void setCharacteristicService(CharacteristicService<Characteristic> characteristicService) -
getSkuGenerationService
-
setSkuGenerationService
-
setTranslationEntityService
@Autowired public void setTranslationEntityService(com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService) -
getTranslationEntityService
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService()
-
applyHydration(ProductOption, ResolvedProductReferences, List)