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)
  • Constructor Details

  • Method Details

    • canHandle

      public boolean canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
    • getSupportedImportTypes

      protected Set<String> getSupportedImportTypes()
    • handle

      @SuppressNotification("SINGLE_INDEX_REQUEST") public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
    • getDataRouteKey

      public String 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 into PersistenceRequests, and failed variants will items will directly become BatchCompletionRecords.
      Parameters:
      request - The original BatchRequest, containing context.
      parent - The pre-converted parent product instance
      productRecord - The BatchRecord 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 from dependentRequests which refer to a "parent" item which was not successfully persisted. For each of these removed requests, a BatchCompletionRecord 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 persisted
      dependentRequests - all of the persistence requests who may potentially have references to the failed parent items
      idExtractor - a function which can retrieve the resource ID from any given dependent request entity
      associatedParentIdExtractor - a function which can retrieve the parent resource ID reference from any given dependent request entity
      Returns:
      a list of BatchCompletionRecord with BatchCompletionRecordStatus.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 the dependentRequests, 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 persisted
      dependentRequests - all of the persistence requests who may potentially have references to the failed parent items
      parentIdExtractor - 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 into BatchRequest.BatchContext.getAdditionalContextMap() for use by ProductRowConverter.
      Parameters:
      request - the original batch request with the batch context to populate
      readContext - the context info to use to read products from the data store
      allPrefetchedProductsByCorrelationId - an additional map (separate from whatever is populated into BatchRequest.BatchContext.getAdditionalContextMap() into which all pre-fetched product instances should also be placed by their correlation ID
    • preFetchCategories

      protected void preFetchCategories(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext)
      To satisfy requirements of CategoryProductColumnConverter, this method will identify and pre-fetch existing categories and place them into BatchRequest.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 subsequent CategoryProduct instances.

      Parameters:
      request - the original batch request
      readContext - 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 of CategoryProductColumnConverter, this method will identify and pre-fetch existing category products and place them into BatchRequest.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 request
      readContext - the context info that can be used to fetch entities
      allPrefetchedProductsByCorrelationId - 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 of ProductImageColumnConverter, this method will identify and pre-fetch existing product assets and place them into BatchRequest.BatchContext.getAdditionalContextMap() under ProductImageColumnConverter.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 request
      readContext - the context info that can be used to fetch assets
      allPrefetchedProductsByCorrelationId - 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 of CatalogTranslationColumnConverter, this method will identify and pre-fetch existing product translations and place them into BatchRequest.BatchContext.getAdditionalContextMap() under CatalogTranslationColumnConverter.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 request
      readContext - the context info that can be used to fetch product translations
      allPrefetchedProductsByCorrelationId - a map from correlation ID to prefetched product instances
    • preFetchVariantsAndVariantRelatedEntities

      protected void preFetchVariantsAndVariantRelatedEntities(com.broadleafcommerce.common.dataimport.messaging.BatchRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo readContext, Map<String,Product> allPrefetchedProductsByCorrelationId)
    • 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 of CatalogTranslationColumnConverter, this method will identify and pre-fetch existing variant translations and place them into BatchRequest.BatchContext.getAdditionalContextMap() under CatalogTranslationColumnConverter.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 request
      readContext - the context info that can be used to fetch variant translations
      allPrefetchedProductsByCorrelationId - a map from correlation ID to prefetched product instances
      allPrefetchedVariantsByCorrelationId - 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

      protected ProductRowConverter getProductConverter()
    • getCategoryProductColumnConverter

      protected CategoryProductColumnConverter getCategoryProductColumnConverter()
    • getProductImageColumnConverter

      protected ProductImageColumnConverter getProductImageColumnConverter()
    • getVariantConverter

      protected VariantRowConverter getVariantConverter()
    • getProductService

      protected ProductService<Product> getProductService()
    • getVariantService

      protected VariantService<Variant> getVariantService()
    • getProductAssetService

      protected ProductAssetService<ProductAsset> getProductAssetService()
    • getCategoryService

      protected CategoryService<Category> getCategoryService()
    • getCategoryProductService

      protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getCatalogTranslationColumnConverter

      protected CatalogTranslationColumnConverter getCatalogTranslationColumnConverter()
    • getTranslationEntityService

      protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService()
    • getBatchSize

      protected int getBatchSize()
    • getRsqlParser

      protected cz.jirutka.rsql.parser.RSQLParser getRsqlParser()