Class CompleteProductImportBatchHandler
java.lang.Object
com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
com.broadleafcommerce.catalog.dataimport.CompleteProductImportBatchHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("catalog")
public class CompleteProductImportBatchHandler
extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
This is the handler intended to process batches for imports matching the
CompleteProductImportSpecification
in the import service.
This is typically intended to create full new products and variants (and related entities) in the datastore.
This component does support 'updates' on existing entities, but only for simple use-cases. Consumers with more complex update use-cases should opt to create separate specifications/batch-handlers for those purposes.
- Author:
- Kelly Tisdell (ktisdell)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
-
Constructor Summary
ConstructorDescriptionCompleteProductImportBatchHandler
(ProductRowConverter productConverter, CategoryProductColumnConverter categoryProductColumnConverter, ProductImageColumnConverter productImageColumnConverter, VariantRowConverter variantConverter, CatalogTranslationColumnConverter catalogTranslationColumnConverter, ProductService<Product> productService, VariantService<Variant> variantService, ProductAssetService<ProductAsset> productAssetService, CategoryService<Category> categoryService, CategoryProductService<CategoryProduct> categoryProductService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, int batchSize, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator) CompleteProductImportBatchHandler
(ProductRowConverter productConverter, CategoryProductColumnConverter categoryProductColumnConverter, ProductImageColumnConverter productImageColumnConverter, VariantRowConverter variantConverter, CatalogTranslationColumnConverter catalogTranslationColumnConverter, ProductService<Product> productService, VariantService<Variant> variantService, ProductAssetService<ProductAsset> productAssetService, CategoryService<Category> categoryService, CategoryProductService<CategoryProduct> categoryProductService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator) -
Method Summary
Modifier and TypeMethodDescriptionboolean
canHandle
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected void
convertVariantRecord
(com.broadleafcommerce.common.dataimport.messaging.BatchRecord variantRecord, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context, Product parent, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Variant>> successfulVariants, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<com.broadleafcommerce.translation.domain.Translation>> successfulTranslations, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> failed) protected void
convertVariantsForProduct
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, Product parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Variant>> successfulVariants, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<com.broadleafcommerce.translation.domain.Translation>> successfulTranslations, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> failed) Converts all variant records for the given product with partial success semantics.protected int
protected BusinessTypeService<BusinessType>
protected CatalogTranslationColumnConverter
protected CategoryProductColumnConverter
protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
protected <T> Set<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<T>>
getNonPersistableDependents
(Set<String> resourceIdsOfFailedParents, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<T>> dependentRequests, Function<T, String> parentIdExtractor) We do not want to even attempt to persist requests which reference a parent item that was not successfully persisted.protected ProductAssetService<ProductAsset>
protected ProductRowConverter
protected ProductImageColumnConverter
protected ProductService<Product>
protected cz.jirutka.rsql.parser.RSQLParser
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation>
protected VariantRowConverter
protected int
protected int
protected VariantService<Variant>
com.broadleafcommerce.common.dataimport.messaging.BatchCompletion
handle
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected void
initializeBatchState
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request) This allows us to initialize shared state for this batch, including pre-fetching existing records for processing, in batch, for performance.protected void
preFetchBusinessTypes
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext) Pre-fetches existingBusinessTypes
from the data store and places them intoBatchRequest.BatchContext.getAdditionalContextMap()
to allowProductRowConverter
to validate a given record's Business Type column.protected void
preFetchCategories
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext) To satisfy requirements ofCategoryProductColumnConverter
, this method will identify and pre-fetch existing categories and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
.protected void
preFetchCategoryProducts
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) To satisfy requirements ofCategoryProductColumnConverter
, this method will identify and pre-fetch existing category products and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
.protected void
preFetchProductAssets
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) To satisfy requirements ofProductImageColumnConverter
, this method will identify and pre-fetch existing product assets and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underProductImageColumnConverter.BATCH_CONTEXT_PREFETCHED_IMAGES_BY_PRODUCT_ID_MAP
.protected void
preFetchProducts
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) Finds provided product records with supplied identifier values, pre-fetches them from the data store and places them intoBatchRequest.BatchContext.getAdditionalContextMap()
for use byProductRowConverter
.protected void
preFetchProductTranslations
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) To satisfy requirements ofCatalogTranslationColumnConverter
, this method will identify and pre-fetch existing product translations and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underCatalogTranslationColumnConverter.BATCH_CONTEXT_PREFETCHED_PRODUCT_TRANSLATIONS_BY_PRODUCT_ID
.protected void
preFetchVariants
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId, Map<String, Variant> allPrefetchedVariantsByCorrelationIdDestination) protected void
preFetchVariantsAndVariantRelatedEntities
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) protected void
preFetchVariantTranslations
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId, Map<String, Variant> allPrefetchedVariantsByCorrelationId) To satisfy requirements ofCatalogTranslationColumnConverter
, this method will identify and pre-fetch existing variant translations and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underCatalogTranslationColumnConverter.BATCH_CONTEXT_PREFETCHED_VARIANT_TRANSLATIONS_BY_VARIANT_ID
.protected <T> List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord>
removeDependentsOfFailedParents
(Map<String, String> failedParentCorrelationIdsByResourceId, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<T>> dependentRequests, Function<T, String> idExtractor, Function<T, String> associatedParentIdExtractor) Finds and removes any dependent persistence requests fromdependentRequests
which refer to a "parent" item which was not successfully persisted.void
setBusinessTypeService
(BusinessTypeService<BusinessType> businessTypeService) 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
-
CompleteProductImportBatchHandler
public CompleteProductImportBatchHandler(ProductRowConverter productConverter, CategoryProductColumnConverter categoryProductColumnConverter, ProductImageColumnConverter productImageColumnConverter, VariantRowConverter variantConverter, CatalogTranslationColumnConverter catalogTranslationColumnConverter, ProductService<Product> productService, VariantService<Variant> variantService, ProductAssetService<ProductAsset> productAssetService, CategoryService<Category> categoryService, CategoryProductService<CategoryProduct> categoryProductService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator) -
CompleteProductImportBatchHandler
public CompleteProductImportBatchHandler(ProductRowConverter productConverter, CategoryProductColumnConverter categoryProductColumnConverter, ProductImageColumnConverter productImageColumnConverter, VariantRowConverter variantConverter, CatalogTranslationColumnConverter catalogTranslationColumnConverter, ProductService<Product> productService, VariantService<Variant> variantService, ProductAssetService<ProductAsset> productAssetService, CategoryService<Category> categoryService, CategoryProductService<CategoryProduct> categoryProductService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, int batchSize, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
-
Method Details
-
canHandle
public boolean canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
getSupportedImportTypes
-
handle
@SuppressNotification("SINGLE_INDEX_REQUEST") public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
getDataRouteKey
-
convertVariantsForProduct
protected void convertVariantsForProduct(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, Product parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Variant>> successfulVariants, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<com.broadleafcommerce.translation.domain.Translation>> successfulTranslations, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> failed) Converts all variant records for the given product with partial success semantics. Successfully converted variants will be placed intoPersistenceRequests
, and failed variants will items will directly becomeBatchCompletionRecords
.- Parameters:
request
- The originalBatchRequest
, containing context.parent
- The pre-converted parent product instanceproductRecord
- TheBatchRecord
associated with the parent Product whose dependent variant records should be converted.successfulVariants
- List of successfully mapped Variants to be persisted.successfulTranslations
- List of successfully mapped Translations to be persisted.failed
- Failed records.
-
convertVariantRecord
protected void convertVariantRecord(com.broadleafcommerce.common.dataimport.messaging.BatchRecord variantRecord, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context, Product parent, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<Variant>> successfulVariants, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<com.broadleafcommerce.translation.domain.Translation>> successfulTranslations, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> failed) -
removeDependentsOfFailedParents
protected <T> List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> removeDependentsOfFailedParents(Map<String, String> failedParentCorrelationIdsByResourceId, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<T>> dependentRequests, Function<T, String> idExtractor, Function<T, String> associatedParentIdExtractor) Finds and removes any dependent persistence requests fromdependentRequests
which refer to a "parent" item which was not successfully persisted. For each of these removed requests, aBatchCompletionRecord
is created. These are collected in a list and returned.- Parameters:
failedParentCorrelationIdsByResourceId
- a map of resource IDs to correlation IDs of "parent" items which could not be successfully persisteddependentRequests
- all of the persistence requests who may potentially have references to the failed parent itemsidExtractor
- a function which can retrieve the resource ID from any given dependent request entityassociatedParentIdExtractor
- a function which can retrieve the parent resource ID reference from any given dependent request entity- Returns:
- a list of
BatchCompletionRecord
withBatchCompletionRecordStatus.ERROR
for the dependent requests which referred to a failed parent
-
getNonPersistableDependents
protected <T> Set<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<T>> getNonPersistableDependents(Set<String> resourceIdsOfFailedParents, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<T>> dependentRequests, Function<T, String> parentIdExtractor) We do not want to even attempt to persist requests which reference a parent item that was not successfully persisted. This method iterates through thedependentRequests
, finding those who refer to a parent item which failed. These are collected and returned.- Parameters:
resourceIdsOfFailedParents
- the resource IDs of "parent" items which could not be successfully persisteddependentRequests
- all of the persistence requests who may potentially have references to the failed parent itemsparentIdExtractor
- a function which can retrieve the parent resource ID reference from any given dependent request entity- Returns:
- the set of
PersistenceRequest
which referred to a failed product
-
initializeBatchState
protected void initializeBatchState(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request) This allows us to initialize shared state for this batch, including pre-fetching existing records for processing, in batch, for performance.- Parameters:
request
- the batch request
-
preFetchProducts
protected void preFetchProducts(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) Finds provided product records with supplied identifier values, pre-fetches them from the data store and places them intoBatchRequest.BatchContext.getAdditionalContextMap()
for use byProductRowConverter
.- Parameters:
request
- the original batch request with the batch context to populatereadContext
- the context info to use to read products from the data storeallPrefetchedProductsByCorrelationId
- an additional map (separate from whatever is populated intoBatchRequest.BatchContext.getAdditionalContextMap()
into which all pre-fetched product instances should also be placed by their correlation ID
-
preFetchBusinessTypes
protected void preFetchBusinessTypes(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext) Pre-fetches existingBusinessTypes
from the data store and places them intoBatchRequest.BatchContext.getAdditionalContextMap()
to allowProductRowConverter
to validate a given record's Business Type column.- Parameters:
request
- the original batch request with the batch context to populatereadContext
- the context info to use to read business types from the data store
-
preFetchCategories
protected void preFetchCategories(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext) To satisfy requirements ofCategoryProductColumnConverter
, this method will identify and pre-fetch existing categories and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
. This ahead-of-time bulk fetch is more performant and allows the converter to properly handle creates vs updates.Fetching
Category
instances is always necessary (regardless of new product or existing product) since we need to map from the name given in the input to an id that can be provided to any subsequentCategoryProduct
instances.- Parameters:
request
- the original batch requestreadContext
- the context info that can be used to fetch entities
-
preFetchCategoryProducts
protected void preFetchCategoryProducts(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) To satisfy requirements ofCategoryProductColumnConverter
, this method will identify and pre-fetch existing category products and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
. This ahead-of-time bulk fetch is more performant and allows the converter to properly handle creates vs updates.Fetching
CategoryProduct
instances is necessary to identify existing relationships.- Parameters:
request
- the original batch requestreadContext
- the context info that can be used to fetch entitiesallPrefetchedProductsByCorrelationId
- a map from correlation ID to prefetched product instances
-
preFetchProductAssets
protected void preFetchProductAssets(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) To satisfy requirements ofProductImageColumnConverter
, this method will identify and pre-fetch existing product assets and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underProductImageColumnConverter.BATCH_CONTEXT_PREFETCHED_IMAGES_BY_PRODUCT_ID_MAP
. This ahead-of-time bulk fetch is more performant and allows the converter to properly handle creates vs updates.- Parameters:
batchRequest
- the original batch requestreadContext
- the context info that can be used to fetch assetsallPrefetchedProductsByCorrelationId
- a map from correlation ID to prefetched product instances
-
preFetchProductTranslations
protected void preFetchProductTranslations(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId) To satisfy requirements ofCatalogTranslationColumnConverter
, this method will identify and pre-fetch existing product translations and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underCatalogTranslationColumnConverter.BATCH_CONTEXT_PREFETCHED_PRODUCT_TRANSLATIONS_BY_PRODUCT_ID
. This ahead-of-time bulk fetch is more performant and allows the converter to properly handle creates vs updates.- Parameters:
batchRequest
- the original batch requestreadContext
- the context info that can be used to fetch product translationsallPrefetchedProductsByCorrelationId
- a map from correlation ID to prefetched product instances
-
preFetchVariantsAndVariantRelatedEntities
-
preFetchVariants
protected void preFetchVariants(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId, Map<String, Variant> allPrefetchedVariantsByCorrelationIdDestination) -
getVariantFetchBatchSize
protected int getVariantFetchBatchSize()- Returns:
- the number of variants that should be fetched from the datastore in a single query
- See Also:
-
preFetchVariantTranslations
protected void preFetchVariantTranslations(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batchRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String, Product> allPrefetchedProductsByCorrelationId, Map<String, Variant> allPrefetchedVariantsByCorrelationId) To satisfy requirements ofCatalogTranslationColumnConverter
, this method will identify and pre-fetch existing variant translations and place them intoBatchRequest.BatchContext.getAdditionalContextMap()
underCatalogTranslationColumnConverter.BATCH_CONTEXT_PREFETCHED_VARIANT_TRANSLATIONS_BY_VARIANT_ID
. This ahead-of-time bulk fetch is more performant and allows the converter to properly handle creates vs updates.- Parameters:
batchRequest
- the original batch requestreadContext
- the context info that can be used to fetch variant translationsallPrefetchedProductsByCorrelationId
- a map from correlation ID to prefetched product instancesallPrefetchedVariantsByCorrelationId
- a map from correlation ID to prefetched variant instances
-
getVariantRelatedEntityFetchBatchSize
protected int getVariantRelatedEntityFetchBatchSize()- Returns:
- the number of variants for which to fetch related entities from the datastore in a single query
- See Also:
-
getProductConverter
-
getCategoryProductColumnConverter
-
getProductImageColumnConverter
-
getVariantConverter
-
getProductService
-
getVariantService
-
getProductAssetService
-
getCategoryService
-
getCategoryProductService
-
getCatalogTranslationColumnConverter
-
getTranslationEntityService
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService() -
setBusinessTypeService
@Autowired public void setBusinessTypeService(BusinessTypeService<BusinessType> businessTypeService) -
getBusinessTypeService
-
getBatchSize
protected int getBatchSize() -
getRsqlParser
protected cz.jirutka.rsql.parser.RSQLParser getRsqlParser()
-