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.VARIANT
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 a list of pre-fetched product translations by product IDs.static final String
InBatchRequest.BatchContext.getAdditionalContextMap()
, we expect a nested map under this key to contain a list of pre-fetched variant translations by variant IDs.static final String
Fields inherited from class com.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter
COMPLEX_COLUMN_HEADER_PREFIX_DELIMITER
-
Constructor Summary
ConstructorDescriptionCatalogTranslationColumnConverter
(@NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory, @NonNull 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<com.broadleafcommerce.translation.domain.Translation>>
convert
(Object parent, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context) protected Locale
convertToLocale
(String localeLanguageTag) Converts the given locale language tag string to aLocale
.protected com.broadleafcommerce.data.tracking.core.type.OperationType
determineOperationType
(@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.IdResolver
getParentIdAndType
(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.TypeFactory
protected 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 theCompleteProductImportBatchHandler
to have pre-fetched translations if supplied in the original rows.protected void
overrideChangeContainerForTranslation
(@NonNull Object parent, @NonNull String parentId, @NonNull com.broadleafcommerce.translation.domain.Translation translation) Overrides the translation'sChangeContainer
information since it's created in the context of another entity's import, e.g., Product.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:
convert
in classcom.broadleafcommerce.common.dataimport.conversion.AbstractRowConverter<List<com.broadleafcommerce.common.dataimport.util.ConversionUtils.ConversionResponse<com.broadleafcommerce.translation.domain.Translation>>>
-
overrideChangeContainerForTranslation
protected void overrideChangeContainerForTranslation(@NonNull @NonNull Object parent, @NonNull @NonNull String parentId, @NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation) Overrides the translation'sChangeContainer
information since it's created in the context of another entity's import, e.g., Product. This allows the changes to the translation to be grouped with the rest of the top entity's changes. In the case of this being a translation for a sub-entity like a Variant, then the parent's override change container will be consulted to get the correct top-level container, e.g., the Variant's parent Product.- Parameters:
parent
- The parent of the translationparentId
- The id of the parenttranslation
- The translation that was updated or created by the import
-
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 theCompleteProductImportBatchHandler
to 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
Pair
containing 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.ConversionResponse
containing 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:
canConvert
in 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
Locale
instance 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 forProduct
translations
-
getVariantTranslationEntityType
- Returns:
- the
Translation.getEntityType()
to use forVariant
translations
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getIdResolver
protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver()
-