Class ExternalCatalogSearchProvider<T extends Product>
java.lang.Object
com.broadleafcommerce.catalogbrowse.service.provider.external.AbstractExternalProvider
com.broadleafcommerce.catalogbrowse.service.provider.external.search.ExternalCatalogSearchProvider<T>
- All Implemented Interfaces:
CatalogSearchProvider<T>
public class ExternalCatalogSearchProvider<T extends Product>
extends AbstractExternalProvider
implements CatalogSearchProvider<T>
- Author:
- Nathan Moore (nathandmoore)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionExternalCatalogSearchProvider(org.springframework.web.reactive.function.client.WebClient catalogSearchWebClient, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PricingProvider browsePricingProvider, CatalogProvider browseCatalogProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddPriceDetail(Product product, DefaultPriceableFieldType fieldType, javax.money.MonetaryAmount price, boolean replaceExisting) protected voidaddPriceDetailFromProductData(Product product, DefaultPriceableFieldType fieldType, javax.money.MonetaryAmount price) protected voidaddPriceDetailsFromProductData(Product product, ProductPricingPredicate predicate) Add price details from product's data.protected voidassignDefaultProductPriceInfos(@NonNull Collection<T> products, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Parses theProductPricingPredicatereturned from the search results to add price details used by the pricing service to compute display results including the cost, base price, sale price, and pricing key for the product.protected StringbuildCustomerContextHeader(org.springframework.util.MultiValueMap<String, String> customerParams, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) convertSuggestionsToMap(@NonNull List<T> suggestions) convertSuggestionsToProducts(@NonNull List<Map<String, Object>> suggestions) protected CustomerContextcreateCustomerContext(org.springframework.util.MultiValueMap<String, String> customerParams, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) fetchCategoryWithDetailsAndSearchResponse(@NonNull CategoryDetailsRequest request) protected PricingProviderprotected CatalogProviderprotected org.springframework.web.reactive.function.client.WebClientgetCustomerContextParams(com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getFullyHydratedProducts(@NonNull CatalogSearchRequest request, @NonNull List<T> content) getHydratedProductSuggestionsPricing(@NonNull List<Map<String, Object>> suggestions, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates pricing on product type-ahead suggetsions.protected ExternalCatalogSearchProviderPropertiesgetSearchResults(@NonNull CatalogSearchRequest request) Performs a search for the provided request.getSearchResultsForCategory(@NonNull CatalogEntityDetailsRequest detailsRequest, @NonNull Category category) Performs a search for products belonging to the provided category.getSuggestions(@NonNull CatalogTypeAheadRequest request) Gets suggestions for a search typeahead component based on the request.protected com.broadleafcommerce.common.extension.TypeFactorygetUrl()protected voidhydrateProductAssets(@NonNull Collection<T> products, org.springframework.util.MultiValueMap<String, String> parameters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Makes an additional call to theCatalogProviderto hydrateAssetsfor the search results.protected voidhydrateProductPricing(@NonNull Collection<T> products, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates pricing onto the results of a search request.protected voidhydrateProductTags(@NonNull Collection<T> products, org.springframework.util.MultiValueMap<String, String> parameters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Makes an additional call to theCatalogProviderto hydrateProductTagsfor the search results.booleanprotected voidoverrideProductPriceDetailsWithSkuData(Product product, ProductPricingPredicate predicate) By default, this method overrides the product prices for display in search with the values from the lowest priced sku.protected ProductPricingPredicateparseProductPricingPredicate(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to fetch theProductPricingPredicatefrom the search response, if it exists.protected voidsetProductPriceInfos(@NonNull Collection<T> products, com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.voidsetProperties(ExternalCatalogSearchProviderProperties properties) protected voidupdateBestPrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) protected voidupdatePricingKeyFromPredicate(ProductPricingPredicate predicate, Product product) Adds the pricing key from the predicate to the product if the product does not already have a pricing key value.Methods inherited from class com.broadleafcommerce.catalogbrowse.service.provider.external.AbstractExternalProvider
getAuthenticationUtils, getExternalProviderProperties, getHeaders, getHeaders, getMapper, isCallerWhitelistedService, setAuthenticationUtils, setExternalProviderProperties
-
Field Details
-
LOWEST_PRICED_SKU_KEY
- See Also:
-
CUSTOMER_CONTEXT_HEADER
- See Also:
-
-
Constructor Details
-
ExternalCatalogSearchProvider
public ExternalCatalogSearchProvider(@Qualifier("catalogSearchWebClient") org.springframework.web.reactive.function.client.WebClient catalogSearchWebClient, com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PricingProvider browsePricingProvider, CatalogProvider browseCatalogProvider)
-
-
Method Details
-
fetchCategoryWithDetailsAndSearchResponse
public Category fetchCategoryWithDetailsAndSearchResponse(@NonNull @NonNull CategoryDetailsRequest request) - Specified by:
fetchCategoryWithDetailsAndSearchResponsein interfaceCatalogSearchProvider<T extends Product>
-
getSearchResultsForCategory
public SearchResponse<T> getSearchResultsForCategory(@NonNull @NonNull CatalogEntityDetailsRequest detailsRequest, @NonNull @NonNull Category category) Description copied from interface:CatalogSearchProviderPerforms a search for products belonging to the provided category.- Specified by:
getSearchResultsForCategoryin interfaceCatalogSearchProvider<T extends Product>- Parameters:
detailsRequest- The original category requestcategory- The resolved category- Returns:
- The search results for the category.
-
getSearchResults
Description copied from interface:CatalogSearchProviderPerforms a search for the provided request.- Specified by:
getSearchResultsin interfaceCatalogSearchProvider<T extends Product>- Parameters:
request- All of the relevant information to be used to retrieve search results.- Returns:
- The
SearchResponsewith results for the request.
-
getSuggestions
Description copied from interface:CatalogSearchProviderGets suggestions for a search typeahead component based on the request.- Specified by:
getSuggestionsin interfaceCatalogSearchProvider<T extends Product>- Parameters:
request- All of the relevant information to be used to retrieve type-ahead suggestions.- Returns:
- The
TypeAheadResponsewith the results for the request.
-
getFullyHydratedProducts
protected List<T> getFullyHydratedProducts(@NonNull @NonNull CatalogSearchRequest request, @NonNull @NonNull List<T> content) -
getHydratedProductSuggestionsPricing
protected List<Map<String,Object>> getHydratedProductSuggestionsPricing(@NonNull @NonNull List<Map<String, Object>> suggestions, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates pricing on product type-ahead suggetsions.- Parameters:
suggestions- Suggestions to be hydratedpriceContext-PriceContextfrom the original request containing general pricing infopriceInfoContext-PriceInfoContextfrom the original request containing info specific for gettingPriceInfossuch as prefetchedPriceLists.contextInfo-ContextInfofrom the original request containing tenant and sandbox info- Returns:
- Hydrated product suggestions
-
hydrateProductPricing
protected void hydrateProductPricing(@NonNull @NonNull Collection<T> products, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceInfoContext priceInfoContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrates pricing onto the results of a search request.- Parameters:
products- The products from theSearchResponseto be hydratedpriceContext-PriceContextfrom the original request containing general pricing infopriceInfoContext-PriceInfoContextfrom the original request containing info specific for gettingPriceInfossuch as prefetchedPriceLists.contextInfo-ContextInfofrom the original request containing tenant and sandbox info
-
assignDefaultProductPriceInfos
protected void assignDefaultProductPriceInfos(@NonNull @NonNull Collection<T> products, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Parses theProductPricingPredicatereturned from the search results to add price details used by the pricing service to compute display results including the cost, base price, sale price, and pricing key for the product. If available, the system will override the product prices to those of it's lowest priced variant.- Parameters:
products- Search results whose contents to ensure to have aPriceInfosinstead of simple prices.priceContext-contextInfo-
-
overrideProductPriceDetailsWithSkuData
protected void overrideProductPriceDetailsWithSkuData(Product product, ProductPricingPredicate predicate) By default, this method overrides the product prices for display in search with the values from the lowest priced sku. This could be changed to utilize the default sku instead.- Parameters:
product-predicate-
-
updateBestPrice
protected void updateBestPrice(com.broadleafcommerce.pricing.client.domain.PriceInfo priceInfo) -
addPriceDetailsFromProductData
Add price details from product's data.For
DefaultPriceableFieldType.BASE_PRICEandDefaultPriceableFieldType.SALE_PRICE, ifProductPricingPredicate.getDefaultSku()exists and the price is available, then that price is used, otherwise use the price from theProductPricingPredicate.- Since:
- 1.8.8, 2.0.1
-
addPriceDetailFromProductData
protected void addPriceDetailFromProductData(Product product, DefaultPriceableFieldType fieldType, javax.money.MonetaryAmount price) -
addPriceDetail
protected void addPriceDetail(Product product, DefaultPriceableFieldType fieldType, @Nullable javax.money.MonetaryAmount price, boolean replaceExisting) -
updatePricingKeyFromPredicate
Adds the pricing key from the predicate to the product if the product does not already have a pricing key value. -
setProductPriceInfos
@Deprecated(forRemoval=true, since="1.8.2") protected void setProductPriceInfos(@NonNull @NonNull Collection<T> products, @Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.Ensures that allProductswith simple prices have those replaced with aPriceInfo.- Parameters:
products- Search results whose contents to ensure to have aPriceInfosinstead of simple prices.
-
hydrateProductAssets
protected void hydrateProductAssets(@NonNull @NonNull Collection<T> products, @Nullable org.springframework.util.MultiValueMap<String, String> parameters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Makes an additional call to theCatalogProviderto hydrateAssetsfor the search results.This hydration is gated by
isHydrateAssets().- Parameters:
products- The search results.parameters- Additional parameters to include the request like filterscontextInfo- Additional sandbox and multitenant state.
-
hydrateProductTags
protected void hydrateProductTags(@NonNull @NonNull Collection<T> products, @Nullable org.springframework.util.MultiValueMap<String, String> parameters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Makes an additional call to theCatalogProviderto hydrateProductTagsfor the search results.- Parameters:
products- The search results.parameters- Additional parameters to include the request like filterscontextInfo- Additional sandbox and multitenant state.
-
convertSuggestionsToProducts
-
convertSuggestionsToMap
-
buildCustomerContextHeader
-
createCustomerContext
protected CustomerContext createCustomerContext(org.springframework.util.MultiValueMap<String, String> customerParams, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getCustomerContextParams
protected org.springframework.util.MultiValueMap<String,String> getCustomerContextParams(@Nullable com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aorg.springframework.util.MultiValueMap<String,that includes params related to the currently authenticated user and any dynamic customer segments that should be passed along to the backing service.String> - Parameters:
priceContext- PriceContext header.contextInfo- Additional tenant and sandbox info along with dynamic customer segments.- Returns:
- A
org.springframework.util.MultiValueMap<String,that includes params related to the currently authenticated user and any dynamic customer segments that should be passed along to the backing service.String>
-
getAuthenticationParams
Builds aorg.springframework.util.MultiValueMap<String,that includes params related to the currently authenticated user that should be passed along to the backing service. This is needed because the authentication in that service will belong to the Cart Operations Client rather than the authenticated user.String> -
parseProductPricingPredicate
@Nullable protected ProductPricingPredicate parseProductPricingPredicate(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Attempts to fetch theProductPricingPredicatefrom the search response, if it exists. This is used for hydrating prices.- Parameters:
product-contextInfo-- Returns:
-
getUrl
-
getSearchUri
-
getSuggestUri
-
isHydrateAssets
public boolean isHydrateAssets() -
getServiceClient
-
getCatalogSearchWebClient
protected org.springframework.web.reactive.function.client.WebClient getCatalogSearchWebClient() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getBrowsePricingProvider
-
getCatalogProvider
-
getProperties
-
setProperties
-
assignDefaultProductPriceInfos(java.util.Collection<T>, com.broadleafcommerce.pricing.client.domain.context.PriceContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo)instead