Class CatalogTranslationColumnConverter
java.lang.Object
com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>>>
com.broadleafcommerce.catalog.dataimport.converter.CatalogTranslationColumnConverter
public class CatalogTranslationColumnConverter
extends com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>>>
Component to parse and convert
Translation-related columns from a
CompleteProductImportBatchHandler.RecordTypes.PRODUCT or CompleteProductImportBatchHandler.RecordTypes.VARIANTimport line.- Author:
- Kelly Tisdell (ktisdell)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringInBatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched product translations by product IDs.static final StringInBatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched variant translations by variant IDs.static final StringFields inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter
COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER -
Constructor Summary
ConstructorsConstructorDescriptionCatalogTranslationColumnConverter(@NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory, @NonNull com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) -
Method Summary
Modifier and TypeMethodDescriptionbooleancanConvert(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>>convert(Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) protected LocaleconvertToLocale(String localeLanguageTag) Converts the given locale language tag string to aLocale.protected com.broadleafcommerce.data.tracking.core.type.OperationTypedetermineOperationType(@NonNull com.broadleafcommerce.translation.domain.Translation translation, boolean translationAlreadyExistsInDatastore, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord originalEntityRecord) Determine the effective operation type for the given translation instance and entity record.protected com.broadleafcommerce.common.dataimport.util.IdResolvergetParentIdAndType(com.broadleafcommerce.common.dataimport.messaging.BatchRecord parentRecord, Object parentInstance) protected List<com.broadleafcommerce.translation.domain.Translation>getPreFetchedProductTranslations(@NonNull String productId, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) getPreFetchedTranslationsForEntityByLocale(com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context, String entityType, String entityId) protected List<com.broadleafcommerce.translation.domain.Translation>getPreFetchedVariantTranslations(@NonNull String variantId, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) protected com.broadleafcommerce.common.extension.TypeFactoryprotected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>initializeData(@NonNull com.broadleafcommerce.translation.domain.Translation translation, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull String entityId, @NonNull String entityType, @NonNull String field, @NonNull Locale locale, @NonNull String value, @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord originalEntityRecord, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) Initialize the data from the translation column onto the translation instance.protected org.springframework.data.util.Pair<Boolean,com.broadleafcommerce.translation.domain.Translation> instantiateOrGetPreFetchedTranslation(@NonNull Locale locale, @NonNull String field, @NonNull Map<String, String> batchRecordRow, @NonNull Map<Locale, Map<String, com.broadleafcommerce.translation.domain.Translation>> existingTranslationsByFieldByLocale) We expect theCompleteProductImportBatchHandlerto have pre-fetched translations if supplied in the original rows.parseFieldNameAndLocale(String translationColumnHeader) Methods inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter
extractSpecialColumns
-
Field Details
-
TRANSLATION_COLUMN_PREFIX
- See Also:
-
BATCH_CONTEXT_PREFETCHED_PRODUCT_TRANSLATIONS_BY_PRODUCT_ID
InBatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched product translations by product IDs.- See Also:
-
BATCH_CONTEXT_PREFETCHED_VARIANT_TRANSLATIONS_BY_VARIANT_ID
InBatchRequest.BatchContext.getAdditionalContextMap(), we expect a nested map under this key to contain a list of pre-fetched variant translations by variant IDs.- See Also:
-
-
Constructor Details
-
CatalogTranslationColumnConverter
public CatalogTranslationColumnConverter(@NonNull @NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory, @NonNull @NonNull com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)
-
-
Method Details
-
convert
@NonNull public List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>> convert(@Nullable Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) - Specified by:
convertin classcom.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>>>
-
instantiateOrGetPreFetchedTranslation
protected org.springframework.data.util.Pair<Boolean,com.broadleafcommerce.translation.domain.Translation> instantiateOrGetPreFetchedTranslation(@NonNull @NonNull Locale locale, @NonNull @NonNull String field, @NonNull @NonNull Map<String, String> batchRecordRow, @NonNull @NonNull Map<Locale, Map<String, com.broadleafcommerce.translation.domain.Translation>> existingTranslationsByFieldByLocale) We expect theCompleteProductImportBatchHandlerto have pre-fetched translations if supplied in the original rows. Any translations that were found in the datastore should have been populated intoexistingTranslationsByFieldByLocale.If a translation is present in this map, we will use this existing instance.
If a translation is not present in this map, we will simply instantiate a new instance.
- Parameters:
locale- the locale that this translation is forfield- the field this translation is forbatchRecordRow- the original entity's batch record rowexistingTranslationsByFieldByLocale- a map which should contain any pre-fetched existing translations for the entity, mapped by field and locale- Returns:
- a
Paircontaining a boolean describing whether the translation was found in the pre-fetched map, as well as the translation instance itself
-
determineOperationType
protected com.broadleafcommerce.data.tracking.core.type.OperationType determineOperationType(@NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation, boolean translationAlreadyExistsInDatastore, @NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord originalEntityRecord) Determine the effective operation type for the given translation instance and entity record. This can help inform decisions on how to instantiate/map fields.- Parameters:
translation- the resolved translation instancetranslationAlreadyExistsInDatastore- whether the translation was determined to already exist in the datastore. SeeinstantiateOrGetPreFetchedTranslation(Locale, String, Map, Map)originalEntityRecord- the original entity batch record- Returns:
- the effective operation type for the given translation instance
-
initializeData
protected com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation> initializeData(@NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType, @NonNull @NonNull String entityId, @NonNull @NonNull String entityType, @NonNull @NonNull String field, @NonNull @NonNull Locale locale, @NonNull @NonNull String value, @NonNull @NonNull com.broadleafcommerce.common.dataimport.messaging.BatchRecord originalEntityRecord, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) Initialize the data from the translation column onto the translation instance.- Parameters:
translation- the target instance on which to initialize dataoperationType- the determined operation type that needs to be performed for this translationentityId- the determinedTranslation.getEntityId()entityType- the determinedTranslation.getEntityType()field- the determinedTranslation.getEntityField()locale- the determinedTranslation.getLocale()value- the determinedTranslation.getValue()originalEntityRecord- the original batch record this translation came fromcontext- the batch context- Returns:
- a
ConversionUtils.ConversionResponsecontaining the updated instance
-
getPreFetchedTranslationsForEntityByLocale
-
getPreFetchedProductTranslations
-
getPreFetchedVariantTranslations
-
canConvert
public boolean canConvert(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) - Specified by:
canConvertin classcom.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>>>
-
parseFieldNameAndLocale
-
convertToLocale
Converts the given locale language tag string to aLocale.- Parameters:
localeLanguageTag- the parsed locale language tag (with either '_' or '-' as the separator)- Returns:
- the
Localeinstance matching the given language tag - Throws:
IllegalArgumentException- if the given language tag is invalid or resolves to an unavailable locale
-
getParentIdAndType
protected org.springframework.data.util.Pair<String,String> getParentIdAndType(com.broadleafcommerce.common.dataimport.messaging.BatchRecord parentRecord, Object parentInstance) - Parameters:
parentRecord- the parent record from which translation columns will be parsedparentInstance- the pre-converted parent instance that was supplied to the converter- Returns:
- a pair containing the ID from the given parent instance as well as the corresponding
Translation.getEntityType()to use for that instance - Throws:
IllegalArgumentException- if the given record and parent instance are not supported by this converter
-
getProductTranslationEntityType
- Returns:
- the
Translation.getEntityType()to use forProducttranslations
-
getVariantTranslationEntityType
- Returns:
- the
Translation.getEntityType()to use forVarianttranslations
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getIdResolver
protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver()
-