Class ProductImageColumnConverter

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

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

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
  • 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 a list of pre-fetched product image assets 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
    ProductImageColumnConverter(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<ProductAsset>>
    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 ProductAsset asset, boolean assetAlreadyExistsInDatastore, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord productRecord)
    Determine the effective operation type for the given product asset instance and product record.
    protected void
    forceSetOpinionatedPropertiesOnMappedInstance(ProductAsset productAsset, Product parent, Map<String,String> propertiesFromAssetCell, com.broadleafcommerce.data.tracking.core.type.OperationType operationType, boolean isPrimary, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    This will be invoked after any properties from the provided row are already mapped onto the target productAsset.
    getExistingImagesForProductByUrl(String productId, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
     
    protected com.broadleafcommerce.common.dataimport.util.IdResolver
     
    protected com.fasterxml.jackson.databind.ObjectMapper
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<ProductAsset>
    initializeData(@NonNull ProductAsset productAsset, @NonNull Map<String,String> propertiesFromAssetCell, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull Product parent, boolean isPrimary, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    Initialize the data from the asset cell onto the asset instance and set additional data as needed.
    protected org.springframework.data.util.Pair<Boolean,ProductAsset>
    instantiateOrGetPrefetchedAsset(@NonNull Map<String,String> propertiesFromAssetCell, @NonNull Product parent, @NonNull Map<String,ProductAsset> existingProductImagesByUrl)
    We expect the CompleteProductImportBatchHandler to have pre-fetched assets if supplied in the original rows.
    protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<ProductAsset>
    modifyMappedResponse(@NonNull Product product, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @NonNull com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<ProductAsset> response, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    Simple hook point to allow the modification of the output of the originally mapped responses.
    protected void
    parseAndSetTags(String rawTagsTokenFromCell, @NonNull ProductAsset targetInstance, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType)
     
    protected Map<String,String>
    Cell values for assets (provided in columns starting with IMAGE_COLUMN_PREFIX) can be complex and supply multiple properties at once.

    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

    • IMAGE_COLUMN_PREFIX

      public static final String IMAGE_COLUMN_PREFIX
      See Also:
    • PRIMARY_IMAGE_COLUMN_PREFIX

      public static final String PRIMARY_IMAGE_COLUMN_PREFIX
      See Also:
    • BATCH_CONTEXT_PREFETCHED_IMAGES_BY_PRODUCT_ID_MAP

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

    • ProductImageColumnConverter

      public ProductImageColumnConverter(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<ProductAsset>> 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<ProductAsset>>>
    • getExistingImagesForProductByUrl

      protected Map<String,ProductAsset> getExistingImagesForProductByUrl(String productId, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    • instantiateOrGetPrefetchedAsset

      protected org.springframework.data.util.Pair<Boolean,ProductAsset> instantiateOrGetPrefetchedAsset(@NonNull @NonNull Map<String,String> propertiesFromAssetCell, @NonNull @NonNull Product parent, @NonNull @NonNull Map<String,ProductAsset> existingProductImagesByUrl)
      We expect the CompleteProductImportBatchHandler to have pre-fetched assets if supplied in the original rows. Any assets that were found in the datastore should have been populated into existingProductImagesByUrl.

      If an asset is present in this map, we will use this existing instance.

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

      Parameters:
      propertiesFromAssetCell - a parsed map of properties from the asset column in the original row
      parent - the pre-converted parent product instance
      existingProductImagesByUrl - a map which should contain any pre-fetched existing assets for the product, mapped by url
      Returns:
      a Pair containing a boolean describing whether the asset was found in the pre-fetched map, as well as the asset instance itself
    • determineOperationType

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

      protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<ProductAsset> initializeData(@NonNull @NonNull ProductAsset productAsset, @NonNull @NonNull Map<String,String> propertiesFromAssetCell, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull @NonNull Product parent, boolean isPrimary, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Initialize the data from the asset cell onto the asset instance and set additional data as needed.
      Parameters:
      productAsset - the target instance on which to initialize data
      propertiesFromAssetCell - the parsed asset properties from the asset cell that need to be mapped to the target instance
      operationType - the determined operation type that needs to be performed for this asset
      parent - the pre-converted parent product instance for this asset
      isPrimary - the value to set for ProductAsset.isPrimary()
      context - the batch context
      Returns:
      a ConversionUtils.ConversionResponse containing the updated instance
    • parseAndSetTags

      protected void parseAndSetTags(@Nullable String rawTagsTokenFromCell, @NonNull @NonNull ProductAsset targetInstance, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType)
    • forceSetOpinionatedPropertiesOnMappedInstance

      protected void forceSetOpinionatedPropertiesOnMappedInstance(ProductAsset productAsset, Product parent, Map<String,String> propertiesFromAssetCell, com.broadleafcommerce.data.tracking.core.type.OperationType operationType, boolean isPrimary, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      This will be invoked after any properties from the provided row are already mapped onto the target productAsset.

      For certain properties, we do not want to honor whatever was provided in the row and instead force-set to opinionated values. This method will set/overwrite values to ensure the system opinions prevail. Note that ProductAsset.getId() is not included in this logic and will already be set to the correct value.

      Parameters:
      productAsset - the target instance on which to initialize data
      parent - the pre-converted parent product instance for this asset
      propertiesFromAssetCell - the parsed asset properties from the asset cell that were already mapped to the target instance
      operationType - the determined operation type that needs to be performed for this asset
      isPrimary - the value to set for ProductAsset.isPrimary()
      context - the batch context
    • parsePropertiesFromAssetCell

      protected Map<String,String> parsePropertiesFromAssetCell(String cellValue)
      Cell values for assets (provided in columns starting with IMAGE_COLUMN_PREFIX) can be complex and supply multiple properties at once. This method is capable of parsing a raw cell value and breaking it into the various properties that were supplied.
      Parameters:
      cellValue - the raw cell value of a column starting with IMAGE_COLUMN_PREFIX
      Returns:
      a map from asset properties to values that were supplied in the cell
      Throws:
      IllegalArgumentException - if parsing could not be successfully completed
    • 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<ProductAsset>>>
    • modifyMappedResponse

      protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<ProductAsset> modifyMappedResponse(@NonNull @NonNull Product product, @NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @NonNull @NonNull com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<ProductAsset> response, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
      Simple hook point to allow the modification of the output of the originally mapped responses. Null responses will be ignored (not handled). You can also return an entirely new response. By default this simply returns the originally mapped ConversionUtils.ConversionResponse.
      Parameters:
      product - the parent product
      record - the original record
      response - the originally mapped response (default behavior of this class)
      context - the batch context
      Returns:
      the ConversionResponse
    • 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()