@Service(value="blInventoryService") public class InventoryServiceImpl extends Object implements ContextualInventoryService
| Modifier and Type | Field and Description |
|---|---|
protected CatalogService |
catalogService |
protected InventoryServiceExtensionManager |
extensionManager |
ORDER_KEY, ROLLBACK_STATE_KEY| Constructor and Description |
|---|
InventoryServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkBasicAvailablility(Sku sku)
Without worrying about quantities, just checks to see if the given Sku is available.
|
void |
decrementInventory(Map<Sku,Integer> skuQuantities)
Attempts to decrement inventory for a map of Skus and quantities
|
void |
decrementInventory(Map<Sku,Integer> skuQuantities,
Map<String,Object> context)
Usually invoked from
DecrementInventoryActivity |
void |
decrementInventory(Sku sku,
int quantity)
Attempts to decrement inventory if it is available.
|
void |
decrementInventory(Sku sku,
int quantity,
Map<String,Object> context)
Pass through for
ContextualInventoryService.decrementInventory(Map, Map) |
void |
incrementInventory(Map<Sku,Integer> skuQuantities)
Attempts to increment inventory for a map of Skus and quantities.
|
void |
incrementInventory(Map<Sku,Integer> skuQuantities,
Map<String,Object> context)
Callers that invoke this method directly should check for a
ContextualInventoryService.ROLLBACK_STATE_KEY in the given context. |
void |
incrementInventory(Sku sku,
int quantity)
Attempts to increment inventory.
|
void |
incrementInventory(Sku sku,
int quantity,
Map<String,Object> context) |
boolean |
isAvailable(Sku sku,
int quantity)
Indicates whether the given quantity is available for the particular skuId.
|
boolean |
isAvailable(Sku sku,
int quantity,
Map<String,Object> context) |
Map<Sku,Integer> |
retrieveQuantitiesAvailable(Collection<Sku> skus)
Retrieves the quantity available for a given sku.
|
Map<Sku,Integer> |
retrieveQuantitiesAvailable(Collection<Sku> skus,
Map<String,Object> context) |
Integer |
retrieveQuantityAvailable(Sku sku)
Retrieves the quantity available for a given sku.
|
Integer |
retrieveQuantityAvailable(Sku sku,
Map<String,Object> context) |
protected CatalogService catalogService
protected InventoryServiceExtensionManager extensionManager
public boolean checkBasicAvailablility(Sku sku)
InventoryServiceSku is
generally available if any of these is true:
Sku.getInventoryType() is nullSku.getInventoryType() is anything but InventoryType.UNAVAILABLESku.isAvailable() is true or nullThis will return true if Sku.getInventoryType() is InventoryType.CHECK_QUANTITY
checkBasicAvailablility in interface InventoryServicesku - the Sku whose availability is being checkedpublic Integer retrieveQuantityAvailable(Sku sku)
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 InventoryType of the given sku is InventoryType.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)
retrieveQuantityAvailable in interface InventoryServiceSku.getInventoryType() is null or
InventoryType.ALWAYS_AVAILABLE). Otherwise, this returns the quantity of the Skupublic Map<Sku,Integer> retrieveQuantitiesAvailable(Collection<Sku> skus)
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 InventoryType of the given sku is InventoryType.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.
retrieveQuantitiesAvailable in interface InventoryServiceskus - the set of Skus to return inventory forMap.keySet()
is the same collection of given skus#retrieveQuantityAvailable(Sku)}public boolean isAvailable(Sku sku, int quantity)
InventoryServiceIndicates whether the given quantity is available for the particular skuId. The result will be true if Sku.getInventoryType() == null or not Sku.getInventoryType().equals(InventoryType.ALWAYS_AVAILABLE).
The result will be false if the Sku is inactive, if the Sku.getAvaialable() == false, if the quantity field is null, or if the quantity requested exceeds the quantity available.
isAvailable in interface InventoryServicesku - the Sku to see if enough quantity is availablequantity - the quantity to check for the given sku@Transactional(value="blTransactionManager",
rollbackFor=InventoryUnavailableException.class)
public void decrementInventory(Sku sku,
int quantity)
throws InventoryUnavailableException
InventoryServiceAttempts to decrement inventory if it is available. If the Sku is marked as InventoryType.ALWAYS_AVAILABLE
then this will be a no-op.
This method is a convenience method to wrap InventoryService.decrementInventory(Map)
decrementInventory in interface InventoryServicesku - the Sku to decrement inventory fromquantity - the quantity to take inventory fromInventoryUnavailableException - if there is not enough of the given quantity for the given sku@Transactional(value="blTransactionManager",
rollbackFor=InventoryUnavailableException.class)
public void decrementInventory(Map<Sku,Integer> skuQuantities)
throws InventoryUnavailableException
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 not InventoryType.CHECK_QUANTITY then this
is a no-op and nothing actually happens
decrementInventory in interface InventoryServiceskuQuantities - a map from a Sku to the quantity attempting to decrementInventoryUnavailableException - if there is not enough inventory to decrement from any of the given skus or
if InventoryService.checkBasicAvailablility(Sku) returns false@Transactional(value="blTransactionManager") public void incrementInventory(Sku sku, int quantity)
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)
incrementInventory in interface InventoryServicesku - the Sku whose inventory should be incrementedquantity - greater than zero#incrementInventory(Map)}@Transactional(value="blTransactionManager") public void incrementInventory(Map<Sku,Integer> skuQuantities)
InventoryServiceIf any of the given Skus inventory type is not InventoryType.CHECK_QUANTITY then this
is a no-op and nothing actually happens
incrementInventory in interface InventoryServiceskuQuantities - the map of a Sku to the quantity that should be incrementedpublic Integer retrieveQuantityAvailable(Sku sku, Map<String,Object> context)
retrieveQuantityAvailable in interface ContextualInventoryServicecontext - can be null. If not null, this should at least contain the #CART_CONTEXT_KEY#retrieveQuantitiesAvailable(Collection, Map)}public Map<Sku,Integer> retrieveQuantitiesAvailable(Collection<Sku> skus, Map<String,Object> context)
retrieveQuantitiesAvailable in interface ContextualInventoryServicecontext - can be null. If not null, this should at least contain the #CART_CONTEXT_KEY#retrieveQuantitiesAvailable(Collection)}public boolean isAvailable(Sku sku, int quantity, Map<String,Object> context)
isAvailable in interface ContextualInventoryServicecontext - can be null. If not null, this should at least contain the #CART_CONTEXT_KEY#isAvailable(Sku, int)}@Transactional(value="blTransactionManager",
rollbackFor=InventoryUnavailableException.class)
public void decrementInventory(Sku sku,
int quantity,
Map<String,Object> context)
throws InventoryUnavailableException
ContextualInventoryServicePass through for ContextualInventoryService.decrementInventory(Map, Map)
decrementInventory in interface ContextualInventoryServiceInventoryUnavailableException#decrementInventory(Map, Map)}@Transactional(value="blTransactionManager",
rollbackFor=InventoryUnavailableException.class)
public void decrementInventory(Map<Sku,Integer> skuQuantities,
Map<String,Object> context)
throws InventoryUnavailableException
ContextualInventoryServiceUsually invoked from DecrementInventoryActivity
Callers 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
interface
Implementers of this method (explicitly those that are utilizing the InventoryServiceExtensionHandler)
should populate a ContextualInventoryService.ROLLBACK_STATE_KEY within the given context in order to communicate back to the
caller what actually happened while decrementing inventory so that it can be undone later
decrementInventory in interface ContextualInventoryServicecontext - can be null. If not null, this should at least contain the ContextualInventoryService.ORDER_KEY and/or the
ContextualInventoryService.ROLLBACK_STATE_KEYInventoryUnavailableException#decrementInventory(Map)}@Transactional(value="blTransactionManager") public void incrementInventory(Sku sku, int quantity, Map<String,Object> context)
incrementInventory in interface ContextualInventoryService#incrementInventory(Map, Map)}@Transactional(value="blTransactionManager") public void incrementInventory(Map<Sku,Integer> skuQuantities, Map<String,Object> context)
ContextualInventoryServiceCallers that invoke this method directly should check for a ContextualInventoryService.ROLLBACK_STATE_KEY in the given context.
This will contain information about what actually happened in terms of decrementing inventory
Implementers of this method (explicitly those that are utilizing the InventoryServiceExtensionHandler)
should populate a ContextualInventoryService.ROLLBACK_STATE_KEY within the given context in order to communicate back to the
caller what actually happened while decrementing inventory so that it can be undone later
incrementInventory in interface ContextualInventoryServicecontext - can be null. If not null, this should at least contain the ContextualInventoryService.ROLLBACK_STATE_KEY#incrementInventory(Map)}Copyright © 2014. All Rights Reserved.