}
// First check if this Sku is available
if (!sku.isAvailable()) {
throw new InventoryUnavailableException("The referenced Sku " + sku.getId() + " is marked as unavailable",
sku.getId(), request.getItemRequest().getQuantity(), 0);
}
if (InventoryType.CHECK_QUANTITY.equals(sku.getInventoryType())) {
Integer requestedQuantity = request.getItemRequest().getQuantity();
Map<String, Object> inventoryContext = new HashMap<String, Object>();
inventoryContext.put(ContextualInventoryService.ORDER_KEY, context.getSeedData().getOrder());
boolean available = inventoryService.isAvailable(sku, requestedQuantity, inventoryContext);
if (!available) {
throw new InventoryUnavailableException(sku.getId(),
requestedQuantity, inventoryService.retrieveQuantityAvailable(sku, inventoryContext));
}
}
// the other case here is ALWAYS_AVAILABLE and null, which we are treating as being available