Class SkuInventoryImportBatchHandler
java.lang.Object
com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
com.broadleafcommerce.inventory.dataimport.SkuInventoryImportBatchHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("inventory")
public class SkuInventoryImportBatchHandler
extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
- Author:
- Kelly Tisdell (ktisdell)
-
Constructor Summary
ConstructorsConstructorDescriptionSkuInventoryImportBatchHandler(SkuInventoryConverter skuInventoryConverter, SkuInventoryService<SkuInventory> skuInventoryService, SkuInventoryDefaultsInitializer skuInventoryDefaultsInitializer, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator) -
Method Summary
Modifier and TypeMethodDescriptionprotected SkuInventoryapplyUpdates(SkuInventory skuInventory, Optional<SkuInventory> existing) protected StringbuildKey(SkuInventory skuInventory, boolean update) protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SkuInventory>>buildPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions) Builds the list ofPersistenceRequestfor theSkuInventory.booleancanHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected com.broadleafcommerce.common.dataimport.util.IdResolverprotected com.broadleafcommerce.common.dataimport.util.OperationResolverprotected SkuInventoryConverterprotected SkuInventoryDefaultsInitializerprotected SkuInventoryService<SkuInventory>com.broadleafcommerce.common.dataimport.messaging.BatchCompletionhandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected voidhandleDuplicates(String key, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, Map<String, SkuInventoryPersistenceRequestHolder> skuInventoryMap) Handles any duplicates in the batch.protected SkuInventoryinitializeSkuInventory(String inventoryLocationId, com.broadleafcommerce.common.dataimport.messaging.BatchRecord skuInventoryRecord, SkuInventory convertedSkuInventory) Initializes the defaults on an existingSkuInventoryobject.protected voidpersistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SkuInventory>> skuInventories, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) Perform a persist of the parsed out domain specified asPersistenceRequests and adds persistence result toallCompletionsprotected Optional<SkuInventory>resolveExistingSkuInventory(String inventoryLocationId, SkuInventory skuInventory, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.data.tracking.core.type.OperationTyperesolveOperationType(com.broadleafcommerce.common.dataimport.messaging.BatchRecord skuInventoryRecord) Deprecated, for removal: This API element is subject to removal in a future version.this is not necessary.protected voidresolveSkuInventoryId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord skuInventoryRecord, SkuInventory skuInventory) Resolves and sets the id forSkuInventory.protected voidsetIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) protected voidsetOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver) protected voidsetVendorRefFromBatchContext(SkuInventory skuInventory, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext batchContext) Sets theSkuInventory.getVendorRef()fromBatchRequest.BatchContext.getVendorRef().Methods inherited from class com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
addFailedConversionCompletions, buildAndAddCompletionRecords, buildContextInfo, buildCreateContextInfo, buildNonValidationErrorCompletions, buildReadContextInfo, buildSuccessfulCompletionsForRequest, buildUpdateContextInfo, buildValidationErrorCompletions, failRecordAndDependentsEarly, finalizeContextForBatch, generateAndAddCompletions, generateAndAddCompletions, generateAndAddValidationErrorCompletions, getBatchContextHelper, getCompletionError, getFormattedEmbeddedValidationErrorString, getFormattedValidationErrorString, getHydrator, getImportContextConfigurationProperties, getImportContextProperties, initializeContextForBatch, persist, persist, removeAndReturnFieldErrorsUnderPath, setBatchContextHelper, setImportContextConfigurationProperties
-
Constructor Details
-
SkuInventoryImportBatchHandler
public SkuInventoryImportBatchHandler(SkuInventoryConverter skuInventoryConverter, SkuInventoryService<SkuInventory> skuInventoryService, SkuInventoryDefaultsInitializer skuInventoryDefaultsInitializer, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
-
Method Details
-
canHandle
public boolean canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
handle
public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
buildPersistenceRequests
protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SkuInventory>> buildPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions) Builds the list ofPersistenceRequestfor theSkuInventory. In case error during conversion, adds failed conversion response to theerroredCompletions, otherwise creates and adds the persistence request to the result.- Parameters:
batch- the original record batcherroredCompletions- the list to which any errored completion records should be added- Returns:
- the list of
PersistenceRequestfor theSkuInventory
-
handleDuplicates
protected void handleDuplicates(String key, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, Map<String, SkuInventoryPersistenceRequestHolder> skuInventoryMap) Handles any duplicates in the batch.- Parameters:
key-erroredCompletions-skuInventoryMap-
-
buildKey
-
applyUpdates
-
resolveOperationType
@Deprecated(forRemoval=true, since="1.7.8") protected com.broadleafcommerce.data.tracking.core.type.OperationType resolveOperationType(com.broadleafcommerce.common.dataimport.messaging.BatchRecord skuInventoryRecord) Deprecated, for removal: This API element is subject to removal in a future version.this is not necessary. We can determine the OperationType based on whether a matching skuInventory exists in the datastore for the skuInventoryLocationResolves operation type for the sku inventory record.- Parameters:
skuInventoryRecord- the record representsSkuInventoryfrom file- Returns:
- type for a change operation
- See Also:
-
initializeSkuInventory
protected SkuInventory initializeSkuInventory(String inventoryLocationId, com.broadleafcommerce.common.dataimport.messaging.BatchRecord skuInventoryRecord, SkuInventory convertedSkuInventory) Initializes the defaults on an existingSkuInventoryobject.- Parameters:
inventoryLocationId- the id of the parent inventory locationskuInventoryRecord- the record representsSkuInventoryfrom fileconvertedSkuInventory- the results of performing the conversion- Returns:
- instance of
SkuInventorywith populated properties
-
setVendorRefFromBatchContext
protected void setVendorRefFromBatchContext(SkuInventory skuInventory, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext batchContext) Sets theSkuInventory.getVendorRef()fromBatchRequest.BatchContext.getVendorRef().This is important, as it ensures all changes will only occur within the import's defined vendor (or not in a vendor, if null).
- ensures any vendorRef value provided for the row within the file is ignored and only the pre-validated vendorRef is used
- if a row is trying to update a record that currently exists in a different vendor, this
will cause the update payload to have a different vendor and will fail the vendor-ref
immutability validation in
DefaultSkuInventoryService. This guarantees the change will fail. - if the specified parent inventory location belongs to a different vendor, the validation
in
SkuInventoryValidatorwill fail and the row will be rejected
- Parameters:
skuInventory- aSkuInventoryinstance converted from a row in a filebatchContext- the batch context provided for the import
-
resolveSkuInventoryId
protected void resolveSkuInventoryId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord skuInventoryRecord, SkuInventory skuInventory) Resolves and sets the id forSkuInventory.- Parameters:
skuInventoryRecord- the record representsSkuInventoryfrom fileskuInventory- theSkuInventoryfor which the id should be resolved
-
resolveExistingSkuInventory
protected Optional<SkuInventory> resolveExistingSkuInventory(String inventoryLocationId, SkuInventory skuInventory, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
persistPersistenceRequests
protected void persistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<SkuInventory>> skuInventories, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) Perform a persist of the parsed out domain specified asPersistenceRequests and adds persistence result toallCompletions- Parameters:
batch- the original record batchskuInventories- a list of the sku inventory persistence requestsallCompletions- a list to which the completion records should be added
-
getDataRouteKey
-
getSkuInventoryConverter
-
getSkuInventoryService
-
getSkuInventoryDefaultsInitializer
-
getIdResolver
protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver() -
setIdResolver
protected void setIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) -
getOperationResolver
protected com.broadleafcommerce.common.dataimport.util.OperationResolver getOperationResolver() -
setOperationResolver
protected void setOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver)
-