Class InventoryServiceImpl
- All Implemented Interfaces:
ContextualInventoryService,InventoryService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContextprotected CatalogServiceprotected InventoryServiceExtensionManagerFields inherited from interface org.broadleafcommerce.core.inventory.service.ContextualInventoryService
CHANGE_ORDER_KEY, ORDER_KEY, ROLLBACK_STATE_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildSkuInventoryMap(Order order) Convenience method to build the sku inventory map given anOrderbooleanWithout worrying about quantities, just checks to see if the given Sku is available.voidcheckSkuAvailability(Order order, Sku sku, Integer requestedQuantity) voiddecrementInventory(Map<Sku, Integer> skuQuantities) Attempts to decrement inventory for a map of Skus and quantitiesvoidUsually invoked fromDecrementInventoryActivityvoiddecrementInventory(Sku sku, int quantity) Attempts to decrement inventory if it is available.voiddecrementInventory(Sku sku, int quantity, Map<String, Object> context) Pass through forContextualInventoryService.decrementInventory(Map, Map)protected voidvoidincrementInventory(Map<Sku, Integer> skuQuantities) Attempts to increment inventory for a map of Skus and quantities.voidCallers that invoke this method directly should check for aContextualInventoryService.ROLLBACK_STATE_KEYin the given context.voidincrementInventory(Sku sku, int quantity) Attempts to increment inventory.voidincrementInventory(Sku sku, int quantity, Map<String, Object> context) protected voidprotected voidinvalidateEntity(Class<?> clazz, String id) Given the class and identifier of an entity, invalidates the cache for that entityprotected voidInvalidates the cache for a given skubooleanisAvailable(Sku sku, int quantity) Indicates whether the given quantity is available for the particular skuId.booleanisAvailable(Sku sku, int quantity, Map<String, Object> context) voidreconcileChangeOrderInventory(Map<Sku, Integer> decrementSkuQuantities, Map<Sku, Integer> incrementSkuQuantities, Map<String, Object> context) Explicit method that defines exactly how to reconcile inventory in the event of a change order.Retrieves the quantity available for a given sku.retrieveQuantitiesAvailable(Collection<Sku> skus, Map<String, Object> context) Retrieves the quantity available for a given sku.retrieveQuantityAvailable(Sku sku, Map<String, Object> context)
-
Field Details
-
catalogService
-
extensionManager
-
applicationContext
@Autowired protected org.springframework.context.ApplicationContext applicationContext
-
-
Constructor Details
-
InventoryServiceImpl
public InventoryServiceImpl()
-
-
Method Details
-
checkBasicAvailablility
Description copied from interface:InventoryServiceWithout worrying about quantities, just checks to see if the given Sku is available. ASkuis generally available if any of these is true:Sku.getInventoryType()is nullSku.getInventoryType()is anything butInventoryType.UNAVAILABLESku.isActive()is is true or null- Does not consider the now-deprecated
Sku.isAvailable()
* @param sku the
Skuwhose availability is being checked- Specified by:
checkBasicAvailablilityin interfaceInventoryService- Returns:
- true or false according to the rules above
-
retrieveQuantityAvailable
Description copied from interface:InventoryServiceRetrieves the quantity available for a given sku. May return null if no inventory is maintained for the given sku when Sku.getInventoryType() == null or the
InventoryTypeof the given sku isInventoryType.ALWAYS_AVAILABLE. Effectively, if the quantity returned is null, inventory is undefined, which most likely means it is available. However, rather than returning an arbitrary integer values (like Integer.MAX_VALUE), which has specific meaning, we return null as this can be interpreted by the client to mean whatever they define it as (including infinitely available), which is the most likely scenario.In practice, this is a convenience method to wrap
InventoryService.retrieveQuantitiesAvailable(Collection)- Specified by:
retrieveQuantityAvailablein interfaceInventoryService- Returns:
- null if there is no inventory strategy defined (meaning,
Sku.getInventoryType()is null orInventoryType.ALWAYS_AVAILABLE). Otherwise, this returns the quantity of theSku
-
retrieveQuantitiesAvailable
Description copied from interface:InventoryServiceRetrieves the quantity available for a given sku. May return null if no inventory is maintained for the given sku when Sku.getInventoryType() == null or the
InventoryTypeof the given sku isInventoryType.ALWAYS_AVAILABLE. Effectively, if the quantity returned is null, inventory is undefined, which most likely means it is available. However, rather than returning an arbitrary integer values (like Integer.MAX_VALUE), which has specific meaning, we return null as this can be interpreted by the client to mean whatever they define it as (including infinitely available), which is the most likely scenario.- Specified by:
retrieveQuantitiesAvailablein interfaceInventoryService- Parameters:
skus- the set ofSkus to return inventory for- Returns:
- a map of the given set of skus to the quantity as represented in the inventory system. The
Map.keySet()is the same collection of given skus
-
isAvailable
Description copied from interface:InventoryServiceIndicates whether the given quantity is available for the particular skuId. The result will be true if Sku.getInventoryType() == null or Sku.getInventoryType().equals(InventoryType.ALWAYS_AVAILABLE).
The result will be false if the
InventoryService.checkBasicAvailablility(Sku)returns false, or if the quantity field is null, or if the quantity requested exceeds the quantity available.- Specified by:
isAvailablein interfaceInventoryService- Parameters:
sku- theSkuto see if enough quantity is availablequantity- the quantity to check for the given sku- Returns:
- true if there is available quantity
-
decrementInventory
@Transactional(value="blTransactionManager", rollbackFor=InventoryUnavailableException.class) public void decrementInventory(Sku sku, int quantity) throws InventoryUnavailableException Description copied from interface:InventoryServiceAttempts to decrement inventory if it is available. If the Sku is marked as
InventoryType.ALWAYS_AVAILABLEthen this will be a no-op.This method is a convenience method to wrap
InventoryService.decrementInventory(Map)- Specified by:
decrementInventoryin interfaceInventoryService- Parameters:
sku- theSkuto decrement inventory fromquantity- the quantity to take inventory from- Throws:
InventoryUnavailableException- if there is not enough of the given quantity for the given sku
-
decrementInventory
@Transactional(value="blTransactionManager", rollbackFor=InventoryUnavailableException.class) public void decrementInventory(Map<Sku, Integer> skuQuantities) throws InventoryUnavailableExceptionDescription copied from interface:InventoryServiceAttempts to decrement inventory for a map of Skus and quantities
Quantities must be greater than zero or an IllegalArgumentException will be thrown.
If any of the given
Skus inventory type is notInventoryType.CHECK_QUANTITYthen this is a no-op and nothing actually happens- Specified by:
decrementInventoryin interfaceInventoryService- Parameters:
skuQuantities- a map from aSkuto the quantity attempting to decrement- Throws:
InventoryUnavailableException- if there is not enough inventory to decrement from any of the given skus or ifInventoryService.checkBasicAvailablility(Sku)returns false
-
incrementInventory
Description copied from interface:InventoryServiceAttempts to increment inventory. Quantity must be greater than zero or an IllegalArgumentException will be thrown.
This is a convenience method to wrap
InventoryService.incrementInventory(Map)- Specified by:
incrementInventoryin interfaceInventoryService- Parameters:
sku- theSkuwhose inventory should be incrementedquantity- greater than zero
-
incrementInventory
@Transactional("blTransactionManager") public void incrementInventory(Map<Sku, Integer> skuQuantities) Description copied from interface:InventoryServiceAttempts to increment inventory for a map of Skus and quantities. All must not be null and must be greater than zero or an IllegalArgumentException will be thrown.If any of the given
Skus inventory type is notInventoryType.CHECK_QUANTITYthen this is a no-op and nothing actually happens- Specified by:
incrementInventoryin interfaceInventoryService- Parameters:
skuQuantities- the map of aSkuto the quantity that should be incremented
-
retrieveQuantityAvailable
- Specified by:
retrieveQuantityAvailablein interfaceContextualInventoryServicecontext- can be null. If not null, this should at least contain the#CART_CONTEXT_KEY
-
retrieveQuantitiesAvailable
public Map<Sku,Integer> retrieveQuantitiesAvailable(Collection<Sku> skus, Map<String, Object> context) - Specified by:
retrieveQuantitiesAvailablein interfaceContextualInventoryServicecontext- can be null. If not null, this should at least contain the#CART_CONTEXT_KEY
-
isAvailable
- Specified by:
isAvailablein interfaceContextualInventoryServicecontext- can be null. If not null, this should at least contain the#CART_CONTEXT_KEY
-
decrementInventory
@Transactional(value="blTransactionManager", rollbackFor=InventoryUnavailableException.class) public void decrementInventory(Sku sku, int quantity, Map<String, Object> context) throws InventoryUnavailableExceptionDescription copied from interface:ContextualInventoryServicePass through for
ContextualInventoryService.decrementInventory(Map, Map)- Specified by:
decrementInventoryin interfaceContextualInventoryService- Throws:
InventoryUnavailableException
-
decrementInventory
@Transactional(value="blTransactionManager", rollbackFor=InventoryUnavailableException.class) public void decrementInventory(Map<Sku, Integer> skuQuantities, Map<String, throws InventoryUnavailableExceptionObject> context) Description copied from interface:ContextualInventoryServiceUsually invoked from
DecrementInventoryActivityCallers that invoke this method directly should check the given context object for a
ContextualInventoryService.ROLLBACK_STATE_KEY. This will contain information about what actually happened in terms of decrementing inventory. For implementers of this interfaceImplementers of this method (explicitly those that are utilizing the
InventoryServiceExtensionHandler) should populate aContextualInventoryService.ROLLBACK_STATE_KEYwithin the given context in order to communicate back to the caller what actually happened while decrementing inventory so that it can be undone later- Specified by:
decrementInventoryin interfaceContextualInventoryServicecontext- can be null. If not null, this should at least contain theContextualInventoryService.ORDER_KEYand/or theContextualInventoryService.ROLLBACK_STATE_KEY- Throws:
InventoryUnavailableException
-
decrementSku
protected void decrementSku(Map<Sku, Integer> skuQuantities, Map<String, throws InventoryUnavailableExceptionObject> context) - Throws:
InventoryUnavailableException
-
incrementInventory
@Transactional("blTransactionManager") public void incrementInventory(Sku sku, int quantity, Map<String, Object> context) - Specified by:
incrementInventoryin interfaceContextualInventoryService
-
incrementInventory
@Transactional("blTransactionManager") public void incrementInventory(Map<Sku, Integer> skuQuantities, Map<String, Object> context) Description copied from interface:ContextualInventoryServiceCallers that invoke this method directly should check for a
ContextualInventoryService.ROLLBACK_STATE_KEYin the given context. This will contain information about what actually happened in terms of decrementing inventoryImplementers of this method (explicitly those that are utilizing the
InventoryServiceExtensionHandler) should populate aContextualInventoryService.ROLLBACK_STATE_KEYwithin the given context in order to communicate back to the caller what actually happened while decrementing inventory so that it can be undone later- Specified by:
incrementInventoryin interfaceContextualInventoryServicecontext- can be null. If not null, this should at least contain theContextualInventoryService.ROLLBACK_STATE_KEY
-
incrementSku
-
reconcileChangeOrderInventory
public void reconcileChangeOrderInventory(Map<Sku, Integer> decrementSkuQuantities, Map<Sku, throws InventoryUnavailableExceptionInteger> incrementSkuQuantities, Map<String, Object> context) Description copied from interface:ContextualInventoryServiceExplicit method that defines exactly how to reconcile inventory in the event of a change order. This usually occurs after an order has been submitted and any inventory changes and reservations/holds have already been committed.
Implementers of this method should assume that the quantities passed in are deltas and represent the changed quantities (either incremented or decremented) from the old order to the newly changed order.
- Specified by:
reconcileChangeOrderInventoryin interfaceContextualInventoryService- Parameters:
decrementSkuQuantities- - the delta change of sku quantities to decrementincrementSkuQuantities- - the delta change of sku quantities to increment- Throws:
InventoryUnavailableException
-
buildSkuInventoryMap
Description copied from interface:ContextualInventoryServiceConvenience method to build the sku inventory map given an
Order- Specified by:
buildSkuInventoryMapin interfaceContextualInventoryService- Returns:
- a SKU to Quantity map represented by the items and quantities on the fulfillment group and fulfillment group items in the order.
-
invalidateSkuInventory
Invalidates the cache for a given sku- Parameters:
sku- The Sku to be invalidated from cache
-
invalidateEntity
Given the class and identifier of an entity, invalidates the cache for that entity- Parameters:
clazz- The class of the entity to invalidate the cache forid- The id of the entity to invalidate the cache for
-
checkSkuAvailability
public void checkSkuAvailability(Order order, Sku sku, Integer requestedQuantity) throws InventoryUnavailableException - Specified by:
checkSkuAvailabilityin interfaceContextualInventoryService- Throws:
InventoryUnavailableException
-