Class DefaultSkuInventoryService<I extends SkuInventory>
- Type Parameters:
I-
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<I>,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<I>,SkuInventoryService<I>
SkuInventory. This is not a typical CRUD
service because it involves multiple access to repositories in a single JPA transaction.- Author:
- Kelly Tisdell (ktisdell)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSkuInventoryService(SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> skuInventoryRepository, InventoryLocationService<InventoryLocation> inventoryLocationService, SkuFieldReferenceTypeUtility skuFieldReferenceTypeUtility, SkuInventoryAdjustmentService<I> skuInventoryAdjustmentService, SkuInventoryAvailabilityStrategy<I> skuInventoryAvailabilityStrategy, StockChangeNotificationService stockChangeNotificationService, SkuInventoryReservationRequestValidator skuInventoryReservationRequestValidator, InventoryTransactionService<InventoryTransaction> inventoryTransactionService, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager domainMapperManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I>buildBulkResponseOfFailures(List<com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse.PersistenceFailure<I>> validationFailures) protected ReleaseSkuInventoryReservationResponsebuildReleaseReservationResponse(@NonNull ReleaseSkuInventoryReservationRequest releaseRequest, @NonNull List<InventoryTransaction> reservationsFound, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aReleaseSkuInventoryReservationResponserepresenting the result of releasing reservations.protected StringbuildSerializedSku(String skuRef, SkuInventory skuInventory) cancelInventory(SkuInventoryAdjustmentRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Performs theDefaultInventoryTransactionType.CANCELLEDInventoryTransactionsto updateSkuInventoryfor fulfilled items.createAll(List<I> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I>createAllAllowingPartialSuccess(List<I> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) createSkuInventoryReservations(SkuInventoryReservationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates HARD or a SOFT Inventory Reservations.voidvoiddeleteAllByInventoryLocationId(String inventoryLocationId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deletes all theSkuInventoryfor the specified inventory location idprotected intprotected StringdetermineSkuRefValue(SkuReferenceFieldType skuReferenceFieldType, I skuInventory, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Map<I,List<SkuInventoryAdjustmentRequestItem>> divideRequestItemsBySkuInventory(SkuInventoryAdjustmentRequest request, InventoryTransactionType latestExistingTransactionType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) booleanexistsByInventoryLocationAndSkuRefFieldValues(String inventoryLocationId, Optional<String> skuContextId, Optional<String> externalId, Optional<String> skuCode, Optional<String> upc, Optional<String> ean, Optional<String> gtin, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Determines is aSkuInventoryrecord exists in a given location, based onSkuReffields.booleanexistsByParentSkuInventoryId(@NonNull String parentSkuInventoryId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Determines if anySkuInventoryrecords exist with the givenSkuInventory.getParentSkuInventoryId().org.springframework.data.domain.Page<I>findAllByInventoryLocationContextId(String inventoryLocationId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all Sku Inventories for the specified inventory location id matching the given filters.fulfillInventory(SkuInventoryAdjustmentRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Performs theDefaultInventoryTransactionType.FULFILLEDInventoryTransactionsto updateSkuInventoryfor fulfilled items.getAlreadyReservedSkuInventories(SkuInventoryReservationRequestGroup group, Map<String, List<InventoryTransaction>> existingSoftReservationsByReference, Map<String, Integer> nonReservedRequestedQuantitiesBySkuReference, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads theSkuInventoryrecords for the reservation request items which already have existing soft reservations.getAvailableSkuInventories(SkuInventoryReservationRequestGroup group, SkuReferenceFieldType fieldType, Map<String, Integer> totalRequestedQuantitiesBySkuReference, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManagerprotected Map<String,List<InventoryTransaction>> getExistingSoftReservationsByReferences(SkuInventoryReservationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getInventoryIdsForReferenceNumbersBasedOnExistingTransactions(List<SkuInventoryAdjustmentRequestItem> items, InventoryTransactionType latestExistingTransactionType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieves theSKU Inventory IDfor the items'reference numbersbased on existing transactions of typelatestExistingTransactionType.protected InventoryLocationService<InventoryLocation>protected InventoryTransactionService<InventoryTransaction>protected SkuFieldReferenceTypeUtilityprotected SkuInventoryAdjustmentService<I>protected SkuInventoryAvailabilityStrategy<I>getSkuInventoryAvailabilityStrategy(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Allows for context-specific selection of a strategy for finding inventory availability for browsing and reservation.protected SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected SkuInventoryReservationRequestValidatorprotected StockChangeNotificationServiceprotected com.broadleafcommerce.common.extension.TypeFactoryprotected Comparator<com.broadleafcommerce.data.tracking.core.service.Update<I>>Provides aComparatorfor sortingUpdateinstances.protected booleanisSerialized(String skuReferenceValue) Determines whether the item being adjusted has a serialized sku inventory objectprotected voidnotifyStockChangeForCreate(I created, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Notifies stock change after creating aSkuInventory.protected voidnotifyStockChangeForDelete(I deleted, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Notifies stock change after deleting aSkuInventory.protected voidpostProcessSkuInventoryCreation(I created, @NonNull Optional<I> maybeParent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform any additional handling after aSkuInventoryhas been created.protected voidpostProcessSkuInventoryDeletion(I deleted, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform any additional handling after aSkuInventoryhas been deleted.readAll(Optional<cz.jirutka.rsql.parser.ast.Node> filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generally used for batch export, this allows a caller to query, filter, and stream paged results.readAllByInventoryLocationId(String inventoryLocationId, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all Sku Inventories for the specified inventory location id matching the given filters.org.springframework.data.domain.Page<I>readAllByName(String nameQuery, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all Inventory Locations, optionally filtered by name or number.readByInventoryLocationAndSkuRefFieldValues(String inventoryLocationId, Optional<String> externalId, Optional<String> skuCode, Optional<String> upc, Optional<String> ean, Optional<String> gtin, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads a (unique)SkuInventoryrecord for a given location, based onSkuReffields.readByInventoryLocationAndSkuRefFieldValuesAndNotSerialized(String inventoryLocationId, Optional<String> externalId, Optional<String> skuCode, Optional<String> upc, Optional<String> ean, Optional<String> gtin, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads a (unique) non-serializedSkuInventoryrecord for a given location, based onSkuReffields.readByParentSkuInventoryIdAndSerializationValue(@NonNull String parentSkuInventoryId, @NonNull String serializationValue, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads a (unique)SkuInventoryrecord for a parent sku inventory id and serialization value.readSkuInventoryDetails(SkuReferenceFieldType skuRefType, Set<String> skuRefs, InventoryLocation location, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) ReadsSkuInventorydetails based on specificSkuRefdetails, specified by theSkuReferenceFieldTypefor a givenInventoryLocation.releaseSkuInventoryReservations(@NonNull ReleaseSkuInventoryReservationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Releases inventory reservations based on the givenReleaseSkuInventoryReservationRequest.replace(String id, I businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I>replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected InventoryReservationRequestTypeprotected SkuInventoryFulfillmentTypeTakes a String value and resolves it to an instance ofSkuInventoryFulfillmentType.returnInventory(SkuInventoryAdjustmentRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Performs theDefaultInventoryTransactionType.RETURNEDInventoryTransactionsto updateSkuInventoryfor returned items.voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) update(String id, I businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) updateAll(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> updates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I>updateAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> updates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidupdateHasChildrenFlagIfSerializedInventoryExists(I inventory, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Sets theSkuInventory.hasChildren()flag if a child inventory exists.protected voidupdateParentHasChildrenFlag(I inventory, @NonNull Optional<I> maybeParent, boolean hasChildrenFlagToSet, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Sets theSkuInventory.hasChildren()flag for the parent if the givenSkuInventoryis serialized.protected IupdateSerializedInventorySkuRefBasedOnParent(I businessInstance, I parent) Updates theSkuInventory.getSkuRef()of a serialized inventory based on its parent.updateSort(com.broadleafcommerce.data.tracking.core.sort.SortPositionRequest sortPositionRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected List<com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse.PersistenceFailure<I>>validateAllSkuInventoryModifications(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> changes, List<com.broadleafcommerce.data.tracking.core.service.Update<I>> successfullyValidated, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean useReplaceSemantics) protected voidvalidateAllSkuInventoryModificationsAndThrowIfError(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> changes, List<com.broadleafcommerce.data.tracking.core.service.Update<I>> successfullyValidated, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean useReplaceSemantics) validateExpectedInventoryTransactionsExist(List<SkuInventoryAdjustmentRequestItem> items, List<InventoryTransaction> inventoryTransactions, InventoryTransactionType transactionType) Validates that all expected inventory transactions exist based on the originalitem list.protected voidvalidateHasNoChildrenBeforeDeletion(I toDelete, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that theSkuInventorybeing deleted has no children.protected voidvalidateSingleSkuInventoryModifications(I current, I changed, boolean useReplaceSemantics) protected voidvalidateSkuInventoryModifications(I current, I changed, org.springframework.validation.Errors errors, boolean useReplaceSemantics) Perform any validations onchangedwith consideration to the current state incurrent.protected voidvalidateSufficientAvailableInventory(List<I> availableSkuInventories, Map<String, Integer> totalRequestedQuantitiesBySkuReference, SkuReferenceFieldType skuReferenceFieldType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAllMethods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, getHelper, getRepository, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, setSortPositionStrategyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
readAll, readAll, readAll, readAllByContextId, readByContextId
-
Constructor Details
-
DefaultSkuInventoryService
public DefaultSkuInventoryService(SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> skuInventoryRepository, InventoryLocationService<InventoryLocation> inventoryLocationService, SkuFieldReferenceTypeUtility skuFieldReferenceTypeUtility, SkuInventoryAdjustmentService<I> skuInventoryAdjustmentService, SkuInventoryAvailabilityStrategy<I> skuInventoryAvailabilityStrategy, StockChangeNotificationService stockChangeNotificationService, SkuInventoryReservationRequestValidator skuInventoryReservationRequestValidator, InventoryTransactionService<InventoryTransaction> inventoryTransactionService, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager domainMapperManager)
-
-
Method Details
-
readAllByName
public org.springframework.data.domain.Page<I> readAllByName(@Nullable String nameQuery, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceRead all Inventory Locations, optionally filtered by name or number.- Specified by:
readAllByNamein interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
nameQuery- (optional) the name to filter byfilters- additional filters to apply in the query, can be nullpage- the requested page of results from the databasecontext- context information surrounding sandboxing and multitenant state- Returns:
- all SkuInventory, optionally filtered by name
-
findAllByInventoryLocationContextId
public org.springframework.data.domain.Page<I> findAllByInventoryLocationContextId(String inventoryLocationId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceRead all Sku Inventories for the specified inventory location id matching the given filters. Read all Inventory Locations,- Specified by:
findAllByInventoryLocationContextIdin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
inventoryLocationId- the inventory location idfilters- additional filters to apply in the query, can be nullpage- the requested page of results from the databasecontext- context information surrounding sandboxing and multitenant state- Returns:
- the Sku Inventories for the specified inventory location id
-
readAllByInventoryLocationId
public Stream<I> readAllByInventoryLocationId(String inventoryLocationId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceRead all Sku Inventories for the specified inventory location id matching the given filters.- Specified by:
readAllByInventoryLocationIdin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
inventoryLocationId- the inventory location idfilters- additional filters to apply in the query, can be nullcontext- context information surrounding sandboxing and multitenant state- Returns:
- the Sku Inventories for the specified inventory location id
-
deleteAllByInventoryLocationId
public void deleteAllByInventoryLocationId(String inventoryLocationId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryServiceDeletes all theSkuInventoryfor the specified inventory location id- Specified by:
deleteAllByInventoryLocationIdin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
inventoryLocationId- the inventory location idcontextInfo- context information surrounding sandboxing and multitenant state
-
readByInventoryLocationAndSkuRefFieldValues
public Optional<I> readByInventoryLocationAndSkuRefFieldValues(String inventoryLocationId, Optional<String> externalId, Optional<String> skuCode, Optional<String> upc, Optional<String> ean, Optional<String> gtin, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceReads a (unique)SkuInventoryrecord for a given location, based onSkuReffields.- Specified by:
readByInventoryLocationAndSkuRefFieldValuesin interfaceSkuInventoryService<I extends SkuInventory>- Returns:
-
readByInventoryLocationAndSkuRefFieldValuesAndNotSerialized
public Optional<I> readByInventoryLocationAndSkuRefFieldValuesAndNotSerialized(String inventoryLocationId, Optional<String> externalId, Optional<String> skuCode, Optional<String> upc, Optional<String> ean, Optional<String> gtin, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceReads a (unique) non-serializedSkuInventoryrecord for a given location, based onSkuReffields.Typically used for the validation to ensure that the parent of serialized inventories do not have duplicate sku reference.
- Specified by:
readByInventoryLocationAndSkuRefFieldValuesAndNotSerializedin interfaceSkuInventoryService<I extends SkuInventory>
-
existsByInventoryLocationAndSkuRefFieldValues
public boolean existsByInventoryLocationAndSkuRefFieldValues(String inventoryLocationId, Optional<String> skuContextId, Optional<String> externalId, Optional<String> skuCode, Optional<String> upc, Optional<String> ean, Optional<String> gtin, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceDetermines is aSkuInventoryrecord exists in a given location, based onSkuReffields.- Specified by:
existsByInventoryLocationAndSkuRefFieldValuesin interfaceSkuInventoryService<I extends SkuInventory>- Returns:
-
readByParentSkuInventoryIdAndSerializationValue
public Optional<I> readByParentSkuInventoryIdAndSerializationValue(@NonNull @NonNull String parentSkuInventoryId, @NonNull @NonNull String serializationValue, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceReads a (unique)SkuInventoryrecord for a parent sku inventory id and serialization value.- Specified by:
readByParentSkuInventoryIdAndSerializationValuein interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
parentSkuInventoryId- the parent sku inventory idserializationValue- the serialization valuecontext- context information surrounding sandboxing and multitenant state- Returns:
- a (unique)
SkuInventoryrecord for a given parent sku inventory id and serialization value.
-
existsByParentSkuInventoryId
public boolean existsByParentSkuInventoryId(@NonNull @NonNull String parentSkuInventoryId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceDetermines if anySkuInventoryrecords exist with the givenSkuInventory.getParentSkuInventoryId().- Specified by:
existsByParentSkuInventoryIdin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
parentSkuInventoryId- the parent sku inventory id to filter bycontext- context information surrounding sandboxing and multitenant state- Returns:
- true if any
SkuInventoryrecords exist with the givenSkuInventory.getParentSkuInventoryId(), otherwise false
-
createSkuInventoryReservations
public List<InventoryTransaction> createSkuInventoryReservations(@NonNull SkuInventoryReservationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException Description copied from interface:SkuInventoryServiceCreates HARD or a SOFT Inventory Reservations. This results in the creation of 1 or moreInventoryTransactionrecords. A SOFT inventory reservation is a temporary reservation that may be removed or rolled back after a period of time. A SOFT reservation typically results in decrementing quantityAvailable on theSkuInventoryrecord. These are typically created prior to payment processing. A HARD reservation makes the SOFT reservation permanent. These are typically created after payment processing. If a corresponding SOFT reservation does not exist, then the creation of a HARD reservation will attempt to decrement quantityAvailable as well. In this case, the process is similar to creating a SOFT reservation immediately followed by a HARD reservation.- Specified by:
createSkuInventoryReservationsin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
request-SkuInventoryReservationRequestto be processedcontextInfo- Context information around sandbox and multitenant state.- Returns:
- The
InventoryTransactionsresulting from processing therequest. - Throws:
InventoryUnavailableException- if inventory cannot be reserved or otherwise decremented
-
releaseSkuInventoryReservations
public ReleaseSkuInventoryReservationResponse releaseSkuInventoryReservations(@NonNull @NonNull ReleaseSkuInventoryReservationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryServiceReleases inventory reservations based on the givenReleaseSkuInventoryReservationRequest.By default, it only releases the soft reservations
- Specified by:
releaseSkuInventoryReservationsin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
request- theReleaseSkuInventoryReservationRequestcontaining details about the releasecontextInfo- context information around sandbox and multitenant state- Returns:
- a
ReleaseSkuInventoryReservationResponserepresents the result
-
buildReleaseReservationResponse
protected ReleaseSkuInventoryReservationResponse buildReleaseReservationResponse(@NonNull @NonNull ReleaseSkuInventoryReservationRequest releaseRequest, @NonNull @NonNull List<InventoryTransaction> reservationsFound, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aReleaseSkuInventoryReservationResponserepresenting the result of releasing reservations.By default it just returns a new
ReleaseSkuInventoryReservationResponsecontaining nothing, serves as a hookpoint for customization.- Parameters:
releaseRequest- the originalReleaseSkuInventoryReservationRequestreservationsFound- theInventoryTransactionsthat were found and releasedcontextInfo- the context around sandboxing and multitenant state- Returns:
- a
ReleaseSkuInventoryReservationResponserepresenting the result of releasing reservations
-
getExistingSoftReservationsByReferences
protected Map<String,List<InventoryTransaction>> getExistingSoftReservationsByReferences(SkuInventoryReservationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getAlreadyReservedSkuInventories
protected Set<I> getAlreadyReservedSkuInventories(SkuInventoryReservationRequestGroup group, Map<String, List<InventoryTransaction>> existingSoftReservationsByReference, Map<String, Integer> nonReservedRequestedQuantitiesBySkuReference, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads theSkuInventoryrecords for the reservation request items which already have existing soft reservations. Also updatesnonReservedRequestedQuantitiesBySkuReferenceto remove items and quantities which have already been fully soft-reserved.- Parameters:
group- the reservation request group to find already reserved inventories forexistingSoftReservationsByReference- the existing soft reservation transactions mapped by item reference numbernonReservedRequestedQuantitiesBySkuReference- all of the requested quantities for each sku reference, to have already-reserved quantities removedcontextInfo- context information surrounding sandboxing and multitenant state- Returns:
- the
SkuInventoryrecords for the reservation request which have existing soft reservations
-
getAvailableSkuInventories
protected List<I> getAvailableSkuInventories(SkuInventoryReservationRequestGroup group, SkuReferenceFieldType fieldType, Map<String, Integer> totalRequestedQuantitiesBySkuReference, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
fulfillInventory
public List<InventoryTransaction> fulfillInventory(@NonNull SkuInventoryAdjustmentRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException, InventoryNotReservedException Description copied from interface:SkuInventoryServicePerforms theDefaultInventoryTransactionType.FULFILLEDInventoryTransactionsto updateSkuInventoryfor fulfilled items.This transaction decrements the reserved and on-hand inventory for the requested items. This should only be performed after the items have already been
DefaultInventoryTransactionType.HARD_RESERVED.- Specified by:
fulfillInventoryin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
request- inventory adjustment to be processed as fulfilledcontextInfo- Context information around sandbox and multitenant state.- Returns:
- The
InventoryTransactionsresulting from processing therequest. - Throws:
InventoryUnavailableException- if inventory could not be decrementedInventoryNotReservedException- if inventory was not already reserved
-
cancelInventory
public List<InventoryTransaction> cancelInventory(@NonNull SkuInventoryAdjustmentRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException, InventoryNotReservedException Description copied from interface:SkuInventoryServicePerforms theDefaultInventoryTransactionType.CANCELLEDInventoryTransactionsto updateSkuInventoryfor fulfilled items.This transaction decrements the reserved inventory for the requested items. This should only be performed after the items have already been
DefaultInventoryTransactionType.HARD_RESERVED.- Specified by:
cancelInventoryin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
request- inventory adjustment to be processed as cancelledcontextInfo- Context information around sandbox and multitenant state.- Returns:
- The
InventoryTransactionsresulting from processing therequest. - Throws:
InventoryUnavailableException- if inventory could not be decrementedInventoryNotReservedException- if inventory was not already reserved
-
returnInventory
public List<InventoryTransaction> returnInventory(@NonNull SkuInventoryAdjustmentRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryServicePerforms theDefaultInventoryTransactionType.RETURNEDInventoryTransactionsto updateSkuInventoryfor returned items.This transaction increments the on-hand inventory for the requested items.
- Specified by:
returnInventoryin interfaceSkuInventoryService<I extends SkuInventory>- Parameters:
request- inventory adjustment to be processed as returnedcontextInfo- Context information around sandbox and multitenant state.- Returns:
- The
InventoryTransactionsresulting from processing therequest.
-
divideRequestItemsBySkuInventory
protected Map<I,List<SkuInventoryAdjustmentRequestItem>> divideRequestItemsBySkuInventory(@NonNull SkuInventoryAdjustmentRequest request, @NonNull InventoryTransactionType latestExistingTransactionType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getInventoryIdsForReferenceNumbersBasedOnExistingTransactions
protected org.springframework.util.MultiValueMap<String,String> getInventoryIdsForReferenceNumbersBasedOnExistingTransactions(List<SkuInventoryAdjustmentRequestItem> items, InventoryTransactionType latestExistingTransactionType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieves theSKU Inventory IDfor the items'reference numbersbased on existing transactions of typelatestExistingTransactionType.For example, if we are fulfilling inventory for items, we will look up the
DefaultInventoryTransactionType.HARD_RESERVEDtransactions for the items'reference numbersand return a map where the keys are the reference numbers and the values are the corresponding SKU Inventory IDs.- Parameters:
items- the items to find SKU inventory IDs forlatestExistingTransactionType- the expected latest existing transaction type, which we will look up to find the correct SKU inventory IDcontextInfo- context information surrounding sandboxing and multitenant state- Returns:
- a map where the keys are the reference numbers and the values are the corresponding SKU Inventory IDs
- Throws:
InventoryTransactionMissingException- if an expected inventory transaction does not exist.
-
validateExpectedInventoryTransactionsExist
protected Optional<String> validateExpectedInventoryTransactionsExist(List<SkuInventoryAdjustmentRequestItem> items, List<InventoryTransaction> inventoryTransactions, InventoryTransactionType transactionType) Validates that all expected inventory transactions exist based on the originalitem list. If these don't exist, an error string is returned indicating what went wrong.- Parameters:
items- The inventory adjustment items to check against.inventoryTransactions- The found inventory adjustments.transactionType- The transaction type (for error message purposes)- Returns:
- An optional with an error message string if not all expected transactions are found,
else
empty
-
determineExpectedReservationCount
-
isSerialized
Determines whether the item being adjusted has a serialized sku inventory object- Parameters:
skuReferenceValue- the sku value of the item- Returns:
- whether the item being adjusted has a serialized sku inventory object
-
determineSkuRefValue
protected String determineSkuRefValue(SkuReferenceFieldType skuReferenceFieldType, I skuInventory, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
buildSerializedSku
-
validateSufficientAvailableInventory
protected void validateSufficientAvailableInventory(List<I> availableSkuInventories, Map<String, Integer> totalRequestedQuantitiesBySkuReference, SkuReferenceFieldType skuReferenceFieldType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws InventoryUnavailableException- Throws:
InventoryUnavailableException
-
readSkuInventoryDetails
public List<I> readSkuInventoryDetails(SkuReferenceFieldType skuRefType, Set<String> skuRefs, InventoryLocation location, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:SkuInventoryServiceReadsSkuInventorydetails based on specificSkuRefdetails, specified by theSkuReferenceFieldTypefor a givenInventoryLocation.- Specified by:
readSkuInventoryDetailsin interfaceSkuInventoryService<I extends SkuInventory>- Returns:
-
readAll
public Stream<I> readAll(@NonNull Optional<cz.jirutka.rsql.parser.ast.Node> filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:SkuInventoryServiceGenerally used for batch export, this allows a caller to query, filter, and stream paged results.- Specified by:
readAllin interfaceSkuInventoryService<I extends SkuInventory>- Returns:
-
update
@Transactional("inventoryTransactionManager") public I update(String id, I businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
updatein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
updatein classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
updateAll
public List<I> updateAll(@NonNull List<com.broadleafcommerce.data.tracking.core.service.Update<I>> updates, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
updateAllin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
updateAllin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
updateAllAllowingPartialSuccess
public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I> updateAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> updates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
updateAllAllowingPartialSuccessin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
updateAllAllowingPartialSuccessin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
buildBulkResponseOfFailures
-
updateSort
@Transactional("inventoryTransactionManager") public I updateSort(com.broadleafcommerce.data.tracking.core.sort.SortPositionRequest sortPositionRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
updateSortin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
updateSortin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
replace
@Transactional("inventoryTransactionManager") public I replace(String id, I businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replacein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
replacein classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
replaceAll
@Transactional("inventoryTransactionManager") public List<I> replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replaceAllin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
replaceAllin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
replaceAllAllowingPartialSuccess
@Transactional("inventoryTransactionManager") public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I> replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replaceAllAllowingPartialSuccessin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
replaceAllAllowingPartialSuccessin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
validateAllSkuInventoryModificationsAndThrowIfError
protected void validateAllSkuInventoryModificationsAndThrowIfError(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> changes, List<com.broadleafcommerce.data.tracking.core.service.Update<I>> successfullyValidated, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean useReplaceSemantics) -
validateAllSkuInventoryModifications
protected List<com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse.PersistenceFailure<I>> validateAllSkuInventoryModifications(List<com.broadleafcommerce.data.tracking.core.service.Update<I>> changes, List<com.broadleafcommerce.data.tracking.core.service.Update<I>> successfullyValidated, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, boolean useReplaceSemantics) -
validateSingleSkuInventoryModifications
-
validateSkuInventoryModifications
protected void validateSkuInventoryModifications(@NonNull I current, @NonNull I changed, @NonNull org.springframework.validation.Errors errors, boolean useReplaceSemantics) Perform any validations onchangedwith consideration to the current state incurrent.- Parameters:
current- the entity instance as it exists in the data store nowchanged- the changed entity instance representing the update/replace that will be appliederrors- the errors object on which to register errorsuseReplaceSemantics- whether or not to consider null values inchangedas changed. If true, null values will be considered as changed. If false, null values will be considered as unchanged. This matters, since in operations likeCrudEntityService.update(String, Object, ContextInfo), a null field value will be ignored and not applied to the entity as a change. However, in operations likeCrudEntityService.replace(String, Object, ContextInfo), all values (null or not) are applied to the entity as a change. This hint enables proper validation behavior in each of these flows.
-
create
public I create(I businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
createin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
createin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
updateSerializedInventorySkuRefBasedOnParent
protected I updateSerializedInventorySkuRefBasedOnParent(@NonNull I businessInstance, @NonNull I parent) Updates theSkuInventory.getSkuRef()of a serialized inventory based on its parent. -
createAll
public List<I> createAll(List<I> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
createAllin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
createAllin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
createAllAllowingPartialSuccess
public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<I> createAllAllowingPartialSuccess(List<I> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
createAllAllowingPartialSuccessin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
createAllAllowingPartialSuccessin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
postProcessSkuInventoryCreation
protected void postProcessSkuInventoryCreation(@NonNull I created, @NonNull @NonNull Optional<I> maybeParent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform any additional handling after aSkuInventoryhas been created.By default, it and notifies stock change.
- Parameters:
created- the createdSkuInventorycontextInfo- context information surrounding sandboxing and multitenant state
-
updateParentHasChildrenFlag
protected void updateParentHasChildrenFlag(@NonNull I inventory, @NonNull @NonNull Optional<I> maybeParent, boolean hasChildrenFlagToSet, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Sets theSkuInventory.hasChildren()flag for the parent if the givenSkuInventoryis serialized.- Parameters:
inventory- theSkuInventoryto update the parent formaybeParent- the optional of already-fetched parentSkuInventoryhasChildrenFlagToSet- theSkuInventory.hasChildren()flag to setcontextInfo- context information surrounding sandboxing and multitenant state
-
updateHasChildrenFlagIfSerializedInventoryExists
protected void updateHasChildrenFlagIfSerializedInventoryExists(@NonNull I inventory, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Sets theSkuInventory.hasChildren()flag if a child inventory exists.- Parameters:
inventory- theSkuInventoryto check and update the flag forcontextInfo- context information surrounding sandboxing and multitenant state
-
notifyStockChangeForCreate
protected void notifyStockChangeForCreate(@NonNull I created, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Notifies stock change after creating aSkuInventory.- Parameters:
created- the createdSkuInventorycontextInfo- context information surrounding sandboxing and multitenant state
-
delete
- Specified by:
deletein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<I extends SkuInventory>- Overrides:
deletein classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<I extends SkuInventory>
-
validateHasNoChildrenBeforeDeletion
protected void validateHasNoChildrenBeforeDeletion(@NonNull I toDelete, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that theSkuInventorybeing deleted has no children.- Parameters:
toDelete- theSkuInventorybeing deletedcontextInfo- context information surrounding sandboxing and multitenant state- Throws:
UnsupportedOperationException- if there are still child inventories
-
postProcessSkuInventoryDeletion
protected void postProcessSkuInventoryDeletion(@NonNull I deleted, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform any additional handling after aSkuInventoryhas been deleted.- Parameters:
deleted- the deletedSkuInventorycontextInfo- context information surrounding sandboxing and multitenant state
-
notifyStockChangeForDelete
protected void notifyStockChangeForDelete(@NonNull I deleted, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Notifies stock change after deleting aSkuInventory.- Parameters:
deleted- the deletedSkuInventorycontextInfo- context information surrounding sandboxing and multitenant state
-
resolveInventoryReservationRequestType
-
getUpdateComparator
protected Comparator<com.broadleafcommerce.data.tracking.core.service.Update<I>> getUpdateComparator()Provides aComparatorfor sortingUpdateinstances. This is mostly used for updateAll and updateAllAllowingPartialSuccess. The default simply comparesUpdate.getId(), which is how queries are sorted that apply locks. This is to prevent deadlocking when updating these one at a time (e.g. in anIterator. This method allows someone to override the comparator, but this will generally be unnecessary.- Returns:
-
getSkuInventoryAvailabilityStrategy
protected SkuInventoryAvailabilityStrategy<I> getSkuInventoryAvailabilityStrategy(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Allows for context-specific selection of a strategy for finding inventory availability for browsing and reservation.- Parameters:
contextInfo-- Returns:
-
resolveSkuInventoryFulfillmentType
Takes a String value and resolves it to an instance ofSkuInventoryFulfillmentType.- Parameters:
value-- Returns:
-
getSkuInventoryRepository
@NonNull protected SkuInventoryRepository<com.broadleafcommerce.data.tracking.core.Trackable> getSkuInventoryRepository() -
getInventoryLocationService
-
getSkuInventoryAdjustmentService
-
getDomainMapperManager
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager getDomainMapperManager() -
getSkuFieldReferenceTypeUtility
-
getSkuInventoryReservationRequestValidator
@NonNull protected SkuInventoryReservationRequestValidator getSkuInventoryReservationRequestValidator() -
getStockChangeNotificationService
-
getInventoryTransactionService
@NonNull protected InventoryTransactionService<InventoryTransaction> getInventoryTransactionService() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-