Class PriceDataBatchItemHandler<T extends Prices>
java.lang.Object
com.broadleafcommerce.dataexchange.service.AbstractBatchItemHandler<T1,T2>
com.broadleafcommerce.dataexchange.service.product.ProductRelatedBatchItemHandler<ComprehensiveProduct,T>
com.broadleafcommerce.dataexchange.service.product.PriceDataBatchItemHandler<T>
- Type Parameters:
T-
- All Implemented Interfaces:
BatchItemHandler<ComprehensiveProduct,T>
public class PriceDataBatchItemHandler<T extends Prices>
extends ProductRelatedBatchItemHandler<ComprehensiveProduct,T>
Handles the processing of price data for a product. This works a little different from typical
handlers in that we process all price data associated with a price list rather than a single
price data object. The reason for this is we treat the
Prices object as all price data
for a given price list. This informs the handler on how to update all price data for a product
and given price list.
For example, if there are 4 existing price data for a product, but the request only contains 1 price data, we will delete the other 3 price data.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringPrice data that needs to be created is stored in the batch properties under this key.protected static final StringIDs of price data that need to be deleted are stored in the batch properties under this key.static final StringExisting price data fetched at the beginning of the batch process.protected static final StringKey used to store the existing price data for the product currently being handled.protected static final StringSaved price data is stored in the batch properties under this key.protected static final StringPrice data that needs to be updated is stored in the batch properties under this key. -
Constructor Summary
ConstructorsConstructorDescriptionPriceDataBatchItemHandler(PriceProvider<PriceData> priceProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected CompletableFuture<Void>applyHandle(HandlerArgs<ComprehensiveProduct, T> args, org.springframework.core.task.AsyncTaskExecutor executor, org.springframework.retry.support.RetryTemplate retryTemplate, CompletableFuture<Void> result) Create a completable future that will apply the handle method.booleancanHandle(ExchangeObject exchangeObject) Determines if this handler can handle the given exchange object.protected <R> RgetDataFromProps(String key, Map<String, Object> batchProperties) getExistingPriceData(Map<String, Object> batchProperties) getPriceDataToCreate(Map<String, Object> batchProperties) getPriceDataToDelete(Map<String, Object> batchProperties) getPriceDataToUpdate(Map<String, Object> batchProperties) handle(HandlerArgs<ComprehensiveProduct, T> args) Perform the necessary actions on the item in the batch.protected CompletableFuture<Void>protected CompletableFuture<Void>protected CompletableFuture<Void>protected voidinitPricesList(ComprehensiveProduct product) Add the given price data to the list of saved price data for the product.This method is called after the item has been saved.preHandle(HandlerArgs<ComprehensiveProduct, T> handlerArgs) Perform any necessary actions before the item is handled (e.g.protected voidprepareCreatesAndUpdates(List<PriceData> prices, Map<String, Object> batchProperties, List<PriceData> existingPriceData) protected Tprotected voidprepareDeletes(List<PriceData> prices, Map<String, Object> batchProperties, List<PriceData> existingPriceData) Methods inherited from class com.broadleafcommerce.dataexchange.service.AbstractBatchItemHandler
applyPostOperations, buildTranslationMap, createFutureInternal, execute, execute, execute, execute, getSavedTopLevel, getTypeFactory, isNewlyCreatedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.dataexchange.service.BatchItemHandler
completedFuture, createCompletableFuture, createCompletableFuture, createSupplementalFutures, handleCreate, handleDelete, handleUpdate, populateCorrelationId, retryableRunnable, retryableSupplier, shouldAbort
-
Field Details
-
EXISTING_PRICE_DATA_KEY
Existing price data fetched at the beginning of the batch process. Available on the batch context. Will be in aMap<String, Map<String, List<PriceData>>. The key is the price data target. The value is a map of price data for the product, keyed by the price list id. SeeDefaultPriceDataPreloadProcessor- See Also:
-
SAVED_PRICE_DATA_KEY
Saved price data is stored in the batch properties under this key.- See Also:
-
DELETE_PRICE_DATA_KEY
IDs of price data that need to be deleted are stored in the batch properties under this key. Will be aSet<String>.- See Also:
-
CREATE_PRICE_DATA_KEY
Price data that needs to be created is stored in the batch properties under this key.- See Also:
-
UPDATE_PRICE_DATA_KEY
Price data that needs to be updated is stored in the batch properties under this key.- See Also:
-
LOCAL_PRICE_DATA_KEY
Key used to store the existing price data for the product currently being handled. Will be aList<PriceData>.- See Also:
-
-
Constructor Details
-
PriceDataBatchItemHandler
public PriceDataBatchItemHandler(PriceProvider<PriceData> priceProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
preHandle
Description copied from interface:BatchItemHandlerPerform any necessary actions before the item is handled (e.g. fetching data, determining save/delete, etc.).- Parameters:
handlerArgs- The handler arguments- Returns:
- A runnable that will be executed before the item is handled. If no action is necessary, returns null.
-
canHandle
Description copied from interface:BatchItemHandlerDetermines if this handler can handle the given exchange object.- Parameters:
exchangeObject- the exchange object- Returns:
- true if this handler can handle the exchange object, false otherwise
-
applyHandle
protected CompletableFuture<Void> applyHandle(HandlerArgs<ComprehensiveProduct, T> args, org.springframework.core.task.AsyncTaskExecutor executor, org.springframework.retry.support.RetryTemplate retryTemplate, CompletableFuture<Void> result) Description copied from class:AbstractBatchItemHandlerCreate a completable future that will apply the handle method. If performing more complex operations that require multiple steps that need to be executed, this is most likely the method that should be overridden.- Overrides:
applyHandlein classAbstractBatchItemHandler<ComprehensiveProduct,T extends Prices> - Parameters:
args- the handler argumentsexecutor- the executor to run the completable futureretryTemplate- the retry template to useresult- the completable future to apply the handle method to- Returns:
- the completable future
-
handle
Description copied from interface:BatchItemHandlerPerform the necessary actions on the item in the batch. Accepts an instance ofHandlerArgsand returns the handled item, which is then passed toBatchItemHandler.postHandle(HandlerArgs).- Returns:
- A function that accepts an instance of
HandlerArgs. If no further handling is necessary, this method or the supplier may return null.
-
postHandle
Description copied from interface:BatchItemHandlerThis method is called after the item has been saved. Any items that should be done after the item is saved should be done here. At minimum, the implementation should set the savedItem result on the parent. At this point, the item is considered "done" and no high risk operations (e.g. API calls) should be done here.- Parameters:
args- the handler arguments. Returns null if no action is necessary.
-
handleCreates
-
handleDeletes
-
handleUpdates
-
prepareDeletes
-
prepareDeleteAll
-
prepareCreatesAndUpdates
-
getExistingPriceData
-
initPricesList
Add the given price data to the list of saved price data for the product. -
getPriceDataToUpdate
-
getPriceDataToDelete
-
getPriceDataToCreate
-
getDataFromProps
-