Class AbstractValueTranslator

java.lang.Object
de.hybris.platform.impex.jalo.translators.AbstractValueTranslator
Direct Known Subclasses:
CollectionValueTranslator, CopyrightTranslator, FileLoaderValueTranslator, MapValueTranslator, MarketplaceBannerComponentTranslator, MarketplaceCategoryTranslator, MarketplaceConsignmentCodeTranslator, MarketplaceProductsTranslator, MarketplaceSlotsTranslator, ObjectValueTranslator, PriceTranslator, SequenceIdTranslator, SingleValueTranslator

public abstract class AbstractValueTranslator extends Object
Base class of all value translator instances. These objects are used by StandardColumnDescriptor to translate a cell into attribute value(s) and back again.

To signal that a value could not be translated properly (but may be tried again later) use setError(). This way the surrounding algorithm merely marks the row as unresolved and tries to translate it in a second pass instead of raising a error directly. Be sure to call clearStatus() at the beginning of each new translation.

  • Constructor Details

    • AbstractValueTranslator

      public AbstractValueTranslator()
  • Method Details

    • createTranslator

      public static AbstractValueTranslator createTranslator(ComposedType targetType, List<AbstractDescriptor.ColumnParams>[] patternLists) throws HeaderValidationException
      Throws:
      HeaderValidationException
    • createTranslator

      public static AbstractValueTranslator createTranslator(AttributeDescriptor attributeDescriptor, AtomicType targetType, List<AbstractDescriptor.ColumnParams>[] patternLists) throws HeaderValidationException
      Throws:
      HeaderValidationException
    • createTranslator

      public static AbstractValueTranslator createTranslator(AttributeDescriptor attributeDescriptor, CollectionType collectionType, List<AbstractDescriptor.ColumnParams>[] patternLists) throws HeaderValidationException
      Throws:
      HeaderValidationException
    • getFlexibleSearch

      protected FlexibleSearch getFlexibleSearch()
    • clearStatus

      protected void clearStatus()
      Resets the empty and unresolved flag.
      Unresolved flag says that the last imported value was unresolved.
      Empty flag says that the last imported value was empty.
    • setError

      protected void setError()
      Sets the unresolved flag. Unresolved flag says that the last imported value was unresolved.
    • setEmpty

      protected void setEmpty()
      Sets the empty flag. Empty flag says that the last imported value was empty.
    • validate

      public void validate(StandardColumnDescriptor columnDescriptor) throws HeaderValidationException
      Validates the value translator once per header creation.
      Parameters:
      columnDescriptor - descriptor where the value to translate belongs to
      Throws:
      HeaderValidationException - validation has thrown errors
    • init

      public void init(StandardColumnDescriptor descriptor)
      Called once per header creation to allow configuring this translator using column modifiers etc.
      Parameters:
      descriptor - descriptor where the value to translate belongs to
    • isDebugEnabled

      @Deprecated(since="ages", forRemoval=false) protected boolean isDebugEnabled()
      Deprecated.
      since ages - use logging methodCategory.isDebugEnabled() directly
      Checks if the debug method of the reader is enabled or if no reader set the logger will be checked.
      Returns:
      is debug mode enabled?
    • debug

      @Deprecated(since="ages", forRemoval=false) protected void debug(String msg)
      Deprecated.
      since ages - use logging methodCategory.debug(Object) directly
      Debugs a message with the reader or the current logger instance.
      Parameters:
      msg - debug message
    • isInfoEnabled

      @Deprecated(since="ages", forRemoval=false) protected boolean isInfoEnabled()
      Deprecated.
      since ages - use logging methodCategory.isInfoEnabled() directly
      Checks if the info method of the reader is enabled or if no reader set the logger will be checked.
      Returns:
      is info mode enabled?
    • info

      @Deprecated(since="ages", forRemoval=false) protected void info(String msg)
      Deprecated.
      since ages - use logging methodCategory.info(Object) directly
      Logs an info message with the reader or the current logger instance.
      Parameters:
      msg - info message
    • warn

      @Deprecated(since="ages", forRemoval=false) protected void warn(String msg)
      Deprecated.
      since ages - use logging methodCategory.warn(Object) directly
      Logs an warn message with the reader or the current logger instance.
      Parameters:
      msg - warn message
    • error

      @Deprecated(since="ages", forRemoval=false) protected void error(String msg)
      Deprecated.
      since ages - use logging methodCategory.error(Object) directly
      Logs an error message with the reader or the current logger instance.
      Parameters:
      msg - error message
    • getColumnDescriptor

      public StandardColumnDescriptor getColumnDescriptor()
      Returns the assigned StandardColumnDescriptor instance.
      Returns:
      StandardColumnDescriptor
      See Also:
    • importValue

      public abstract Object importValue(String valueExpr, Item toItem) throws JaloInvalidParameterException
      Translates a tokenized csv value for import usage. This means that the result object must be a instance of the expected attribute type.
      Parameters:
      valueExpr - expression to translate
      toItem - the target item in case it already exist, null otherwise (for partOf attributes!)
      Returns:
      Object translated value
      Throws:
      JaloInvalidParameterException - value can not be translated with this translator or is invalid
    • exportValue

      public abstract String exportValue(Object value) throws JaloInvalidParameterException
      Translates an attribute value for export usage. This means the attribute value must be transformed into a string which should be re-importable again.
      Parameters:
      value - value to translate
      Returns:
      String translated value
      Throws:
      JaloInvalidParameterException - value can not be translated with this translator or is invalid
    • wasUnresolved

      public boolean wasUnresolved()
      Indicates that the last call to importValue(String, Item) or exportValue(Object) could not translate the value yet but may be tried later again.

      This applies mostly to importing item references which require the referenced item to be created first .

      Returns:
      true if the last value could not be translated yet
    • wasEmpty

      public boolean wasEmpty()
      Indicates that the last call to importValue(String, Item) has produced an empty value in respect to the target attribute.

      E.g. collection attributes may consider empty collections as empty value contrary to single valued attributes which will only see null as empty value.

      Returns:
      true if last call of importValue(String, Item) has produced an empty value, false otherwise