Class DefaultProductDetailsService
java.lang.Object
com.broadleafcommerce.catalog.service.product.commerce.DefaultProductDetailsService
- All Implemented Interfaces:
ProductDetailsService
- Author:
- Nathan Moore (nathandmoore)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultProductDetailsService(List<ProductDetailsContributor> detailsContributors, List<ProductDetailsContextContributor> contextContributors, List<ProductDetailsContextConsolidator> contextConsolidators, ProductService<Product> productService, ProductAssetService<ProductAsset> productAssetService, ProductTagService<ProductTag> productTagService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends ProductDetailsContext>
Collection<T>buildContexts(@NonNull Collection<T> detailsContexts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) BuildsProductDetailsContextsin response toProductDetailsRequests.protected <T extends ProductDetailsContext>
ProductDetailsListbuildDetails(@NonNull Collection<T> detailsContexts, @NonNull ProductDetailsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds out theProductDetailsin response to aProductDetailsRequest.getAssetsForProducts(@NonNull Collection<String> productIds, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductAssetsthat match theproductIdsprovided.protected List<ProductDetailsContextConsolidator>protected List<ProductDetailsContextContributor>protected List<ProductDetailsContributor>getDetailsForProducts(@NonNull Collection<? extends Product> products, @NonNull ProductDetailsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductDetailsListfor the providedproducts.protected ProductAssetService<ProductAsset>getProductDetailsForRequest(@NonNull ProductDetailsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets aProductDetailsfor theProductDetailsRequest.protected ProductService<Product>getProductsForUris(Set<String> productUris, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected ProductTagService<ProductTag>protected ProductDetailsPropertiesgetTagDetailsForProducts(Collection<String> productIds, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductTagsfor the givenproductIds.protected com.broadleafcommerce.common.extension.TypeFactoryprotected StringgetVariantHydrationBehavior(@NonNull ProductDetailsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductDetailsRequest.getVariantHydrationBehavior()or defaults toProductDetailsProperties.getVariantHydrationBehavior()if blank.protected VariantService<Variant>protected BinaryOperator<Product>mergeProductsWithSameUris(List<Product> products) resolveProducts(@NonNull ProductDetailsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves the base product for the given requests.resolveVariants(@NonNull ProductDetailsRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) voidsetProperties(ProductDetailsProperties properties) voidsetVariantService(VariantService<Variant> variantService)
-
Constructor Details
-
DefaultProductDetailsService
public DefaultProductDetailsService(List<ProductDetailsContributor> detailsContributors, List<ProductDetailsContextContributor> contextContributors, List<ProductDetailsContextConsolidator> contextConsolidators, ProductService<Product> productService, ProductAssetService<ProductAsset> productAssetService, ProductTagService<ProductTag> productTagService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
getProductDetailsForRequest
public Optional<ProductDetailsList> getProductDetailsForRequest(@NonNull @NonNull ProductDetailsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductDetailsServiceGets aProductDetailsfor theProductDetailsRequest.- Specified by:
getProductDetailsForRequestin interfaceProductDetailsService- Parameters:
request- theProductDetailsRequestwith additional request context for identifying the products for which to retrieve details and defining the how much detail to go into.contextInfo- context information surrounding sandboxing/multitenant state- Returns:
ProductDetailsListfor theProductDetailsRequests.
-
getAssetsForProducts
public Map<String,List<ProductAsset>> getAssetsForProducts(@NonNull @NonNull Collection<String> productIds, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductDetailsServiceGets theProductAssetsthat match theproductIdsprovided. The results are mapped by the product ID.- Specified by:
getAssetsForProductsin interfaceProductDetailsService- Parameters:
productIds- IDs of theProductswhose assets to fetch.filters- additional filters to apply in the query.contextInfo- context information surrounding sandboxing/multitenant state.- Returns:
- the
ProductAssetsthat match theproductIdsprovided.
-
getDetailsForProducts
public ProductDetailsList getDetailsForProducts(@NonNull @NonNull Collection<? extends Product> products, @NonNull @NonNull ProductDetailsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductDetailsServiceGets theProductDetailsListfor the providedproducts.The product IDs and URIs not found should be populated onto the original
ProductDetailsRequestrather than be passed in separately to clean up the method signature and allow even more information to be passed in besides in the future or by extensions.- Specified by:
getDetailsForProductsin interfaceProductDetailsService- Parameters:
products-Productsfor which to get aProductDetailsList.request- The originalrequest.contextInfo- context information surrounding sandboxing/multitenant state- Returns:
ProductDetailsListfor theproducts.
-
getTagDetailsForProducts
public Map<String,List<ProductTagDetail>> getTagDetailsForProducts(Collection<String> productIds, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ProductDetailsServiceGets theProductTagsfor the givenproductIds. The results are mapped by the owning product ID.- Specified by:
getTagDetailsForProductsin interfaceProductDetailsService- Parameters:
productIds- IDs of theProductswhose assets to fetch.filters- additional filters to apply in the query.contextInfo- context information surrounding sandboxing/multitenant state.- Returns:
- The
ProductTagsfor the givenproductIds.
-
getVariantHydrationBehavior
protected String getVariantHydrationBehavior(@NonNull @NonNull ProductDetailsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theProductDetailsRequest.getVariantHydrationBehavior()or defaults toProductDetailsProperties.getVariantHydrationBehavior()if blank.- Parameters:
request- The incoming requestcontextInfo- Additional tenant and sandbox info- Returns:
- the variant hydration behavior
- Since:
- Catalog Service 2.3.0-GA, Release Train 2.3.0-GA
-
resolveVariants
protected Set<Variant> resolveVariants(@NonNull @NonNull ProductDetailsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
resolveProducts
protected Set<Product> resolveProducts(@NonNull @NonNull ProductDetailsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resolves the base product for the given requests.- Parameters:
request- TheProductDetailsRequeststo use to resolve the base productscontextInfo- context information surrounding sandboxing/multitenant state- Returns:
- the resolved base products
-
getProductsForUris
-
mergeProductsWithSameUris
If aSELECTORproduct and another product share the same URL, theSELECTORproduct replaces the other one. If more than oneSELECTORproduct has the same URI it returns the first one.- Parameters:
products- the list of products to merge- Returns:
- the merged list of products
-
mergeProductsWithSameUris
-
buildContexts
protected <T extends ProductDetailsContext> Collection<T> buildContexts(@NonNull @NonNull Collection<T> detailsContexts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) BuildsProductDetailsContextsin response toProductDetailsRequests. This facilitates gathering all of the related catalog entities to the requested products all at once to allow fewer DB calls throughout the process of buildingProductDetails. It first gathers all of the context info using all of theProductDetailsContextContributors. Then, it consolidates the context info onto the related entities such as addingProductAssetsto the relatedProductsusing theProductDetailsContextConsolidators.- Parameters:
detailsContexts- theProductDetailsContextwith the request context and resolved products populatedcontextInfo- context information surrounding sandboxing/multitenant state- Returns:
- a
ProductDetailsContextin response to aProductDetailsRequest.
-
buildDetails
protected <T extends ProductDetailsContext> ProductDetailsList buildDetails(@NonNull @NonNull Collection<T> detailsContexts, @NonNull @NonNull ProductDetailsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds out theProductDetailsin response to aProductDetailsRequest. It relies on all of theProductDetailsContributors.- Parameters:
detailsContexts- TheProductDetailsContextscreated in response to theProductDetailsRequests. This contains context information and all the catalog entities related to the requested product pre-fetched and consolidated.request- The originalrequest. The IDs and URIs for entities not found should be hydrated onto this.contextInfo- context information surrounding sandboxing/multitenant state- Returns:
- the
ProductDetailsin response to aProductDetailsRequest.
-
getDetailsContributors
-
getContextContributors
-
getContextConsolidators
-
getProductService
-
getProductAssetService
-
getProductTagService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getVariantService
- Since:
- Catalog Service 2.3.0-GA, Release Train 2.3.0-GA
-
setVariantService
- Since:
- Catalog Service 2.3.0-GA, Release Train 2.3.0-GA
-
getProperties
- Since:
- Catalog Service 2.3.0-GA, Release Train 2.3.0-GA
-
setProperties
- Since:
- Catalog Service 2.3.0-GA, Release Train 2.3.0-GA
-