Class DataDrivenEnumBatchLoaderProcessor
java.lang.Object
com.broadleafcommerce.dataexchange.service.catalog.DataDrivenEnumBatchLoaderProcessor
- All Implemented Interfaces:
BatchExtensionProcessor,org.springframework.core.Ordered
Loads data driven enums from the catalog service. Handles out of box data driven enums as well as
custom data driven enums defined in properties. Required IDs of the data driven enums are
populated on the products. If the values are for some reason needed elsewhere, they can be
accessed from the batch context via the attribute
FETCHED_DATA_DRIVEN_ENUMS and will be
of type DataDrivenEnumResponse.
This may be overridden just like any Broadleaf implementation, but also supports custom mappings that may be configured via property.
See CustomDataDriveEnumProperties for instructions on how to define custom data driven
enums.
-
Field Summary
FieldsFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionDataDrivenEnumBatchLoaderProcessor(CatalogProvider<ComprehensiveProduct, Variant> catalogProvider, CustomDataDriveEnumProperties properties, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCustomDataDriveEnumFilters(DataDrivenEnumRequestFilters filters, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) protected Optional<DataDrivenEnum>addNotFoundException(String type, String requestValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) protected voidaddStandardDataDriveEnumFilters(DataDrivenEnumRequestFilters filters, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Handles adding OOB data driven enums that will be used in a request to the catalog service.booleanMethod to determine if this handler should execute.protected voidfetchDataDrivenEnums(BatchContext<ComprehensiveProduct> batchContext) protected CatalogProvider<ComprehensiveProduct,Variant> protected List<DataDrivenEnum>getCustomDataDrivenEnums(ComprehensiveProduct product, String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping, BatchContext<ComprehensiveProduct> batchContext) Returns the data driven enum(s) for a custom field.protected com.fasterxml.jackson.databind.ObjectMapperintgetOrder()protected CustomDataDriveEnumPropertiesprotected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanisValid(DataDrivenEnum dataDrivenEnum) Return true if the DataDrivenEnum supplied on the request has enough information to resolve the value from the catalog service.protected List<DataDrivenEnum>mapCollectionCustomDataDrivenEnum(String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping, Object customValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Maps a collection of custom data driven enums.protected DataDrivenEnummapCustomDataDrivenEnum(String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping, Object customValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Attempts to map any custom data driven enums.protected voidpopulateAndValidateDataDrivenEnums(DataDrivenEnumResponse response, BatchContext<ComprehensiveProduct> batchContext) Populates data driven enums on the supplied product to be used when persisting the products later in the product create/update flow.protected voidpopulateCustomDataDriveEnums(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) protected voidpopulateCustomDataDrivenEnum(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext, String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping) protected voidpopulateCustomDataDrivenEnumCollection(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext, String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping) protected voidpopulateStandardDataDriveEnums(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) voidpreProcess(BatchContext<?> batchContext) This method will be executed to allow customers to fetch, for example, data that is required for future processing.protected Optional<DataDrivenEnum>tryFindEnumById(DataDrivenEnumResponse response, org.apache.commons.lang3.tuple.Pair<String, String> type, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext, DataDrivenEnum requestValue) Try to resolve the enum by ID.protected booleanvalidateAndAddFilter(org.apache.commons.lang3.tuple.Pair<String, String> type, DataDrivenEnum enumValue, DataDrivenEnumRequestFilters filters, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Adds a data driven enum to the filters if it is valid.protected booleanvalidateSuppliedDataDrivenEnum(org.apache.commons.lang3.tuple.Pair<String, String> type, DataDrivenEnum enumValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Validates that the supplied data driven enum is valid.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.dataexchange.service.BatchExtensionProcessor
postProcess
-
Field Details
-
FETCHED_DATA_DRIVEN_ENUMS
- See Also:
-
MERCHANDISING_TYPE
-
BRAND
-
TARGET_DEMOGRAPHIC
-
-
Constructor Details
-
DataDrivenEnumBatchLoaderProcessor
public DataDrivenEnumBatchLoaderProcessor(CatalogProvider<ComprehensiveProduct, Variant> catalogProvider, CustomDataDriveEnumProperties properties, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
canHandle
Description copied from interface:BatchExtensionProcessorMethod to determine if this handler should execute.- Specified by:
canHandlein interfaceBatchExtensionProcessor- Returns:
-
preProcess
Description copied from interface:BatchExtensionProcessorThis method will be executed to allow customers to fetch, for example, data that is required for future processing. This is good in situations where you want to pre-fetch or batch fetch and pre-cache data for use within this batch context. Generally, implementors should save any results that they want to save and use later inBatchContext#getAdditionalProperties(). This method is called only ifBatchExtensionProcessor.canHandle(Class)returns true. It is executed inAbstractDataExchangeService.saveAll(List, ContextInfo)afterAbstractDataExchangeService.split(List, BatchContext)and beforeAbstractDataExchangeService.aggregate(BatchContext).- Specified by:
preProcessin interfaceBatchExtensionProcessor
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceBatchExtensionProcessor- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
fetchDataDrivenEnums
-
addCustomDataDriveEnumFilters
protected void addCustomDataDriveEnumFilters(DataDrivenEnumRequestFilters filters, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) -
getCustomDataDrivenEnums
@Nullable protected List<DataDrivenEnum> getCustomDataDrivenEnums(ComprehensiveProduct product, String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping, BatchContext<ComprehensiveProduct> batchContext) Returns the data driven enum(s) for a custom field. If the value is not present on the product, null is returned. If the mapping is a collection, the returned list may have multiple values. If it is not, the returned list will have a single value.- Parameters:
product- The product.fieldName- The field name of the custom data driven enum.mapping- The mapping for the custom data driven enum.batchContext- The batch context.- Returns:
- A list of DataDrivenEnum objects.
-
mapCollectionCustomDataDrivenEnum
@Nullable protected List<DataDrivenEnum> mapCollectionCustomDataDrivenEnum(String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping, Object customValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Maps a collection of custom data driven enums. This will attempt to convert each value in the collection to a DataDrivenEnum object. If the value is non-null and the conversion fails, an exception is registered with the batch context for the product.- Parameters:
fieldName- The field name of the custom data driven enum.mapping- The mapping for the custom data driven enum.customValue- The value of the custom data driven enum. This should either be a Collection or an array.product- The product.batchContext- The batch context.- Returns:
- The mapped DataDrivenEnum objects, or null if the value was unable to be mapped.
-
mapCustomDataDrivenEnum
@Nullable protected DataDrivenEnum mapCustomDataDrivenEnum(String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping, Object customValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Attempts to map any custom data driven enums. This will attempt to convert the custom value to a DataDrivenEnum object. If the value is non-null and the conversion fails, an exception is registered with the batch context for the product.- Parameters:
fieldName- The field name of the custom data driven enum.mapping- The mapping for the custom data driven enum.customValue- The value of the custom data driven enum.product- The product.batchContext- The batch context.- Returns:
- The mapped DataDrivenEnum object, or null if the value was unable to be mapped.
-
populateAndValidateDataDrivenEnums
protected void populateAndValidateDataDrivenEnums(DataDrivenEnumResponse response, BatchContext<ComprehensiveProduct> batchContext) Populates data driven enums on the supplied product to be used when persisting the products later in the product create/update flow. If a data driven enum was not found, an exception is registered with the batch context for that product.- Parameters:
response- the response from the catalog servicebatchContext- the batch context
-
populateCustomDataDriveEnums
protected void populateCustomDataDriveEnums(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) -
populateCustomDataDrivenEnum
protected void populateCustomDataDrivenEnum(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext, String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping) -
populateCustomDataDrivenEnumCollection
protected void populateCustomDataDrivenEnumCollection(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext, String fieldName, CustomDataDriveEnumProperties.DataDrivenEnumMapping mapping) -
populateStandardDataDriveEnums
protected void populateStandardDataDriveEnums(DataDrivenEnumResponse response, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) -
tryFindEnumById
protected Optional<DataDrivenEnum> tryFindEnumById(DataDrivenEnumResponse response, org.apache.commons.lang3.tuple.Pair<String, String> type, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext, DataDrivenEnum requestValue) Try to resolve the enum by ID. This is called if, on the request, we do not have a name for the enum but do have an ID. If no value is found, an exception is added to the batch context for the supplied product.- Parameters:
response- The response from the catalog service.type- The type of the data driven enum. Left: The type of the enum (e.g. "BRAND", "MERCHANDISING_TYPE"). Right: the field name on the product.product- The productbatchContext- The batch contextrequestValue- The value supplied on the request- Returns:
-
addNotFoundException
protected Optional<DataDrivenEnum> addNotFoundException(String type, String requestValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) -
addStandardDataDriveEnumFilters
protected void addStandardDataDriveEnumFilters(DataDrivenEnumRequestFilters filters, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Handles adding OOB data driven enums that will be used in a request to the catalog service.- Parameters:
filters- The filters object.product- The productbatchContext- The batch context.
-
validateAndAddFilter
protected boolean validateAndAddFilter(org.apache.commons.lang3.tuple.Pair<String, String> type, DataDrivenEnum enumValue, DataDrivenEnumRequestFilters filters, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Adds a data driven enum to the filters if it is valid. Invalid values generally indicate that we don't have enough data to resolve the enum. If the value is invalid, an exception is added to the batch context for the product.- Parameters:
type- the type of the data driven enum (e.g. "MERCHANDISING_TYPE")enumValue- the data driven enum value received on the requestfilters- the filters to add the data driven enum toproduct- the product to validate the data driven enum againstbatchContext- the batch context- Returns:
- true if the supplied enum value was valid and added to the filters, false otherwise
-
validateSuppliedDataDrivenEnum
protected boolean validateSuppliedDataDrivenEnum(org.apache.commons.lang3.tuple.Pair<String, String> type, DataDrivenEnum enumValue, ComprehensiveProduct product, BatchContext<ComprehensiveProduct> batchContext) Validates that the supplied data driven enum is valid.- Parameters:
type- the type of the data driven enum. Left: The type of the enum (e.g. "BRAND", "MERCHANDISING_TYPE"). Right: the field name on the product.enumValue- the data driven enum value received on the requestproduct- the product associated with the data driven enumbatchContext- the batch context- Returns:
- true if the supplied data driven enum is valid, false otherwise
-
isValid
Return true if the DataDrivenEnum supplied on the request has enough information to resolve the value from the catalog service.- Parameters:
dataDrivenEnum- The value to validate.- Returns:
- true if valid, else false.
-
getCatalogProvider
-
getProperties
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-