Class CategoryProductColumnConverter

java.lang.Object
com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>>>
com.broadleafcommerce.catalog.dataimport.converter.CategoryProductColumnConverter

public class CategoryProductColumnConverter extends com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>>>
Component to parse and convert category-product-related columns from a CompleteProductImportBatchHandler.RecordTypes.PRODUCT import line.
Author:
Kelly Tisdell (ktisdell)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    In BatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain pre-fetched category instances by category names.
    static final String
    In BatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched category product instances by product IDs.
    static final String
     
    static final String
     

    Fields inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter

    COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER
  • Constructor Summary

    Constructors
    Constructor
    Description
    CategoryProductColumnConverter(com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canConvert(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
     
    List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>>
    convert(Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
     
    protected com.broadleafcommerce.data.tracking.core.type.OperationType
    determineOperationType(@NonNull CategoryProduct categoryProduct, boolean categoryProductAlreadyExistsInDatastore, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord)
    Determine the effective operation type for the given category product instance and product record.
    protected com.broadleafcommerce.common.dataimport.util.IdResolver
     
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    protected Map<String,Category>
    getPreFetchedCategoriesByName(com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
     
    getPreFetchedCategoryProductsForProductByCategoryId(com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context, Product product)
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>
    initializeData(@NonNull CategoryProduct categoryProduct, @NonNull Product parent, @NonNull Category category, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, boolean isPrimary, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord)
    Initialize the data from the category product row onto the category product instance and set additional data as needed.
    protected org.springframework.data.util.Pair<Boolean,CategoryProduct>
    instantiateOrGetPrefetchedCategoryProduct(@NonNull Product product, @NonNull Category category, @NonNull Map<String,CategoryProduct> existingCategoryProductRelationshipsForProductByCategoryId)
    We expect the CompleteProductImportBatchHandler to have pre-fetched category products if supplied in the original rows.

    Methods inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter

    extractSpecialColumns

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CATEGORY_COLUMN_PREFIX

      public static final String CATEGORY_COLUMN_PREFIX
      See Also:
    • PRIMARY_CATEGORY_COLUMN_PREFIX

      public static final String PRIMARY_CATEGORY_COLUMN_PREFIX
      See Also:
    • BATCH_CONTEXT_PREFETCHED_CATEGORIES_BY_NAME_MAP

      public static final String BATCH_CONTEXT_PREFETCHED_CATEGORIES_BY_NAME_MAP
      In BatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain pre-fetched category instances by category names.
      See Also:
    • BATCH_CONTEXT_PREFETCHED_CATEGORY_PRODUCTS_BY_PRODUCT_ID_MAP

      public static final String BATCH_CONTEXT_PREFETCHED_CATEGORY_PRODUCTS_BY_PRODUCT_ID_MAP
      In BatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched category product instances by product IDs.
      See Also:
  • Constructor Details

    • CategoryProductColumnConverter

      public CategoryProductColumnConverter(com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
  • Method Details

    • convert

      @NonNull public List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>> convert(@Nullable Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Specified by:
      convert in class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>>>
    • getPreFetchedCategoriesByName

      protected Map<String,Category> getPreFetchedCategoriesByName(@Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    • getPreFetchedCategoryProductsForProductByCategoryId

      protected Map<String,CategoryProduct> getPreFetchedCategoryProductsForProductByCategoryId(@Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context, Product product)
    • instantiateOrGetPrefetchedCategoryProduct

      protected org.springframework.data.util.Pair<Boolean,CategoryProduct> instantiateOrGetPrefetchedCategoryProduct(@NonNull @NonNull Product product, @NonNull @NonNull Category category, @NonNull @NonNull Map<String,CategoryProduct> existingCategoryProductRelationshipsForProductByCategoryId)
      We expect the CompleteProductImportBatchHandler to have pre-fetched category products if supplied in the original rows. Any category products that were found in the datastore should have been populated into existingCategoryProductRelationshipsForProductByCategoryId.

      If a category product is present in this map, we will use this existing instance.

      If a category product is not present in this map, we will simply instantiate a new instance.

      Parameters:
      product - the pre-converted parent product instance for which a category-product relationship was requested
      category - the pre-fetched category instance for which a category-product relationship was requested
      existingCategoryProductRelationshipsForProductByCategoryId - a map which should contain any pre-fetched existing category products for the product, mapped by category id
      Returns:
      a Pair containing a boolean describing whether the category product was found in the pre-fetched map, as well as the category product instance itself
    • determineOperationType

      protected com.broadleafcommerce.data.tracking.core.type.OperationType determineOperationType(@NonNull @NonNull CategoryProduct categoryProduct, boolean categoryProductAlreadyExistsInDatastore, @NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord)
      Determine the effective operation type for the given category product instance and product record. This can help inform decisions on how to instantiate/map fields.
      Parameters:
      categoryProduct - the resolved category product instance
      categoryProductAlreadyExistsInDatastore - whether the category product was determined to already exist in the datastore. See instantiateOrGetPrefetchedCategoryProduct(Product, Category, Map)
      productRecord - the original product batch record
      Returns:
      the effective operation type for the given category product instance
    • initializeData

      protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct> initializeData(@NonNull @NonNull CategoryProduct categoryProduct, @NonNull @NonNull Product parent, @NonNull @NonNull Category category, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, boolean isPrimary, @NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord)
      Initialize the data from the category product row onto the category product instance and set additional data as needed.
      Parameters:
      categoryProduct - the target instance on which to initialize data
      parent - the pre-converted parent product instance for this category product
      category - the pre-fetched category instance for this category product
      operationType - the determined operation type that needs to be performed for this category product
      isPrimary - the value to set for CategoryProduct.isPrimary()
      productRecord - the original product record
      Returns:
      a ConversionUtils.ConversionResponse containing the updated instance
    • canConvert

      public boolean canConvert(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Specified by:
      canConvert in class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>>>
    • getMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getIdResolver

      protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver()