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 voidaddNewProductCharacteristic(Product product, Characteristic characteristic, boolean initializeDefaultValues) applyCharacteristicHydration(List<T> unhydrated, ResolvedProductReferences resolvedProductReferences, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This is essentially the same asProductHydrationService.hydrateCharacteristics(List, ContextInfo), but the caller is able to provide their own pre-fetched data to use for the complex hydration rather than having this service do the fetching.protected 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, 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 voidcomputeCharacteristicsOverriddenHint(Product productWithChars, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates the value ofProduct.getCharacteristicsOverriddenHint().protected booleancontainsAnyProductionLevelFieldChanges(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState) protected CharacteristicdeepCloneCharacteristic(Characteristic toClone) 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 voidfindBusinessTypes(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theBusinessTypesreferenced by the product.protected voidfindCategories(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theCategoriesreferenced by the product.protected voidfindCharacteristics(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theCharacteristicsreferenced by the product'sProductCharacteristics.protected voidfindDataDrivenEnums(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theDataDrivenEnumsreferenced by the product.protected voidfindOptionTemplateReferences(ProductReferences references, ResolvedProductReferences resolved) Collects the ids of all products and variants referenced by anOptionTemplate.protected voidfindOptionTemplates(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theOptionTemplatesreferenced by the product.protected voidfindPrimaryAssets(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the primaryProductAssetsfor the products being hydrated.protected Map<String,CategoryProduct> findPrimaryCategoryProducts(ProductReferences references, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the primaryCategoryProductrelationships for the products.protected voidfindProductCharacteristics(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theProductCharacteristicsfor the products.protected voidfindProducts(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theProductsreferenced by the product.protected ResolvedProductReferencesfindReferences(ProductReferences references, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Queries for all of the references inreferencesand returns the results.protected voidfindVariants(ProductReferences references, ResolvedProductReferences resolved, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theVariantsreferenced by the product.protected Set<BusinessTypeCharacteristic>getAllCharacteristicsForBusinessType(BusinessType businessType) Gathers all uniqueBusinessTypeCharacteristicfrom a givenBusinessTypeand all of its ancestors.protected StringgetAttributeChoiceTypeFromCharacteristic(@NonNull Characteristic characteristic) Determines theAttributeChoice typefrom the configurableCharacteristic.protected StringgetAttributeChoiceValueType(@NonNull String valueType) Determines theAttributeChoice.getType()from theCharacteristicValue value type.protected BusinessTypeService<BusinessType>protected CategoryProductService<CategoryProduct>protected CategoryService<Category>protected CharacteristicHydrationServiceprotected CharacteristicService<Characteristic>protected CharacteristicsTranslationServiceprotected List<CharacteristicValue>getCharacteristicValues(Product product, Characteristic characteristic) Retrieves the list ofCharacteristicValuesto use for generating theAttributeChoiceValuesof aProductOptionfor aCharacteristic.protected DataDrivenEnumService<DataDrivenEnum>protected ObjectDeepCopyUtilityprotected Optional<ProductOption>getOptionMatchingCharacteristic(@NonNull Product product, @NonNull Characteristic characteristic) protected OptionTemplateService<OptionTemplate>protected StringgetOverrideOrBaseCatalogId(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState) protected ProductAssetService<ProductAsset>protected ProductCharacteristicValuegetProductCharacteristicValue(CharacteristicValue characteristicValue) 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>protected ProductCharacteristichandleMultipleProdCharsFoundForSameFieldName(ProductCharacteristic pc1, ProductCharacteristic pc2, Product product, ResolvedProductReferences foundItems) Called insetProductCharacteristicsIfFound(Product, ResolvedProductReferences)to resolve a scenario where the query for product characteristics of a product actually produced multiple results for the sameProductCharacteristic.getFieldName().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.protected voidhydrateAllowedValues(AttributeChoice attributeChoice, Map<String, Set<String>> allOptionValues) hydrateCharacteristics(List<T> unhydrated, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Specifically finds and hydrates theProduct.getCharacteristics()of each product in the given list, including any default values.protected voidhydrateDefaultVariant(ResolvedProductReferences foundItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidhydrateExistingProductCharacteristic(Product product, Characteristic characteristic, Set<BusinessTypeCharacteristic> allCharacteristics, 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.protected voidhydrateMissingProductCharacteristics(Product product, Set<BusinessTypeCharacteristic> allCharacteristics, ResolvedProductReferences foundItems, boolean initializeDefaultValues, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidhydrateOrAddProductCharacteristic(Product product, BusinessTypeCharacteristic busTypeChar, Set<BusinessTypeCharacteristic> allCharacteristics, ResolvedProductReferences foundItems, boolean initializeDefaultValues, 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.primaryAssetof each product in the given page.protected voidinitializeDefaultCharacteristicValues(ProductCharacteristic productCharacteristic, Characteristic characteristic) protected booleanisAnyProdCharsOverriddenInCurrentCatalogContext(Product productWithChars, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reports whether any of theProduct.getCharacteristics()have been overridden directly in the currentContextRequest.protected booleanisOverrideCatalogAtLeafLevelInCurrentAppContext(@NonNull com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextRequest appContextRequest) protected booleanisOverrideDefinedInCurrentCatalogContext(ProductCharacteristic pcToEvaluate, Product parentProduct, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidresolvePrimaryCategories(ResolvedProductReferences resolved, Map<String, CategoryProduct> primaryCategoryProductsByProductId) Resolves the actualCategoryentities for the products' primary categories.protected voidsetAllowedValueFromCharacteristicValue(@NonNull AttributeChoiceValue allowedValue, @NonNull CharacteristicValue characteristicValue, @NonNull Characteristic characteristic) Extension point for converting complexCharacteristic valuesto strings, whichAttributeChoice valuesrequire.voidsetBusinessTypeService(BusinessTypeService<BusinessType> businessTypeService) voidsetCharacteristicHydrationService(CharacteristicHydrationService characteristicHydrationService) voidsetCharacteristicService(CharacteristicService<Characteristic> characteristicService) voidsetCharacteristicsTranslationService(CharacteristicsTranslationService characteristicsTranslationService) voidsetObjectDeepCopyUtility(ObjectDeepCopyUtility objectDeepCopyUtility) voidsetOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) voidsetProductCharacteristicService(ProductCharacteristicService<ProductCharacteristic> productCharacteristicService) protected voidsetProductCharacteristicsIfFound(Product product, ResolvedProductReferences foundItems) 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) protected booleanshouldAddAllowedValuesToProductOptionFromCharacteristics(String valueChoiceType, AttributeChoice attributeChoice, Characteristic characteristic) protected voidsynchronizeCharacteristics(Product product) Synchronizes the product characteristics.protected voidsynchronizeEnumTypeCharacteristics(ProductCharacteristic pc, Characteristic characteristic) Synchronizes the enum type characteristics for a given product characteristic.protected voidsynchronizePlaceholderCharacteristics(ProductCharacteristic pc, Characteristic characteristic) Synchronizes the placeholder characteristics for a given product characteristic.protected voidsyncOptionForConfigurableProductCharacteristic(Product product, Characteristic characteristic)
-
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
-
findOptionTemplates
protected void findOptionTemplates(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theOptionTemplatesreferenced by the product. This looks up templates by ID as specified in thereferencesand populates theresolvedobject with the results.- Parameters:
references- the product references containing the option template IDs to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findProducts
protected void findProducts(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theProductsreferenced by the product. This includes products referenced as included products, default products in item choices, or specific item choices. The results are stored in theresolvedobject.- Parameters:
references- the product references containing the product IDs to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findBusinessTypes
protected void findBusinessTypes(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theBusinessTypesreferenced by the product. This fetches the business types by their type key, including their ancestors, to support characteristic inheritance.- Parameters:
references- the product references containing the business type keys to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findVariants
protected void findVariants(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theVariantsreferenced by the product. This includes variants referenced in included products or item choices.- Parameters:
references- the product references containing the variant IDs to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findPrimaryAssets
protected void findPrimaryAssets(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the primaryProductAssetsfor the products being hydrated. These assets are typically used to populate the primary asset field on the product.- Parameters:
references- the product references containing the product IDs to find primary assets forresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findPrimaryCategoryProducts
@Nullable protected Map<String,CategoryProduct> findPrimaryCategoryProducts(ProductReferences references, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the primaryCategoryProductrelationships for the products. This method also extracts theCategoryIDs from the found relationships and adds them to thereferencesso the actual categories can be fetched in a subsequent step.- Parameters:
references- the product references containing the product IDs to find primary categories forcontextInfo- context information surrounding sandboxing and multitenant state- Returns:
- a map of product ID to primary category product, or null if none found
-
findCategories
protected void findCategories(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theCategoriesreferenced by the product. This includes categories referenced in item choices as well as the primary categories identified viafindPrimaryCategoryProducts(com.broadleafcommerce.catalog.service.product.hydration.ProductReferences, com.broadleafcommerce.data.tracking.core.context.ContextInfo).- Parameters:
references- the product references containing the category IDs to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
resolvePrimaryCategories
protected void resolvePrimaryCategories(ResolvedProductReferences resolved, @Nullable Map<String, CategoryProduct> primaryCategoryProductsByProductId) Resolves the actualCategoryentities for the products' primary categories. It uses theprimaryCategoryProductsByProductIdmap to link products to their primary category ID, and then looks up the correspondingCategoryfrom theresolvedcategories.- Parameters:
resolved- the resolved product references to populateprimaryCategoryProductsByProductId- the map of product ID to primary category product
-
findDataDrivenEnums
protected void findDataDrivenEnums(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theDataDrivenEnumsreferenced by the product. These are typically referenced by custom fields or specific product properties.- Parameters:
references- the product references containing the data driven enum IDs to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findProductCharacteristics
protected void findProductCharacteristics(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theProductCharacteristicsfor the products. This method groups the found characteristics by product ID. It also identifies the underlyingCharacteristicIDs and adds them to thereferencesto be fetched. Additionally, it fetches the inheritance line for characteristics to support narrowing.- Parameters:
references- the product references containing the product IDs to find product characteristics forresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
findCharacteristics
protected void findCharacteristics(ProductReferences references, ResolvedProductReferences resolved, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theCharacteristicsreferenced by the product'sProductCharacteristics. These definitions are used to fully hydrate the product characteristics.- Parameters:
references- the product references containing the characteristic IDs to findresolved- the resolved product references to populatecontextInfo- context information surrounding sandboxing and multitenant state
-
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
-
synchronizeCharacteristics
Synchronizes the product characteristics. This method encapsulates the logic for syncing configurable, enum type, and placeholder characteristics. This is intended to be called during the hydration process to ensure the in-memory representation of the product is consistent with any changes that have been made in its parent business type (and the business type characteristics) since the product was initially created.Note: This requires the product's characteristics to be hydrated, as well as their own
ProductCharacteristic.getCharacteristic()property.- Parameters:
product- the product whose characteristics should be synchronized
-
synchronizeEnumTypeCharacteristics
protected void synchronizeEnumTypeCharacteristics(ProductCharacteristic pc, Characteristic characteristic) Synchronizes the enum type characteristics for a given product characteristic. For any characteristic that is of an enum type, this method will ensure that the value stored on the characteristic is the actual enum value, along with setting the label and valueType appropriately.- Parameters:
pc- the product characteristic to synchronizecharacteristic- the characteristic definition
-
synchronizePlaceholderCharacteristics
protected void synchronizePlaceholderCharacteristics(ProductCharacteristic pc, Characteristic characteristic) Synchronizes the placeholder characteristics for a given product characteristic. This is used when there are changes to the characteristic values on a placeholder characteristic and we need to ensure that the product characteristic values reflect those changes.- Parameters:
pc- the product characteristic to synchronizecharacteristic- the characteristic definition
-
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
-
hydrateMissingProductCharacteristics
protected void hydrateMissingProductCharacteristics(Product product, Set<BusinessTypeCharacteristic> allCharacteristics, ResolvedProductReferences foundItems, boolean initializeDefaultValues, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
hydrateOrAddProductCharacteristic
protected void hydrateOrAddProductCharacteristic(Product product, BusinessTypeCharacteristic busTypeChar, Set<BusinessTypeCharacteristic> allCharacteristics, ResolvedProductReferences foundItems, boolean initializeDefaultValues, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
deepCloneCharacteristic
-
hydrateExistingProductCharacteristic
protected void hydrateExistingProductCharacteristic(Product product, Characteristic characteristic, Set<BusinessTypeCharacteristic> allCharacteristics, ResolvedProductReferences foundItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
addNewProductCharacteristic
protected void addNewProductCharacteristic(Product product, Characteristic characteristic, boolean initializeDefaultValues) -
initializeDefaultCharacteristicValues
protected void initializeDefaultCharacteristicValues(ProductCharacteristic productCharacteristic, Characteristic characteristic) -
getProductCharacteristicValue
protected ProductCharacteristicValue getProductCharacteristicValue(CharacteristicValue characteristicValue) -
getOptionMatchingCharacteristic
protected Optional<ProductOption> getOptionMatchingCharacteristic(@NonNull @NonNull Product product, @NonNull @NonNull Characteristic characteristic) -
syncOptionForConfigurableProductCharacteristic
protected void syncOptionForConfigurableProductCharacteristic(Product product, Characteristic characteristic) Synchronizes aProductOptionto represent aconfigurableCharacteristic.If no matching option exists on the
Product, a new one is generated. For existing options, this method ensures the underlyingAttributeChoice typestays in sync with the characteristic's data type.Additionally, for choice-based types (e.g. SELECT, COLOR, SIZE), this will append any missing allowed values. For
BOOLEANtypes, allowed values are only populated during initial instantiation and are not appended subsequently. Forplaceholdercharacteristics, these allowed values are sourced directly from the product'sProductCharacteristicValues rather than the global definition.- Parameters:
product- The parentProductwhose options should be mutatedcharacteristic- The discoveredCharacteristicfrom which to sync theProductOption.- Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
shouldAddAllowedValuesToProductOptionFromCharacteristics
protected boolean shouldAddAllowedValuesToProductOptionFromCharacteristics(String valueChoiceType, AttributeChoice attributeChoice, Characteristic characteristic) -
getCharacteristicValues
protected List<CharacteristicValue> getCharacteristicValues(Product product, Characteristic characteristic) Retrieves the list ofCharacteristicValuesto use for generating theAttributeChoiceValuesof aProductOptionfor aCharacteristic. If thecharacteristic is a placeholder, then the values will be sourced from theProductCharacteristicon theproductinstead of theCharacteristicValueson thecharacteristic.- Parameters:
product- The parentProductcontaining theProductCharacteristicscharacteristic- The sourceCharacteristicfrom which to retrieve theCharacteristicValues.- Returns:
- The list of
CharacteristicValuesto use for generatingAttributeChoiceValues. - Since:
- Catalog Services 2.3.0, Release Train 2.3.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:
-
getAttributeChoiceValueType
Determines theAttributeChoice.getType()from theCharacteristicValue value type.This method is used to handle special cases when the characteristic's value's value type indicates a special type such as
COLORorSIZE.- Parameters:
valueType- The sourcevalue typeto evaluate.- Returns:
- The choice value type to use, or
nullif no special type is applicable.
-
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) -
setProductCharacteristicsIfFound
protected void setProductCharacteristicsIfFound(Product product, ResolvedProductReferences foundItems) Sets theProductCharacteristicson theproductif they were found in thefoundItems.This method filters the found characteristics against the
BusinessTypeassociated with the product. Only characteristics that are defined on the business type (or its ancestors) are retained. This ensures that stale or invalid characteristics are not hydrated onto the product.- Parameters:
product- the product to set characteristics onfoundItems- the resolved references containing the found product characteristics and business types
-
handleMultipleProdCharsFoundForSameFieldName
protected ProductCharacteristic handleMultipleProdCharsFoundForSameFieldName(ProductCharacteristic pc1, ProductCharacteristic pc2, Product product, ResolvedProductReferences foundItems) Called in
setProductCharacteristicsIfFound(Product, ResolvedProductReferences)to resolve a scenario where the query for product characteristics of a product actually produced multiple results for the sameProductCharacteristic.getFieldName().This scenario should not arise at this stage in the flow, since whatever mechanism is responsible for populating
ResolvedProductReferences.getProductCharacteristicsByProductId()should have already handled edge cases with deduplicating by field name. SeeProductCharacteristicService.readAllByProductContextIdIn(Collection, boolean, ContextInfo)for details on the edge case that can produce this scenario and how it is handled.- Parameters:
pc1- a ProductCharacteristic instance for the same product with the same field name aspc2pc2- a ProductCharacteristic instance for the same product with the same field name aspc1product- the product for which these characteristics were foundfoundItems- all found items for the current hydration attempt- Returns:
- the product characteristic instance to prefer for the current request
-
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
-
hydrateAllowedValues
protected void hydrateAllowedValues(AttributeChoice attributeChoice, Map<String, Set<String>> allOptionValues) -
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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationServiceSpecifically finds and hydrates theProduct.getCharacteristics()of each product in the given list, including any default values. By default, the hydration logic is complex,and involves populating missing product characteristics, modifying product options, and performing value narrowing on characteristics.- 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
- See Also:
-
applyCharacteristicHydration
public <T extends Product> List<T> applyCharacteristicHydration(List<T> unhydrated, ResolvedProductReferences resolvedProductReferences, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductHydrationServiceThis is essentially the same as
ProductHydrationService.hydrateCharacteristics(List, ContextInfo), but the caller is able to provide their own pre-fetched data to use for the complex hydration rather than having this service do the fetching. This can be particularly helpful in non-narrowed context environments like search reindexing, where the typical queries run by the hydration service will fail.- Specified by:
applyCharacteristicHydrationin interfaceProductHydrationService- Parameters:
unhydrated- the list of unhydrated products whose characteristics should be hydratedresolvedProductReferences- the pre-fetched data that should be used for hydration. At a minimum, this must include:ResolvedProductReferences.getProductCharacteristicsByProductId()(for all the product characteristics),ResolvedProductReferences.getBusinessTypeByTypeKey()(for all the product business types),ResolvedProductReferences.getCharacteristicsById()(the base characteristic for each product characteristic), andResolvedProductReferences.getProductCharacteristicsFromInheritanceLineByProductId()(for all the product characteristics).contextInfo- context information surrounding sandboxing and multitenant state- Returns:
- a list of the hydrated products
- See Also:
-
computeCharacteristicsOverriddenHint
protected void computeCharacteristicsOverriddenHint(Product productWithChars, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Populates the value of
Product.getCharacteristicsOverriddenHint().- Parameters:
productWithChars- the product instance with product characteristics already hydratedcontextInfo- the current context info- Since:
- Catalog Service 2.3.0, Release Train 2.3.0
- See Also:
-
isAnyProdCharsOverriddenInCurrentCatalogContext
protected boolean isAnyProdCharsOverriddenInCurrentCatalogContext(Product productWithChars, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reports whether any of theProduct.getCharacteristics()have been overridden directly in the currentContextRequest. This is particularly relevant to driveProduct.getCharacteristicsOverriddenHint().- Parameters:
productWithChars- the product with characteristics already hydratedcontextInfo- the current context against which to evaluate override state- Returns:
- whether any of the product's characteristics are directly overridden in the current catalog context
- Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
containsAnyProductionLevelFieldChanges
protected boolean containsAnyProductionLevelFieldChanges(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState) - Parameters:
contextState- the context state of an entity- Returns:
- whether the entity contains any production-level field changes that would indicate it is a production-level override record
- Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
isOverrideDefinedInCurrentCatalogContext
protected boolean isOverrideDefinedInCurrentCatalogContext(ProductCharacteristic pcToEvaluate, Product parentProduct, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Parameters:
pcToEvaluate- the product characteristic whose override state should be evaluated. This should already have been validated as being a record that contains production-level field changes.parentProduct- the parent product for which this characteristic was loadedcontextInfo- the current context against which to evaluate override state- Returns:
- whether the
pcToEvaluatehas been directly overridden in the current catalog context (as opposed to being inherited from a parent catalog) - Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
getOverrideOrBaseCatalogId
protected String getOverrideOrBaseCatalogId(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState) - Parameters:
contextState- the context state to extract catalog information from- Returns:
- the
ContextState.getOverrideCatalogId()if set, elseContextState.getCatalog()ID. This allows us to clearly identify the catalog in which the entity actually resides. SeeContextStateBuilderto understand where these fields come from - Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
isOverrideCatalogAtLeafLevelInCurrentAppContext
protected boolean isOverrideCatalogAtLeafLevelInCurrentAppContext(@NonNull @NonNull com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextRequest appContextRequest) - Parameters:
contextState- entity context state that's already validated as having a value forContextState.getOverrideCatalogId()appContextRequest- application context request- Returns:
- whether
ContextState.getOverrideCatalogId()matches one of the application's implicit catalogs - Since:
- Catalog Service 2.3.0, Release Train 2.3.0
-
getAllCharacteristicsForBusinessType
protected Set<BusinessTypeCharacteristic> getAllCharacteristicsForBusinessType(@Nullable BusinessType businessType) Gathers all uniqueBusinessTypeCharacteristicfrom a givenBusinessTypeand all of its ancestors. Note - the input to this method should have already been appropriately hydrated with its ancestor characteristics - seeResolvedProductReferences.getBusinessTypeByTypeKey()and how it is computed. As a result, this method simply grabs the values fromBusinessType.getCharacteristics()directly and converts them to aSetrepresentation.- Parameters:
businessType- the business type to process- Returns:
- a set of all characteristics for the business type hierarchy
-
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) -
getCharacteristicHydrationService
-
setCharacteristicHydrationService
@Autowired public void setCharacteristicHydrationService(CharacteristicHydrationService characteristicHydrationService) -
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() -
setProductCharacteristicService
@Autowired public void setProductCharacteristicService(ProductCharacteristicService<ProductCharacteristic> productCharacteristicService) -
getProductCharacteristicService
-
setObjectDeepCopyUtility
-
getObjectDeepCopyUtility
-
setCharacteristicsTranslationService
@Autowired public void setCharacteristicsTranslationService(CharacteristicsTranslationService characteristicsTranslationService) -
getCharacteristicsTranslationService
-
applyHydration(ProductOption, ResolvedProductReferences, List)