Class PriceDataImportBatchHandler
java.lang.Object
com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
com.broadleafcommerce.pricing.dataimport.PriceDataImportBatchHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("pricing")
public class PriceDataImportBatchHandler
extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
- Author:
- Vitalii Voronkov (vvoronkov)
-
Constructor Summary
ConstructorDescriptionPriceDataImportBatchHandler
(PriceDataConverter priceDataConverter, PriceDataService<PriceData> priceDataService, PriceListService<PriceList> priceListService, com.broadleafcommerce.common.extension.TypeFactory pricingFactory, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData>
buildPersistenceRequest
(String requestedPriceDataTargetKey, org.apache.commons.lang3.tuple.Pair<PriceData, com.broadleafcommerce.common.dataimport.messaging.BatchRecord> requestedPriceDataAndBatchRecord, Map<String, PriceData> existingPriceDataByTargetKey) Determines id, operation type and builds thePersistenceRequest
for thePriceData
.buildPersistenceRequests
(String priceListId, Map<String, org.apache.commons.lang3.tuple.Pair<PriceData, com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> requestedPriceDataByTargetKey, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Builds the list ofPersistenceRequest
for thePriceData
.boolean
canHandle
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected Map<String,
org.apache.commons.lang3.tuple.Pair<PriceData, com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> convertBatchRecords
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, String priceListId) Converts all of the batch records in the batch request to price data.convertToPriceData
(com.broadleafcommerce.common.dataimport.messaging.BatchRecord priceDataRecord, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) getExistingPriceDataByTargetKey
(List<com.broadleafcommerce.pricing.client.domain.PriceableTargetRef> priceableTargetRefs, String priceListId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected com.broadleafcommerce.common.dataimport.util.IdResolver
protected static String[]
protected com.broadleafcommerce.common.dataimport.util.OperationResolver
protected static String
protected PriceDataConverter
protected PriceDataService<PriceData>
com.broadleafcommerce.common.extension.TypeFactory
protected static String
protected static String
protected String
getTargetKey
(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target) protected String
getTargetKey
(String targetType, String targetId, String targetVendorRef) protected String
getTargetKey
(Map<String, String> row, String vendorRef) com.broadleafcommerce.common.dataimport.messaging.BatchCompletion
handle
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) void
initializeContextForBatch
(@NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) The main change in the implementation for price data is to read thePriceList
the data goes into and set theCurrencyContext
to match to ensure that the prices are deserialized with the correct currency.protected void
persistPersistenceRequests
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData>> priceDataRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) Perform a persist of the parsed out domain specified asPersistenceRequest
s and adds persistence result toallCompletions
protected void
setIdResolver
(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) protected void
setOperationResolver
(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver) 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, persist, persist, removeAndReturnFieldErrorsUnderPath, setBatchContextHelper, setImportContextConfigurationProperties
-
Constructor Details
-
PriceDataImportBatchHandler
public PriceDataImportBatchHandler(PriceDataConverter priceDataConverter, PriceDataService<PriceData> priceDataService, PriceListService<PriceList> priceListService, com.broadleafcommerce.common.extension.TypeFactory pricingFactory, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
-
Method Details
-
initializeContextForBatch
public void initializeContextForBatch(@NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) The main change in the implementation for price data is to read thePriceList
the data goes into and set theCurrencyContext
to match to ensure that the prices are deserialized with the correct currency.- Specified by:
initializeContextForBatch
in interfacecom.broadleafcommerce.common.dataimport.ImportBatchHandler
- Overrides:
initializeContextForBatch
in classcom.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
- Parameters:
batch
- The batch to be processed.- Throws:
IllegalArgumentException
- if no price list id found atBatchRequest.BatchContext.getParentEntityId()
.com.broadleafcommerce.data.tracking.core.exception.EntityMissingException
- if noPriceList
found matching theBatchRequest.BatchContext.getParentEntityId()
-
handle
public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
convertBatchRecords
protected Map<String,org.apache.commons.lang3.tuple.Pair<PriceData, convertBatchRecordscom.broadleafcommerce.common.dataimport.messaging.BatchRecord>> (com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, String priceListId) Converts all of the batch records in the batch request to price data.If conversion fails for a record, a
BatchCompletionRecord
will be created for it and added toerroredCompletions
, and it will not appear in the converted result.If multiple batch records are attempting to import the same price data, all but the first will be considered errored. A
BatchCompletionRecord
will be created for the duplicates and added toerroredCompletions
, and they will not appear in the converted result.- Parameters:
batch
- the original record batcherroredCompletions
- the list to which any errored completion records should be addedpriceListId
- the id of the parent price list- Returns:
- a map of the converted
PriceData
and originalBatchRecord
pairs grouped by target key value
-
persistPersistenceRequests
protected void persistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData>> priceDataRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) Perform a persist of the parsed out domain specified asPersistenceRequest
s and adds persistence result toallCompletions
- Parameters:
batch
- the original record batchpriceDataRequests
- a list of the price data persistence requestsallCompletions
- the list to which the completion records should be added
-
getDataRouteKey
-
getTargetKey
-
getTargetKey
protected String getTargetKey(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target) -
getTargetKey
-
convertToPriceData
-
buildPersistenceRequests
protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData>> buildPersistenceRequests(String priceListId, Map<String, org.apache.commons.lang3.tuple.Pair<PriceData, com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> requestedPriceDataByTargetKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Builds the list ofPersistenceRequest
for thePriceData
.This method will query the data-store for existing price data to determine whether each item should be an update or a create.
-
buildPersistenceRequest
protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData> buildPersistenceRequest(String requestedPriceDataTargetKey, org.apache.commons.lang3.tuple.Pair<PriceData, com.broadleafcommerce.common.dataimport.messaging.BatchRecord> requestedPriceDataAndBatchRecord, Map<String, PriceData> existingPriceDataByTargetKey) Determines id, operation type and builds thePersistenceRequest
for thePriceData
.- Parameters:
requestedPriceDataTargetKey
- the target key of the requested price datarequestedPriceDataAndBatchRecord
- the pair of requestedPriceData
andBatchRecord
existingPriceDataByTargetKey
- a map ofPriceData
that already exist in the data store, with the target key as the map key- Returns:
- the
PersistenceRequest
for thePriceData
-
getExistingPriceDataByTargetKey
-
canHandle
public boolean canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
getIMPORT_TYPES
-
getTARGET_TYPE
-
getTARGET_ID
-
getPRICE_DATA_IMPORTED_ERROR
-
getPriceDataConverter
-
getPriceDataService
-
getPriceListService
-
getPricingFactory
public com.broadleafcommerce.common.extension.TypeFactory getPricingFactory() -
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)
-