Class CatalogTrackableSolrQueryContributor
- All Implemented Interfaces:
SolrQueryContributor,org.springframework.core.Ordered
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddMarketplaceFilter(@NonNull org.apache.solr.client.solrj.SolrQuery solrQuery, @NonNull com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context, @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.Application application) Adds filtering when the requested Application is a marketplace.protected StringaddPendingMarketplaceApplicationFilter(com.broadleafcommerce.data.tracking.core.tenant.domain.Application application, String marketplaceApplication) protected Stringprotected StringbuildFilterOnCatalogOmissions(Set<String> catalogIds) We expect catalog omissions to be populated any time we expect a trackable record to not be inherited by a certain catalog.protected StringbuildFilterOnCreatingApplication(String applicationId) protected StringbuildFilterOnIncludedCatalogs(Set<String> catalogsToInclude) protected StringbuildFilterOnPlainCatalogOverrides(Set<String> catalogIds) protected StringbuildFilterOnSandboxAwareCatalogOverrides(Set<String> catalogIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) SolrNarrowFields.CATALOG_OVERRIDESwill contain an entry if there is _any_ override record in a more derived catalog, regardless of whether the override is at user level, higher-than-user level (ex: promoted), or production, and regardless of which sandbox the change is in (ex: even if the base record and derived record are both sandbox changes, but are in different sandboxes, in which case the derived record really isn't an override of the base record at all).protected voidcontributeInternal(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, String locale, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Customize the providedsolrQuerywith some additional behavior.booleanprotected StringCreate a filter for documents with no specified catalog.protected StringfilterOverriddenCatalogs(Set<String> catalogIds, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create a filter to exclude documents for which more specific versions exist for this catalog context.getApplicationCatalogs(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve all catalogs visible from the current application.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsgetForcedCatalogs(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve currently specified visible catalogs.voidsetAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) protected booleanshouldContribute(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Determines if this contributor should run.Methods inherited from class com.broadleafcommerce.search.provider.solr.AbstractCatalogTrackableSolrQueryContributor
addPositiveExpressionModifier, getArchivedCatalogs, getCatalogs, getCatalogsForApplication, getDirectImplicitCatalogsForApplicationMethods inherited from class com.broadleafcommerce.search.provider.solr.AbstractSolrQueryContributor
contributeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.search.provider.solr.SolrQueryContributor
getOrder, isTypeAheadRequest
-
Constructor Details
-
CatalogTrackableSolrQueryContributor
public CatalogTrackableSolrQueryContributor()
-
-
Method Details
-
contributeInternal
protected void contributeInternal(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fieldDefinitions, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, @Nullable String locale, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from class:AbstractSolrQueryContributorCustomize the providedsolrQuerywith some additional behavior.- Specified by:
contributeInternalin classAbstractSolrQueryContributor- Parameters:
solrQuery- The query to customizesearchRequest- The search query requestfieldDefinitions- The fields to perform the search onpage- Page information for page to retrieve for queryproperties- Additional properties for this querylocale- The locale of this searchcontext- The context information surrounding sandboxing/multitenant state
-
getForcedCatalogs
protected Set<String> getForcedCatalogs(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve currently specified visible catalogs.- Parameters:
context- The context information surrounding sandboxing/multitenant state- Returns:
- Catalogs narrowed to only specified visible catalogs
-
addMarketplaceFilter
protected void addMarketplaceFilter(@NonNull @NonNull org.apache.solr.client.solrj.SolrQuery solrQuery, @NonNull @NonNull com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo context, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.tenant.domain.Application application) Adds filtering when the requested Application is a marketplace. This will add filtering bySolrNarrowFields.MARKETPLACE_APPLICATIONSas well as isolated catalog ids.- Parameters:
solrQuery- Query to add the filter tosearchRequest- details about the search requestcontext- Additional context infoapplication- Requested application
-
addPendingMarketplaceApplicationFilter
-
getApplicationCatalogs
protected Set<String> getApplicationCatalogs(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Retrieve all catalogs visible from the current application.- Parameters:
context- The context information surrounding sandboxing/multitenant state- Returns:
- Catalogs narrowed to all catalogs visible from the current application.
-
filterOnNoCatalog
Create a filter for documents with no specified catalog.Note that the nested negative filter must contain a "*:* AND" as well. See https://stackoverflow.com/questions/7363819
- Returns:
- A filter for documents with no specified catalog.
-
filterOverriddenCatalogs
protected String filterOverriddenCatalogs(Set<String> catalogIds, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create a filter to exclude documents for which more specific versions exist for this catalog context.- Parameters:
catalogIds- The IDs of the catalogs which are used for this contextsearchRequest- details about the search requestcontextInfo- context information around multitenant state- Returns:
- Filter query to exclude less specific catalog documents
-
buildFilterOnPlainCatalogOverrides
-
buildFilterOnSandboxAwareCatalogOverrides
protected String buildFilterOnSandboxAwareCatalogOverrides(Set<String> catalogIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) SolrNarrowFields.CATALOG_OVERRIDESwill contain an entry if there is _any_ override record in a more derived catalog, regardless of whether the override is at user level, higher-than-user level (ex: promoted), or production, and regardless of which sandbox the change is in (ex: even if the base record and derived record are both sandbox changes, but are in different sandboxes, in which case the derived record really isn't an override of the base record at all).Normally, we universally filter out records who have an override in a more derived catalog, with the expectation that the more derived record will be included in the results and can be returned to the caller. However, we cannot do this with sandboxable entities, because the override itself may not be visible to the current user.
Consider a scenario where we have 'Tenant Catalog Product X', and UserA has made a user-level change to that product in 'childCatalog' (ex: application catalog). Then, UserB performs a search for products in 'childCatalog'.
In this case, even though
SolrNarrowFields.CATALOG_OVERRIDESfor 'Tenant Catalog Product X' would contain 'childCatalog', we actually cannot exclude this record because the current user should only be able to see user-level records _they_ have created, higher-than-user-level records, or production records. And as such, the 'Tenant Catalog Product X' record should actually be included in the results.The
SandboxTrackableSolrQueryContributoralready takes care of adding appropriate filters to only expose the appropriate sandbox changes to the current user.However, we still need to make sure our catalog override filters are not overzealous and are incorporating sandboxing awareness before excluding a record. Thus, we should only exclude a record that has been overridden in one of the provided catalogs if we know that at least one of those overrides is actually visible to the current user. That is why we must use
SolrNarrowFields.SANDBOX_AWARE_CATALOG_OVERRIDES.- Parameters:
catalogIds- the catalog IDs that should be included in the resultscontextInfo- context information about sandboxing and multitenant state- Returns:
- a solr filter on sandbox-aware catalog overrides
-
shouldContribute
protected boolean shouldContribute(org.apache.solr.client.solrj.SolrQuery solrQuery, com.broadleafcommerce.search.api.domain.SearchRequest searchRequest, org.springframework.data.domain.Pageable page, com.broadleafcommerce.search.core.service.SearchRequestProperties properties, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from class:AbstractSolrQueryContributorDetermines if this contributor should run.- Specified by:
shouldContributein classAbstractSolrQueryContributor- Parameters:
solrQuery- The query to customizesearchRequest- The search query requestpage- Page information for page to retrieve for queryproperties- Additional properties for this query.context- The context information surrounding sandboxing/multitenant state- Returns:
- whether this contributor should run
-
contributeOnTypeAhead
public boolean contributeOnTypeAhead()- Returns:
- Should this contributor be executed on TypeAhead requests?
-
buildFilterOnIncludedCatalogs
- Parameters:
catalogsToInclude- IDs of catalogs to include- Returns:
- a solr filter against
SolrNarrowFields.CATALOG
-
buildFilterForProductionTrackingLevel
- Returns:
- solr filter to get production-level records
-
buildFilterOnCreatingApplication
- Parameters:
applicationId- the application ID to filter on- Returns:
- solr filter where
SolrNarrowFields.CREATING_APPLICATION_IDmatches the givenapplicationId
-
buildFilterOnCatalogOmissions
We expect catalog omissions to be populated any time we expect a trackable record to not be inherited by a certain catalog. This can be because the current record is a new creation at the sandbox level (only production inheritance is allowed), or because we have inclusion/exclusion filters on the catalogs for specific records.
Omissions are calculated from a production context, so generally speaking are safe to indiscriminately filter against, since the omission should apply everywhere.
- Parameters:
catalogIds- the catalog IDs that should be included in the results- Returns:
- a solr filter on
SolrNarrowFields.CATALOG_OMISSIONS
-
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils() -
setAuthenticationUtils
@Autowired public void setAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
-