Class DefaultProductHydrationService

java.lang.Object
com.broadleafcommerce.catalog.service.product.hydration.DefaultProductHydrationService
All Implemented Interfaces:
ProductHydrationService

public class DefaultProductHydrationService extends Object implements ProductHydrationService
Author:
Samarth Dhruva (samarthd)
  • Constructor Details

  • 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 the unhydrated 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 interface ProductHydrationService
      Parameters:
      unhydrated - the unhydrated product whose references should be hydrated
      Returns:
      the product after applying the hydration
    • determineReferences

      protected void determineReferences(Product product, ProductReferences references)
      Traverses through the product and populates the references with each referenced ID.
      Parameters:
      product - the product whose references should be examined
      references - each item that the product makes a reference to will be added to this object
    • determineReferences

      protected void determineReferences(@Nullable DataDrivenEnum dataDrivenEnum, ProductReferences references)
    • determineReferences

      protected void determineReferences(IncludedProduct includedProduct, ProductReferences references)
    • determineReferences

      protected void determineReferences(ProductOption productOption, ProductReferences references)
    • determineReferences

      protected void determineReferences(ItemChoice itemChoice, ProductReferences references)
    • determineReferences

      protected void determineReferences(SpecificItemChoice specificChoice, ProductReferences references)
    • findReferences

      protected ResolvedProductReferences findReferences(ProductReferences references, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Queries for all of the references in references and returns the results.
      Parameters:
      references - all of the references that need to be found in the data store
      contextInfo - 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 an OptionTemplate. These ids are needed to resolve the products and variants that later will be hydrated onto the product option by applyHydration(SpecificItemChoice, ResolvedProductReferences). This method may resolve the appropriate ids once the ResolvedProductReferences.optionTemplatesById have been resolved.
      Parameters:
      references - the product references to update
      resolved - the object containing the list of resolved option templates
    • applyHydration

      @Deprecated protected Product applyHydration(Product product, ResolvedProductReferences foundItems)
    • applyHydration

      protected Product applyHydration(Product product, ResolvedProductReferences foundItems, List<Variant> variants)
      Traverses through the product and replaces each item reference with the fully-populated representation of the reference as found in foundItems. Also goes through the existing variants for the product and hydrates the ProductOptions with all possible option values.

      If a reference was not found, an error will be logged.

      Parameters:
      product - the product whose references should be hydrated
      foundItems - the results of querying for references in the data store
      variants - all variants for under product
      Returns:
      the given product after hydrating its references
    • setProductPrimaryAssetIfFound

      protected void setProductPrimaryAssetIfFound(Product product, ResolvedProductReferences foundItems)
    • 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)
    • applyHydration

      protected ProductOption applyHydration(ProductOption option, ResolvedProductReferences foundItems, List<Variant> variants)
      Traverses through the option and replaces each item reference with the fully-populated representation of the reference as found in foundItems.

      If a reference was not found, an error will be logged.

      Parameters:
      option - the product option whose references should be hydrated
      foundItems - the results of querying for references in the data store
      Returns:
      the given option after hydrating its references
    • applyHydration

      protected void applyHydration(ItemChoice itemChoice, ResolvedProductReferences foundItems)
    • 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 interface ProductHydrationService
      Parameters:
      unhydrated - the page of unhydrated products whose references should be hydrated
      contextInfo - 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 the Product.primaryAsset of each product in the given page.
      Specified by:
      hydratePrimaryAssets in interface ProductHydrationService
      Parameters:
      unhydrated - the page of unhydrated products whose primary assets should be hydrated
      contextInfo - 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 the unhydrated 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 interface ProductHydrationService
      Parameters:
      unhydrated - the unhydrated option whose references should be hydrated
      contextInfo - 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

      protected Set<String> getProductIds(List<Map.Entry<String,String>> partition)
    • getSkus

      protected Set<String> getSkus(List<Map.Entry<String,String>> partition)
    • buildSkuAndProductIdKey

      protected String buildSkuAndProductIdKey(String productId, String sku)
    • getProductService

      protected ProductService<Product> getProductService()
    • getProductAssetService

      protected ProductAssetService<ProductAsset> getProductAssetService()
    • getVariantService

      protected VariantService<Variant> getVariantService()
    • getCategoryService

      protected CategoryService<Category> getCategoryService()
    • getCategoryProductService

      protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getDataDrivenEnumService

      protected DataDrivenEnumService<DataDrivenEnum> getDataDrivenEnumService()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getOptionTemplateService

      protected OptionTemplateService<OptionTemplate> getOptionTemplateService()
    • setOptionTemplateService

      @Autowired public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService)