Class ProductInventoryAvailableSolrDocumentContributor
- java.lang.Object
-
- com.broadleafcommerce.search.index.catalog.solr.document.ProductInventoryAvailableSolrDocumentContributor
-
- All Implemented Interfaces:
com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
public class ProductInventoryAvailableSolrDocumentContributor extends Object implements com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
A component to contribute a field to theSolrInputDocument
to hold inventory availability for a product. This is not meant to hold store-level availability, nor quantity-level availability. Rather this simply stores, in Solr, details about general availability so that search components can either hide or bury unavailable items during browsing and searching. There may be some concern about invoking a remote call to InventoryServices for each document. The reason that it was done this way to begin with is that in some cases, clients have dozens or hundreds of SKUs (sku codes) perProduct
. As a result, we will rely on efficient calls to Inventory Services to populate inventory-related fields on a per-Product, multi-SKU basis. It is assumed that these calls will be efficient and that Inventory Services will allow for scaling due to multi-threaded calls during a multi-threaded reindexing process. This component can easily be disabled by overriding it and retuning false, from the canHandle(Indxable) method.- Author:
- Kelly Tisdell (ktisdell)
- See Also:
InventoryAvailabilityQueryContributor
-
-
Constructor Summary
Constructors Constructor Description ProductInventoryAvailableSolrDocumentContributor(com.broadleafcommerce.search.index.catalog.service.InventoryAvailabilityService inventoryAvailabilityService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canHandle(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
void
contributeInternal(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields)
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
createContextInfo(String tenantId)
Return aContextInfo
to allow us to query the Inventory Services.protected com.broadleafcommerce.search.index.catalog.service.InventoryAvailabilityService
getInventoryAvailabilityService()
protected void
handleSetInventoryAvailableFilterFieldException(com.broadleafcommerce.search.catalog.core.domain.Product product, Exception e)
By default, we want to log the error and otherwise, suppress it to avoid stopping an entire process.protected boolean
isProduction(com.broadleafcommerce.search.catalog.core.domain.Product product)
We only want to apply inventory details to production records, so we need to determine if this product is a "production" record.protected void
setInventoryAvailableFilterField(com.broadleafcommerce.search.catalog.core.domain.Product product, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields)
This method adds a Solr doc field indicating which tenants or applications have inventory for this product.protected void
setInventoryCheckRequiredFilterField(com.broadleafcommerce.search.catalog.core.domain.Product product, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields)
This method adds a Solr doc field indicating whether this product is inventory-sensitive.
-
-
-
Method Detail
-
contributeInternal
public void contributeInternal(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields) throws com.broadleafcommerce.search.api.SearchIndexException
- Specified by:
contributeInternal
in interfacecom.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
-
canHandle
public boolean canHandle(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
- Specified by:
canHandle
in interfacecom.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
-
setInventoryCheckRequiredFilterField
protected void setInventoryCheckRequiredFilterField(com.broadleafcommerce.search.catalog.core.domain.Product product, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields)
This method adds a Solr doc field indicating whether this product is inventory-sensitive. By default, the Solr field name is 'inventoryCheckRequired_b' - a boolean field, indicating if we care about inventory while browsing or searching this product. By default, if either inventoryReservationStrategy or inventoryCheckStrategy on the product is anything but null or 'NEVER', then this field is set to true.- Parameters:
product
- the product representation, from Catalog Servicesdocument
- the Solr representation of the Product, so farcontext
- the JSON document contextsearchFields
- a list of Search fields
-
setInventoryAvailableFilterField
protected void setInventoryAvailableFilterField(com.broadleafcommerce.search.catalog.core.domain.Product product, org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields)
This method adds a Solr doc field indicating which tenants or applications have inventory for this product. By default, the Solr field name is 'inventoryAvailableForScope_ss' - a multi-valued string field, indicating which tenants and/or applications have inventory available. This method does a callout to Inventory Services.- Parameters:
product
- the product representation, from Catalog Servicesdocument
- the Solr representation of the Product, so farcontext
- the JSON document contextsearchFields
- a list of Search fields
-
createContextInfo
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo createContextInfo(String tenantId)
Return aContextInfo
to allow us to query the Inventory Services. This will only contain the tenantId of theProduct
in question.- Parameters:
tenantId
-- Returns:
-
isProduction
protected boolean isProduction(com.broadleafcommerce.search.catalog.core.domain.Product product)
We only want to apply inventory details to production records, so we need to determine if this product is a "production" record. By default, this means that it has a tracking level of 100000.- Parameters:
product
-- Returns:
-
handleSetInventoryAvailableFilterFieldException
protected void handleSetInventoryAvailableFilterFieldException(com.broadleafcommerce.search.catalog.core.domain.Product product, Exception e)
By default, we want to log the error and otherwise, suppress it to avoid stopping an entire process. Implementors may wish to override this. This is meant to allow one to (re)throw aRuntimeException
, log the error (default behavior), etc. By default, this logs the error to prevent (re)indexing the product. But this will also mean that reindexing of this Product may complete successfully, but that it is not available during search and browse. By default, this logs the exception and otherwise, allows this document to be indexed without inventory.- Parameters:
e
-
-
getInventoryAvailabilityService
protected com.broadleafcommerce.search.index.catalog.service.InventoryAvailabilityService getInventoryAvailabilityService()
-
-