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

    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 translations by product IDs.
    static final String
    In BatchRequest.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

    Constructors
    Constructor
    Description
    CatalogTranslationColumnConverter(@NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory, @NonNull 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<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 a Locale.
    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
     
    protected org.springframework.data.util.Pair<String,String>
    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)
     
    protected Map<Locale,Map<String,com.broadleafcommerce.translation.domain.Translation>>
    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 the CompleteProductImportBatchHandler to have pre-fetched translations if supplied in the original rows.
    protected org.springframework.data.util.Pair<String,Locale>
    parseFieldNameAndLocale(String translationColumnHeader)
     

    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

    • TRANSLATION_COLUMN_PREFIX

      public static final String TRANSLATION_COLUMN_PREFIX
      See Also:
    • BATCH_CONTEXT_PREFETCHED_PRODUCT_TRANSLATIONS_BY_PRODUCT_ID

      public static final String BATCH_CONTEXT_PREFETCHED_PRODUCT_TRANSLATIONS_BY_PRODUCT_ID
      In BatchRequest.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

      public static final String BATCH_CONTEXT_PREFETCHED_VARIANT_TRANSLATIONS_BY_VARIANT_ID
      In BatchRequest.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 class com.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 the CompleteProductImportBatchHandler to have pre-fetched translations if supplied in the original rows. Any translations that were found in the datastore should have been populated into existingTranslationsByFieldByLocale.

      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 for
      field - the field this translation is for
      batchRecordRow - the original entity's batch record row
      existingTranslationsByFieldByLocale - 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 instance
      translationAlreadyExistsInDatastore - whether the translation was determined to already exist in the datastore. See instantiateOrGetPreFetchedTranslation(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 data
      operationType - the determined operation type that needs to be performed for this translation
      entityId - the determined Translation.getEntityId()
      entityType - the determined Translation.getEntityType()
      field - the determined Translation.getEntityField()
      locale - the determined Translation.getLocale()
      value - the determined Translation.getValue()
      originalEntityRecord - the original batch record this translation came from
      context - the batch context
      Returns:
      a ConversionUtils.ConversionResponse containing the updated instance
    • getPreFetchedTranslationsForEntityByLocale

      protected Map<Locale,Map<String,com.broadleafcommerce.translation.domain.Translation>> getPreFetchedTranslationsForEntityByLocale(@Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context, String entityType, String entityId)
    • getPreFetchedProductTranslations

      protected List<com.broadleafcommerce.translation.domain.Translation> getPreFetchedProductTranslations(@NonNull @NonNull String productId, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    • getPreFetchedVariantTranslations

      protected List<com.broadleafcommerce.translation.domain.Translation> getPreFetchedVariantTranslations(@NonNull @NonNull String variantId, @Nullable com.broadleafcommerce.common.dataimport.messaging.BatchRequest.BatchContext context)
    • 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<com.broadleafcommerce.translation.domain.Translation>>>
    • parseFieldNameAndLocale

      protected org.springframework.data.util.Pair<String,Locale> parseFieldNameAndLocale(String translationColumnHeader)
    • convertToLocale

      protected Locale convertToLocale(String localeLanguageTag)
      Converts the given locale language tag string to a Locale.
      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 parsed
      parentInstance - 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

      public String getProductTranslationEntityType()
      Returns:
      the Translation.getEntityType() to use for Product translations
    • getVariantTranslationEntityType

      public String getVariantTranslationEntityType()
      Returns:
      the Translation.getEntityType() to use for Variant translations
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getIdResolver

      protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver()