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 voidapplyHydration(DataDrivenEnum dataDrivenEnum, String hydrationTarget, ResolvedProductReferences foundItems) protected voidapplyHydration(ProductCharacteristic productCharacteristic, ResolvedProductReferences foundItems) protected voidapplyHydration(IncludedProduct includedProduct, ResolvedProductReferences foundItems) protected voidapplyHydration(ItemChoice itemChoice, ResolvedProductReferences foundItems) protected ProductOptionapplyHydration(ProductOption option, ResolvedProductReferences foundItems) Deprecated.protected ProductOptionapplyHydration(ProductOption option, ResolvedProductReferences foundItems, List<Variant> variants) Traverses through theoptionand replaces each item reference with the fully-populated representation of the reference as found infoundItems.protected voidapplyHydration(SpecificItemChoice specificChoice, ResolvedProductReferences foundItems) protected ProductapplyHydration(Product product, ResolvedProductReferences foundItems) protected ProductapplyHydration(Product product, ResolvedProductReferences foundItems, List<Variant> variants, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Traverses through theproductand replaces each item reference with the fully-populated representation of the reference as found infoundItems.protected StringbuildSkuAndProductIdKey(String productId, String sku) protected voiddetermineReferences(DataDrivenEnum dataDrivenEnum, ProductReferences references) protected voiddetermineReferences(Characteristic characteristic, ProductReferences references) protected voiddetermineReferences(IncludedProduct includedProduct, ProductReferences references) protected voiddetermineReferences(ItemChoice itemChoice, ProductReferences references) protected voiddetermineReferences(ProductOption productOption, ProductReferences references) protected voiddetermineReferences(SpecificItemChoice specificChoice, ProductReferences references) protected voiddetermineReferences(Product product, ProductReferences references) Traverses through theproductand populates thereferenceswith each referenced ID.protected voidfindOptionTemplateReferences(ProductReferences references, ResolvedProductReferences resolved) Collects the ids of all products and variants referenced by anOptionTemplate.protected ResolvedProductReferencesfindReferences(ProductReferences references, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for all of the references inreferencesand returns the results.protected StringgetAttributeChoiceTypeFromCharacteristic(@NonNull Characteristic characteristic) Determines theAttributeChoice typefrom 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 StringgetProductOptionTypeFromCharacteristic(@NonNull Characteristic characteristic) DeterminesProductOption typeto 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.TypeFactoryprotected VariantService<Variant>hydrate(@NonNull Product unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the IDs of items that are referenced by theunhydratedproduct, 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 theunhydratedoption, 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.characteristicsof each product in the given list, including any default values.protected voidhydrateConfigurableProductCharacteristics(Product product, Characteristic characteristic) Generates aProductOptionfor any newly discoveredCharacteristicthat isconfigurableor adds any missingAttributeChoiceValuesif theProductalready has a matchingProductOptionfrom theCharacteristicValues.protected voidhydrateDefaultVariant(ResolvedProductReferences foundItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidhydrateMissingProductCharacteristics(Product product, ResolvedProductReferences foundItems, boolean initializeDefaultValues, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles hydratingProductCharacteristicsonto 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.primaryAssetof each product in the given page.protected voidsetAllowedValueFromCharacteristicValue(@NonNull AttributeChoiceValue allowedValue, @NonNull CharacteristicValue characteristicValue, @NonNull Characteristic characteristic) Extension point for converting complexCharacteristic valuesto strings, whichAttributeChoice valuesrequire.voidsetBusinessTypeService(BusinessTypeService<BusinessType> businessTypeService) voidsetCharacteristicService(CharacteristicService<Characteristic> characteristicService) voidsetOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) protected voidsetProductDataDrivenEnumFieldsIfFound(Product product, ResolvedProductReferences foundItems) protected voidsetProductPrimaryAssetIfFound(Product product, ResolvedProductReferences foundItems) protected voidsetProductPrimaryCategoryIfFound(Product product, ResolvedProductReferences foundItems) voidsetSkuGenerationService(SkuGenerationService<Variant> skuGenerationService) voidsetTranslationEntityService(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:ProductHydrationServiceGets the IDs of items that are referenced by theunhydratedproduct, 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:
hydratein interfaceProductHydrationService- Parameters:
unhydrated- the unhydrated product whose references should be hydrated- Returns:
- the product after applying the hydration
-
determineReferences
Traverses through theproductand populates thereferenceswith each referenced ID.- Parameters:
product- the product whose references should be examinedreferences- each item that theproductmakes 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 inreferencesand 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 theproductand replaces each item reference with the fully-populated representation of the reference as found infoundItems. Also goes through the existing variants for theproductand hydrates theProductOptionswith all possible option values.If a reference was not found, an error will be logged.
For
ProductCharacteristichydration, this will set the associatedCharacteristicon 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
productafter hydrating its references
-
hydrateMissingProductCharacteristics
protected void hydrateMissingProductCharacteristics(Product product, ResolvedProductReferences foundItems, boolean initializeDefaultValues, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles hydratingProductCharacteristicsonto aProduct. This will look up theCharacteristicslinked to theproduct'sBusinessTypeand populate those that are missing.This is also responsible for hydrating any configurable product characteristics.
If the
initializeDefaultValuesis set, then it will attempt to createProductCharacteristicValues from the associatedCharacteristicValueonly 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 theproductto 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 aProductOptionfor any newly discoveredCharacteristicthat isconfigurableor adds any missingAttributeChoiceValuesif theProductalready has a matchingProductOptionfrom theCharacteristicValues.- Parameters:
product- The parentProduct.characteristic- The discoveredCharacteristicfrom which to generate aProductOption.- Since:
- Catalog Service 2.2.0, Release Train 2.2.0
-
getProductOptionTypeFromCharacteristic
protected String getProductOptionTypeFromCharacteristic(@NonNull @NonNull Characteristic characteristic) DeterminesProductOption typeto represent the configurableCharacteristic.- Parameters:
characteristic- The source configurableCharacteristicto generate aProductOptionfrom.- 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 typefrom the configurableCharacteristic.- Parameters:
characteristic- The source configurableCharacteristicto generate aProductOptionfrom.- 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 valuesto strings, whichAttributeChoice valuesrequire. This is only applicable forconfigurable CharacteristicsoftypeVARIANT_OPTION.- Parameters:
allowedValue- TheAttributeChoiceValuecreated to represent thecharacteristicValuefor a configurableCharacteristic.characteristicValue- The sourceCharacteristicValueto be converted to aProductOption'sallowedValue.characteristic- The parentCharacteristicof 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 theoptionand 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
optionafter 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:ProductHydrationServiceGets 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:
hydratein 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:ProductHydrationServiceSpecifically finds and hydrates theProduct.primaryAssetof each product in the given page.- Specified by:
hydratePrimaryAssetsin 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:ProductHydrationServiceGets the IDs of items that are referenced by theunhydratedoption, 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:
hydratein 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:ProductHydrationServiceSpecifically finds and hydrates theProduct.characteristicsof each product in the given list, including any default values.- Specified by:
hydrateCharacteristicsin 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)