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
Modifier and TypeClassDescriptionstatic final class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
InBatchRequest.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
ConstructorDescriptionProductImageColumnConverter
(com.fasterxml.jackson.databind.ObjectMapper mapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) -
Method Summary
Modifier and TypeMethodDescriptionboolean
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 targetproductAsset
.protected Map<String,
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 theCompleteProductImportBatchHandler
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) parsePropertiesFromAssetCell
(String cellValue) Cell values for assets (provided in columns starting withIMAGE_COLUMN_PREFIX
) can be complex and supply multiple properties at once.Methods inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter
extractSpecialColumns
-
Field Details
-
IMAGE_COLUMN_PREFIX
- See Also:
-
PRIMARY_IMAGE_COLUMN_PREFIX
- See Also:
-
BATCH_CONTEXT_PREFETCHED_IMAGES_BY_PRODUCT_ID_MAP
InBatchRequest.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 classcom.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 theCompleteProductImportBatchHandler
to have pre-fetched assets if supplied in the original rows. Any assets that were found in the datastore should have been populated intoexistingProductImagesByUrl
.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 rowparent
- the pre-converted parent product instanceexistingProductImagesByUrl
- 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 instanceassetAlreadyExistsInDatastore
- whether the asset was determined to already exist in the datastore. SeeinstantiateOrGetPrefetchedAsset(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 datapropertiesFromAssetCell
- the parsed asset properties from the asset cell that need to be mapped to the target instanceoperationType
- the determined operation type that needs to be performed for this assetparent
- the pre-converted parent product instance for this assetisPrimary
- the value to set forProductAsset.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 targetproductAsset
.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 dataparent
- the pre-converted parent product instance for this assetpropertiesFromAssetCell
- the parsed asset properties from the asset cell that were already mapped to the target instanceoperationType
- the determined operation type that needs to be performed for this assetisPrimary
- the value to set forProductAsset.isPrimary()
context
- the batch context
-
parsePropertiesFromAssetCell
Cell values for assets (provided in columns starting withIMAGE_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 withIMAGE_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 classcom.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 mappedConversionUtils.ConversionResponse
.- Parameters:
product
- the parent productrecord
- the original recordresponse
- 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()
-