Class DefaultSkuInventoryAdjustmentService<I extends SkuInventory>
java.lang.Object
com.broadleafcommerce.inventory.service.DefaultSkuInventoryAdjustmentService<I>
- All Implemented Interfaces:
SkuInventoryAdjustmentService<I>
@Transactional(transactionManager="inventoryTransactionManager",
rollbackFor={InventoryUnavailableException.class,InventoryNotReservedException.class},
propagation=REQUIRES_NEW)
public class DefaultSkuInventoryAdjustmentService<I extends SkuInventory>
extends Object
implements SkuInventoryAdjustmentService<I>
This component is responsible for reading, locking, and adjusting
SkuInventory
records,
as well as for creating hard and soft inventory reservations. This component is also responsible
for other types of InventoryTransactionType
s and for the adjustment of SkuInventory
records for those as well.- Author:
- Kelly Tisdell (ktisdell)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSkuInventoryAdjustmentService
(SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> skuInventoryRepository, InventoryTransactionService<InventoryTransaction> inventoryTransactionService, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager domainMapperManager, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, com.broadleafcommerce.common.extension.TypeFactory typeFactory, StockChangeNotificationService stockChangeNotificationService) -
Method Summary
Modifier and TypeMethodDescriptionprotected List<FulfillmentInventoryTransactionChangeRequest>
buildFutureInventoryTransactionChanges
(Map<String, List<InventoryTransaction>> inventoryTransactions, Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems) protected <T extends InventoryTransaction>
TbuildInventoryTransaction
(int quantity, InventoryTransactionType type, String reference, String skuInventoryId, String batchId, Instant dateProcessed) protected <T extends InventoryTransaction>
List<T>buildInventoryTransactionsForCurrentAndFutureStock
(@NonNull SkuInventoryAdjustmentDTO adjustmentDTO, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds inventory transactions for current and future stock reservations.protected SkuInventoryAdjustmentDTO
buildSkuInventoryAdjustmentDTO
(@NonNull SkuInventory inventory, InventoryTransaction softTransaction, @NonNull Integer quantityRequested, @NonNull String referenceNumber, @NonNull String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected int
calculateQuantityAvailable
(SkuInventory inventory) Deprecated.cancelInventory
(Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryAdjustmentRequestItems, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform the cancel of inventory to remove reserved quantity.protected <T extends InventoryTransaction>
List<T>convertFutureReservationToHardReservation
(@NonNull SkuInventoryAdjustmentDTO adjustmentDTO, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point extension method.convertSkuInventoryFromPersistentDomain
(Iterable<com.broadleafcommerce.data.tracking.core.Trackable> iterable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected InventoryTransaction
createCancelledTransaction
(@NonNull SkuInventory inventory, int quantity, @NonNull String referenceNumber, @NonNull String batchId) Builds a cancelledInventoryTransaction
and adjusts theSkuInventory
quantities.protected InventoryTransaction
createFulfilledTransaction
(@NonNull SkuInventory inventory, int quantity, @NonNull String referenceNumber, @NonNull String batchId) Builds a fulfilledInventoryTransaction
and adjusts theSkuInventory
quantities.protected <T extends InventoryTransaction>
List<T>createHardReservation
(@NonNull SkuInventoryAdjustmentDTO adjustmentDTO, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hard inventory reservation.protected InventoryTransaction
createHardReservation
(@NonNull SkuInventory inventory, InventoryTransaction softTransaction, @NonNull Integer quantityRequested, @NonNull String referenceNumber, @NonNull String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.deprecated in favor ofcreateHardReservation(SkuInventoryAdjustmentDTO, ContextInfo)
createHardReservations
(Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.createHardReservations
(Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, String requestId, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hard reservations that represent final inventory reservations.protected InventoryTransaction
createOrUpdateInventoryTransaction
(InventoryTransaction inventoryTransaction, InventoryTransaction existingSoftReservation, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an inventory transaction, or update an existing transaction if a previous soft transaction existsprotected <T extends InventoryTransaction>
List<T>createOrUpdateInventoryTransactions
(List<T> inventoryTransactions, T existingReservation, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an inventory transaction, or update an existing transaction if a previous transaction existsprotected InventoryTransaction
createReturnedTransaction
(@NonNull SkuInventory inventory, int quantity, @NonNull String referenceNumber, @NonNull String batchId) Builds a returnedInventoryTransaction
and adjusts theSkuInventory
quantities.protected InventoryTransaction
createSoftReservation
(@NonNull SkuInventory inventory, @NonNull Integer quantityRequested, @NonNull String referenceNumber, @NonNull String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Soft inventory reservation.createSoftReservations
(Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Soft reservations that represent temporary inventory reservations.createSoftReservations
(Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, Map<String, List<InventoryTransaction>> existingSoftReservationsByReference, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Soft reservations that represent temporary inventory reservations.protected void
deleteInventoryTransaction
(InventoryTransaction transaction, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Convenience method for deleting (archiving) an inventory transaction.protected boolean
protected InventoryTransaction
freeSoftReservationQuantity
(InventoryTransaction softReservation, SkuInventory skuInventory) Adjusts the SKU inventory quantities to reflect a soft inventory reservation being released (back to the available pool).void
freeSoftReservations
(List<InventoryTransaction> softReservations, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Release soft reservations and add back to on-hand quantity.fulfillInventory
(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryAdjustmentRequestItems, @NonNull String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform the fulfillment of inventory to remove reserved quantity and decrement on-hand quantity.protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager
protected Map<String,
List<InventoryTransaction>> getExistingReservationsByReferences
(List<String> referenceNumbers, Set<String> transactionTypesToRead, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected InventoryTransactionService<InventoryTransaction>
int
getQuantityAvailableWithoutPreviousReservationQuantity
(@NonNull SkuInventory inventory, @NonNull Integer softReservedQty) protected com.broadleafcommerce.common.messaging.notification.DetachedDurableMessageSender
protected Comparator<SkuInventory>
protected SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected StockChangeNotificationService
protected com.broadleafcommerce.common.extension.TypeFactory
protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager
protected boolean
handlePreExistingHardOrFutureReservationTransactions
(Map<String, List<InventoryTransaction>> originalReferenceTransactionMap, List<InventoryTransaction> out, List<InventoryTransaction> existingReservationsForItem, SkuInventory inventoryToDecrement, SkuInventoryAdjustmentRequestItem item, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles converting future reservations to hard reservations or finding pre-exising hard reservations for the provided item reference.protected boolean
hasExistingReservations
(List<InventoryTransaction> transactions) protected InventoryUnavailableException
inventoryUnavailableException
(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, InventoryTransactionType transactionType, String reason) protected void
notifyIfFutureStockReserved
(Map<String, List<InventoryTransaction>> inventoryTransactions, Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, String requestId, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Map<String,
List<InventoryTransaction>> readExistingTransactionsForItemByType
(SkuInventoryAdjustmentRequestItem item, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) readOptionalSkuInventory
(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected I
readSkuInventory
(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) returnInventory
(Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryAdjustmentRequestItems, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform the return of inventory to add back on-hand quantity.protected List<InventoryTransaction>
saveInventoryTransactions
(List<InventoryTransaction> transactions, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) saveSkuInventories
(Collection<I> inventories, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected <T extends InventoryTransaction>
voidsendAssignReferenceNumberForFutureInventoryMessage
(Map<String, List<InventoryTransaction>> inventoryTransactions, Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, String requestId, String batchId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) void
setSender
(com.broadleafcommerce.common.messaging.notification.DetachedDurableMessageSender sender) protected int
sumQuantityForTransactionType
(Map<String, List<InventoryTransaction>> transactionsByType, InventoryTransactionType type) protected void
throwUnavailableInventoryException
(@NonNull SkuInventoryAdjustmentDTO adjustmentDTO, int softReservedQty, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<InventoryTransaction>
updateInventoryTransactions
(List<com.broadleafcommerce.data.tracking.core.service.Update<InventoryTransaction>> transactions, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected <T extends InventoryTransaction>
TupdatePreviousReservationTransaction
(T existingReservation, @NonNull SkuInventory inventory, @NonNull Integer quantityRequested, @NonNull String transactionType, @NonNull String batchId) protected void
updateSkuInventoryQuantityReservation
(@NonNull SkuInventory inventory, @NonNull Integer quantityRequested) protected List<com.broadleafcommerce.data.tracking.core.service.Update<InventoryTransaction>>
updateSoftReservationTransactionAndInventory
(@NonNull List<InventoryTransaction> inventoryTransactions, @NonNull Map<String, I> refreshedInventories, @NonNull SkuInventoryAdjustmentRequestItem item) protected List<com.broadleafcommerce.data.tracking.core.service.Update<InventoryTransaction>>
updateSoftReservationTransactionAndInventory
(List<InventoryTransaction> inventoryTransactions, SkuInventory refreshedInventory, SkuInventoryAdjustmentRequestItem item) Deprecated.protected void
validateCanCancelInventory
(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
validateCanFulfillInventory
(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
validateExistingFutureStockReservations
(@NonNull SkuInventoryAdjustmentRequestItem item, @NonNull SkuInventory skuInventory, @NonNull List<InventoryTransaction> existingTransactions) protected boolean
validateExistingHardReservations
(@NonNull SkuInventoryAdjustmentRequestItem item, @NonNull List<InventoryTransaction> existingTransactions) Validates that there is not an existingInventoryTransactions
that isDefaultInventoryTransactionType.HARD_RESERVED
for the givenSkuInventoryAdjustmentRequestItem
.protected void
validateSufficientQuantityReservedForItemAdjustment
(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, Map<String, List<InventoryTransaction>> existingTransactionsByType, InventoryTransactionType transactionType)
-
Constructor Details
-
DefaultSkuInventoryAdjustmentService
public DefaultSkuInventoryAdjustmentService(SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> skuInventoryRepository, InventoryTransactionService<InventoryTransaction> inventoryTransactionService, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager domainMapperManager, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, com.broadleafcommerce.common.extension.TypeFactory typeFactory, StockChangeNotificationService stockChangeNotificationService)
-
-
Method Details
-
createSoftReservations
public List<InventoryTransaction> createSoftReservations(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableExceptionDescription copied from interface:SkuInventoryAdjustmentService
Soft reservations that represent temporary inventory reservations.- Specified by:
createSoftReservations
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
skuInventoryReservationRequestItems
- - the key to the map is theSkuInventory
that needs to be updated (pre-determined outside of this method).batchId
- identifier for the current batch of items updating inventorycontextInfo
- the context around sandboxing and multitenant state- Returns:
- the created inventory transactions
- Throws:
InventoryUnavailableException
- if there was insufficient inventory to be reserved
-
getExistingReservationsByReferences
-
createSoftReservations
public List<InventoryTransaction> createSoftReservations(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, Map<String, throws InventoryUnavailableExceptionList<InventoryTransaction>> existingSoftReservationsByReference, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryAdjustmentService
Soft reservations that represent temporary inventory reservations.- Specified by:
createSoftReservations
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
skuInventoryReservationRequestItems
- - the key to the map is theSkuInventory
that needs to be updated (pre-determined outside of this method).existingSoftReservationsByReference
- the existing soft reservations grouped by reference numberbatchId
- identifier for the current batch of items updating inventorycontextInfo
- the context around sandboxing and multitenant state- Returns:
- the created inventory transactions
- Throws:
InventoryUnavailableException
- if there was insufficient inventory to be reserved
-
updateSoftReservationTransactionAndInventory
@Deprecated protected List<com.broadleafcommerce.data.tracking.core.service.Update<InventoryTransaction>> updateSoftReservationTransactionAndInventory(List<InventoryTransaction> inventoryTransactions, SkuInventory refreshedInventory, SkuInventoryAdjustmentRequestItem item) throws InventoryUnavailableException Deprecated.- Throws:
InventoryUnavailableException
-
updateSoftReservationTransactionAndInventory
protected List<com.broadleafcommerce.data.tracking.core.service.Update<InventoryTransaction>> updateSoftReservationTransactionAndInventory(@NonNull @NonNull List<InventoryTransaction> inventoryTransactions, @NonNull @NonNull Map<String, I> refreshedInventories, @NonNull @NonNull SkuInventoryAdjustmentRequestItem item) throws InventoryUnavailableException- Throws:
InventoryUnavailableException
-
createHardReservations
@Deprecated(forRemoval=true, since="2.1.0") public List<InventoryTransaction> createHardReservations(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableExceptionDeprecated, for removal: This API element is subject to removal in a future version.- Specified by:
createHardReservations
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Throws:
InventoryUnavailableException
-
createHardReservations
public List<InventoryTransaction> createHardReservations(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, @NonNull String requestId, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableExceptionDescription copied from interface:SkuInventoryAdjustmentService
Hard reservations that represent final inventory reservations.- Specified by:
createHardReservations
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
skuInventoryReservationRequestItems
- - the key to the map is theSkuInventory
that needs to be updated (pre-determined outside of this method).batchId
- identifier for the current batch of items updating inventorycontextInfo
- the context around sandboxing and multitenant state- Returns:
- the created inventory transactions
- Throws:
InventoryUnavailableException
- if there was insufficient inventory to be reserved
-
handlePreExistingHardOrFutureReservationTransactions
protected boolean handlePreExistingHardOrFutureReservationTransactions(@NonNull Map<String, List<InventoryTransaction>> originalReferenceTransactionMap, @NonNull List<InventoryTransaction> out, @NonNull List<InventoryTransaction> existingReservationsForItem, @NonNull SkuInventory inventoryToDecrement, @NonNull SkuInventoryAdjustmentRequestItem item, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles converting future reservations to hard reservations or finding pre-exising hard reservations for the provided item reference.- Parameters:
originalReferenceTransactionMap
- a mapping of original item reference numbers to new transactionsout
- the inventory transactions computed for this requestexistingReservationsForItem
- the pre-exising transactions for the item based on referenceinventoryToDecrement
- the inventory record to updateitem
- theSkuInventoryAdjustmentRequestItem
being processedbatchId
- the batch ID for this requestcontextInfo
- the context around sandboxing and multitenant state- Returns:
- true, if a future or hard pre-exising transaction handled this request
-
notifyIfFutureStockReserved
protected void notifyIfFutureStockReserved(@NonNull Map<String, List<InventoryTransaction>> inventoryTransactions, @NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, @NonNull String requestId, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
hasExistingReservations
-
validateExistingHardReservations
protected boolean validateExistingHardReservations(@NonNull @NonNull SkuInventoryAdjustmentRequestItem item, @NonNull @NonNull List<InventoryTransaction> existingTransactions) Validates that there is not an existingInventoryTransactions
that isDefaultInventoryTransactionType.HARD_RESERVED
for the givenSkuInventoryAdjustmentRequestItem
.- Parameters:
item
- theSkuInventoryAdjustmentRequestItem
to validate forexistingTransactions
- the existingInventoryTransactions
- Throws:
IllegalArgumentException
- if there is already aDefaultInventoryTransactionType.HARD_RESERVED
-
validateExistingFutureStockReservations
protected boolean validateExistingFutureStockReservations(@NonNull @NonNull SkuInventoryAdjustmentRequestItem item, @NonNull @NonNull SkuInventory skuInventory, @NonNull @NonNull List<InventoryTransaction> existingTransactions) -
createSoftReservation
protected InventoryTransaction createSoftReservation(@NonNull @NonNull SkuInventory inventory, @NonNull @NonNull Integer quantityRequested, @NonNull @NonNull String referenceNumber, @NonNull @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException Soft inventory reservation. This also appropriately adjusts the inventory record passed in. This method, by default, does not save anything. Rather, it allows the calling method to handle that to allow for situations where a single SkuInventory may be adjusted more than once in a single call. That can happen, for example, when a PICKUP and a SHIP reservation for the same item are being requested for the same inventory. As a result, this method does the adjustment to the SkuInventory record and persists the associated InventoryTransaction.- Parameters:
inventory
-quantityRequested
-referenceNumber
-batchId
-contextInfo
-- Returns:
- Throws:
InventoryUnavailableException
-
updateSkuInventoryQuantityReservation
protected void updateSkuInventoryQuantityReservation(@NonNull @NonNull SkuInventory inventory, @NonNull @NonNull Integer quantityRequested) throws InventoryUnavailableException - Throws:
InventoryUnavailableException
-
getQuantityAvailableWithoutPreviousReservationQuantity
public int getQuantityAvailableWithoutPreviousReservationQuantity(@NonNull @NonNull SkuInventory inventory, @NonNull @NonNull Integer softReservedQty) -
buildInventoryTransaction
protected <T extends InventoryTransaction> T buildInventoryTransaction(int quantity, InventoryTransactionType type, String reference, String skuInventoryId, String batchId, Instant dateProcessed) -
convertFutureReservationToHardReservation
protected <T extends InventoryTransaction> List<T> convertFutureReservationToHardReservation(@NonNull @NonNull SkuInventoryAdjustmentDTO adjustmentDTO, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point extension method. Can override this to add custom logic for converting future stock reservation to a hard reservation.- Parameters:
adjustmentDTO
- the details needed to create adjustments to inventory reservationscontextInfo
- the context around sandboxing and multitenant state- Returns:
- the list of future or hard inventory transactions for this request
-
createHardReservation
@Deprecated(forRemoval=true, since="2.1.0") protected InventoryTransaction createHardReservation(@NonNull @NonNull SkuInventory inventory, @Nullable InventoryTransaction softTransaction, @NonNull @NonNull Integer quantityRequested, @NonNull @NonNull String referenceNumber, @NonNull @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException Deprecated, for removal: This API element is subject to removal in a future version.deprecated in favor ofcreateHardReservation(SkuInventoryAdjustmentDTO, ContextInfo)
- Throws:
InventoryUnavailableException
-
createHardReservation
protected <T extends InventoryTransaction> List<T> createHardReservation(@NonNull @NonNull SkuInventoryAdjustmentDTO adjustmentDTO, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException Hard inventory reservation. If an associated soft reservation is found, this method converts it to a hard reservation. Otherwise, this method decrements quantity available and increments quantity reserved and creates a new InventoryTransaction with a transaction type of "HARD_RESERVED". In this case, the providedSkuInventory
argument is a hint or an option in case a SOFT reservation was not completed or in case it expired and has been rolled back. The logic is as follows: 1. Look upInventoryTransaction
s based on the referenceNumber andInventoryTransactionType
.
2. If a HARD reservation exists, throw an exception
3. If a SOFT reservation exists, then look up theSkuInventory
record associated with the SOFT transaction, decrement inventory, and create a HARD reservation.
4. If a SOFT reservation does not exist, then decrement inventory as if it was a soft reservation, and create a HARD reservation
TheSkuInventory
record provided as an argument is a hint. If a SOFT reservation exists, then we want to use the SkuInventory that is already soft reserved (which may be the same). However, if a soft record does not exist, then we try to use the providedSkuInventory
record.- Parameters:
inventory
- - The inventory that should be adjustedsoftTransaction
- - existing soft inventory reservation that will be converted to a hard reservationquantityRequested
- - Quantity to reserve - Must be greater than 0referenceNumber
- - Arbitrary, unique reference number - usually Fulfillment Group Item ReferencebatchId
- - arbitrary batch ID (typically to identify a logical transaction)contextInfo
-- Returns:
- A single entry Map keyed by the
SkuInventory
that should be persisted and the associatedInventoryTransaction
- Throws:
InventoryUnavailableException
-
buildInventoryTransactionsForCurrentAndFutureStock
protected <T extends InventoryTransaction> List<T> buildInventoryTransactionsForCurrentAndFutureStock(@NonNull @NonNull SkuInventoryAdjustmentDTO adjustmentDTO, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds inventory transactions for current and future stock reservations. If stock is available now, a HARD transaction reservation will be created. If stock is available in the future, a FUTURE transaction reservation will be created, which can be converted to a HARD reservation when the stock becomes available. There can be multiple transactions from this method when the item requires both HARD & FUTURE reservations across its quantity.- Parameters:
adjustmentDTO
- theSkuInventoryAdjustmentDTO
containing the details needed to reserve and adjust inventory recordscontextInfo
- the context around sandboxing and multitenant state- Returns:
- the list of created
InventoryTransactions
for this request
-
updatePreviousReservationTransaction
protected <T extends InventoryTransaction> T updatePreviousReservationTransaction(@NonNull T existingReservation, @NonNull @NonNull SkuInventory inventory, @NonNull @NonNull Integer quantityRequested, @NonNull @NonNull String transactionType, @NonNull @NonNull String batchId) -
createOrUpdateInventoryTransactions
protected <T extends InventoryTransaction> List<T> createOrUpdateInventoryTransactions(List<T> inventoryTransactions, @Nullable T existingReservation, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an inventory transaction, or update an existing transaction if a previous transaction exists- Parameters:
inventoryTransactions
- inventory transaction to be created or updatedexistingReservation
- existing inventory reservation to be converted to a hard reservationcontextInfo
- context info- Returns:
- the created or updated inventory transaction
-
createOrUpdateInventoryTransaction
protected InventoryTransaction createOrUpdateInventoryTransaction(InventoryTransaction inventoryTransaction, @Nullable InventoryTransaction existingSoftReservation, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an inventory transaction, or update an existing transaction if a previous soft transaction exists- Parameters:
inventoryTransaction
- inventory transaction to be created or updatedexistingSoftReservation
- existing soft inventory reservation to be converted to a hard reservationcontextInfo
- context info- Returns:
- the created or updated inventory transaction
-
sendAssignReferenceNumberForFutureInventoryMessage
protected <T extends InventoryTransaction> void sendAssignReferenceNumberForFutureInventoryMessage(@NonNull Map<String, List<InventoryTransaction>> inventoryTransactions, @NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems, @NonNull String requestId, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
buildFutureInventoryTransactionChanges
protected List<FulfillmentInventoryTransactionChangeRequest> buildFutureInventoryTransactionChanges(Map<String, List<InventoryTransaction>> inventoryTransactions, @NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryReservationRequestItems) -
fulfillInventory
public List<InventoryTransaction> fulfillInventory(@NonNull @NonNull @NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryAdjustmentRequestItems, @NonNull @NonNull @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException, InventoryNotReservedExceptionDescription copied from interface:SkuInventoryAdjustmentService
Perform the fulfillment of inventory to remove reserved quantity and decrement on-hand quantity.- Specified by:
fulfillInventory
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
skuInventoryAdjustmentRequestItems
- - the key to the map is theSkuInventory
that needs to be updated (pre-determined outside of this method).batchId
- identifier for the current batch of items updating inventorycontextInfo
- the context around sandboxing and multitenant state- Returns:
- the created inventory transactions
- Throws:
InventoryUnavailableException
- if there was insufficient inventory reserved or on handInventoryNotReservedException
- if there were not already hard reservations for these inventory items
-
validateCanFulfillInventory
protected void validateCanFulfillInventory(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException, InventoryNotReservedException -
createFulfilledTransaction
protected InventoryTransaction createFulfilledTransaction(@NonNull @NonNull SkuInventory inventory, int quantity, @NonNull @NonNull String referenceNumber, @NonNull @NonNull String batchId) Builds a fulfilledInventoryTransaction
and adjusts theSkuInventory
quantities.- Parameters:
inventory
- the inventory being fulfilledquantity
- the quantity being fulfilledreferenceNumber
- the reference number of the item fulfilling inventorybatchId
- identifier for the current batch of items updating inventory- Returns:
- the inventory transaction for this fulfilled item quantity
-
cancelInventory
public List<InventoryTransaction> cancelInventory(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryAdjustmentRequestItems, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException, InventoryNotReservedExceptionDescription copied from interface:SkuInventoryAdjustmentService
Perform the cancel of inventory to remove reserved quantity.- Specified by:
cancelInventory
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
skuInventoryAdjustmentRequestItems
- - the key to the map is theSkuInventory
that needs to be updated (pre-determined outside of this method).batchId
- identifier for the current batch of items updating inventorycontextInfo
- the context around sandboxing and multitenant state- Returns:
- the created inventory transactions
- Throws:
InventoryUnavailableException
- if there was insufficient inventory reservedInventoryNotReservedException
- if there were not already hard reservations for these inventory items
-
freeSoftReservations
public void freeSoftReservations(@NonNull List<InventoryTransaction> softReservations, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryAdjustmentService
Release soft reservations and add back to on-hand quantity. Note that this archives the soft reservation in-place, no new inventory transactions are created.- Specified by:
freeSoftReservations
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
softReservations
- the soft reservations to freecontextInfo
- the context around sandboxing and multitenant state
-
freeSoftReservationQuantity
protected InventoryTransaction freeSoftReservationQuantity(@NonNull InventoryTransaction softReservation, @NonNull SkuInventory skuInventory) Adjusts the SKU inventory quantities to reflect a soft inventory reservation being released (back to the available pool).- Parameters:
softReservation
- the soft reservation to releaseskuInventory
- the SKU inventory to adjust the quantities of (will be mutated)- Returns:
- the soft reservation
-
validateCanCancelInventory
protected void validateCanCancelInventory(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException, InventoryNotReservedException -
createCancelledTransaction
protected InventoryTransaction createCancelledTransaction(@NonNull @NonNull SkuInventory inventory, int quantity, @NonNull @NonNull String referenceNumber, @NonNull @NonNull String batchId) Builds a cancelledInventoryTransaction
and adjusts theSkuInventory
quantities.- Parameters:
inventory
- the inventory being cancelledquantity
- the quantity being cancelledreferenceNumber
- the reference number of the item cancelling inventorybatchId
- identifier for the current batch of items updating inventory- Returns:
- the inventory transaction for this cancelled item quantity
-
readExistingTransactionsForItemByType
protected Map<String,List<InventoryTransaction>> readExistingTransactionsForItemByType(SkuInventoryAdjustmentRequestItem item, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
validateSufficientQuantityReservedForItemAdjustment
protected void validateSufficientQuantityReservedForItemAdjustment(SkuInventory inventory, SkuInventoryAdjustmentRequestItem item, Map<String, List<InventoryTransaction>> existingTransactionsByType, InventoryTransactionType transactionType) throws InventoryUnavailableException, InventoryNotReservedException -
sumQuantityForTransactionType
protected int sumQuantityForTransactionType(Map<String, List<InventoryTransaction>> transactionsByType, InventoryTransactionType type) -
calculateQuantityAvailable
Deprecated.in favor ofSkuInventory.updateQuantityAvailable()
-
returnInventory
public List<InventoryTransaction> returnInventory(@NonNull Map<I, List<SkuInventoryAdjustmentRequestItem>> skuInventoryAdjustmentRequestItems, @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryAdjustmentService
Perform the return of inventory to add back on-hand quantity.- Specified by:
returnInventory
in interfaceSkuInventoryAdjustmentService<I extends SkuInventory>
- Parameters:
skuInventoryAdjustmentRequestItems
- - the key to the map is theSkuInventory
that needs to be updated (pre-determined outside of this method).batchId
- identifier for the current batch of items updating inventorycontextInfo
- the context around sandboxing and multitenant state- Returns:
- the created inventory transactions
-
createReturnedTransaction
protected InventoryTransaction createReturnedTransaction(@NonNull @NonNull SkuInventory inventory, int quantity, @NonNull @NonNull String referenceNumber, @NonNull @NonNull String batchId) Builds a returnedInventoryTransaction
and adjusts theSkuInventory
quantities.- Parameters:
inventory
- the inventory being returnedquantity
- the quantity being returnedreferenceNumber
- the reference number of the item returning inventorybatchId
- identifier for the current batch of items returning inventory- Returns:
- the inventory transaction for this returned item quantity
-
readSkuInventory
-
readOptionalSkuInventory
-
saveSkuInventories
protected List<I> saveSkuInventories(@NonNull Collection<I> inventories, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
saveInventoryTransactions
protected List<InventoryTransaction> saveInventoryTransactions(@NonNull List<InventoryTransaction> transactions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
updateInventoryTransactions
protected List<InventoryTransaction> updateInventoryTransactions(@NonNull List<com.broadleafcommerce.data.tracking.core.service.Update<InventoryTransaction>> transactions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
deleteInventoryTransaction
protected void deleteInventoryTransaction(@NonNull InventoryTransaction transaction, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Convenience method for deleting (archiving) an inventory transaction.- Parameters:
transaction
- the transaction to deletecontextInfo
- the context in which to delete in
-
getSkuInventoryComparator
-
convertSkuInventoryFromPersistentDomain
-
buildSkuInventoryAdjustmentDTO
protected SkuInventoryAdjustmentDTO buildSkuInventoryAdjustmentDTO(@NonNull @NonNull SkuInventory inventory, @Nullable InventoryTransaction softTransaction, @NonNull @NonNull Integer quantityRequested, @NonNull @NonNull String referenceNumber, @NonNull @NonNull String batchId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
doesSkuInventoryHaveUnlimitedFutureStock
-
getInventoryReservationTypes
-
getSkuInventoryRepository
@NonNull protected SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> getSkuInventoryRepository() -
getInventoryTransactionService
@NonNull protected InventoryTransactionService<InventoryTransaction> getInventoryTransactionService() -
getStockChangeNotificationService
-
getDomainMapperManager
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager getDomainMapperManager() -
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator() -
getTypeFactory
@NonNull protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getSender
protected com.broadleafcommerce.common.messaging.notification.DetachedDurableMessageSender getSender() -
setSender
@Autowired public void setSender(com.broadleafcommerce.common.messaging.notification.DetachedDurableMessageSender sender)
-
SkuInventory.updateQuantityAvailable()