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
Modifier and TypeFieldDescriptionstatic final String
InBatchRequest.BatchContext.getAdditionalContextMap()
, we expect a nested map under this key to contain pre-fetched category instances by category names.static final String
InBatchRequest.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
ConstructorDescriptionCategoryProductColumnConverter
(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<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
getPreFetchedCategoriesByName
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) protected Map<String,
CategoryProduct> 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 theCompleteProductImportBatchHandler
to have pre-fetched category products if supplied in the original rows.Methods inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter
extractSpecialColumns
-
Field Details
-
CATEGORY_COLUMN_PREFIX
- See Also:
-
PRIMARY_CATEGORY_COLUMN_PREFIX
- See Also:
-
BATCH_CONTEXT_PREFETCHED_CATEGORIES_BY_NAME_MAP
InBatchRequest.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
InBatchRequest.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 classcom.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<CategoryProduct>>>
-
getPreFetchedCategoriesByName
-
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 theCompleteProductImportBatchHandler
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 intoexistingCategoryProductRelationshipsForProductByCategoryId
.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 requestedcategory
- the pre-fetched category instance for which a category-product relationship was requestedexistingCategoryProductRelationshipsForProductByCategoryId
- 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 instancecategoryProductAlreadyExistsInDatastore
- whether the category product was determined to already exist in the datastore. SeeinstantiateOrGetPrefetchedCategoryProduct(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 dataparent
- the pre-converted parent product instance for this category productcategory
- the pre-fetched category instance for this category productoperationType
- the determined operation type that needs to be performed for this category productisPrimary
- the value to set forCategoryProduct.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 classcom.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()
-