public interface InventoryService
This basic inventory service checks and adjusts the current inventory of a sku. All Skus will be considered
generally unavailable from an inventory perspective if Sku#isAvaliable() returns false or if Sku.isActive()
returns false.
Skus with an InventoryType of null or 'ALWAYS_AVAILABLE' will be considered undefined from an inventory perspective, and will generally
be considered available. However, a request for available quantities of Skus with a null or 'ALWAYS_AVAILABLE' inventory type will
return null (as the Sku is available but no inventory strategy is defined).
| 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(Sku sku,
int quantity)
Attempts to decrement inventory if it is available.
|
void |
incrementInventory(Map<Sku,Integer> skuQuantities)
Attempts to increment inventory for a map of Skus and quantities.
|
void |
incrementInventory(Sku sku,
int quantity)
Attempts to increment inventory.
|
boolean |
isAvailable(Sku sku,
int quantity)
Indicates whether the given quantity is available for the particular skuId.
|
Map<Sku,Integer> |
retrieveQuantitiesAvailable(Collection<Sku> skus)
Retrieves the quantity available for a given sku.
|
Integer |
retrieveQuantityAvailable(Sku sku)
Retrieves the quantity available for a given sku.
|
Integer retrieveQuantityAvailable(Sku sku)
Retrieves 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 retrieveQuantitiesAvailable(Collection)
- Sku.getInventoryType() is null or
InventoryType.ALWAYS_AVAILABLE). Otherwise, this returns the quantity of the SkuMap<Sku,Integer> retrieveQuantitiesAvailable(Collection<Sku> skus)
Retrieves 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.
skus - the set of Skus to return inventory forMap.keySet()
is the same collection of given skus#retrieveQuantityAvailable(Sku)}boolean isAvailable(Sku sku, int quantity)
Indicates 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.
sku - the Sku to see if enough quantity is availablequantity - the quantity to check for the given skuboolean checkBasicAvailablility(Sku sku)
Sku 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
sku - the Sku whose availability is being checkedvoid decrementInventory(Sku sku, int quantity) throws InventoryUnavailableException
Attempts 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 decrementInventory(Map)
sku - the Sku to decrement inventory fromquantity - the quantity to take inventory fromInventoryUnavailableException - if there is not enough of the given quantity for the given skuIllegalArgumentException - if the given quantity is not greater than zerovoid decrementInventory(Map<Sku,Integer> skuQuantities) throws InventoryUnavailableException
Attempts 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
skuQuantities - 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 checkBasicAvailablility(Sku) returns falseIllegalArgumentException - if any of the quantities of the given skus are less than zerovoid incrementInventory(Sku sku, int quantity)
Attempts to increment inventory. Quantity must be greater than zero or an IllegalArgumentException will be thrown.
This is a convenience method to wrap incrementInventory(Map)
sku - the Sku whose inventory should be incrementedquantity - greater than zeroIllegalArgumentException - if quantity is less than zero or retrieveQuantityAvailable(Sku) for
the given sku returns null#incrementInventory(Map)}void incrementInventory(Map<Sku,Integer> skuQuantities)
If any of the given Skus inventory type is not InventoryType.CHECK_QUANTITY then this
is a no-op and nothing actually happens
skuQuantities - the map of a Sku to the quantity that should be incrementedIllegalArgumentException - if any of the quantities in the map values are null or less than zero, or if
retrieveQuantityAvailable(Sku) for the Skus in the map is nullCopyright © 2015. All Rights Reserved.