Class CollectionValueTranslator

java.lang.Object
de.hybris.platform.impex.jalo.translators.AbstractValueTranslator
de.hybris.platform.impex.jalo.translators.CollectionValueTranslator
Direct Known Subclasses:
ActiveDirectoryGroupCollectionTranslator, DiscountValuesTranslator, Europe1DiscountsTranslator, Europe1PricesTranslator, ExtractUserGroupTranslator, PromotionPriceRowsTranslator, TaxValuesTranslator

public class CollectionValueTranslator extends AbstractValueTranslator
  • Constructor Details

    • CollectionValueTranslator

      public CollectionValueTranslator(CollectionType targetType, AbstractValueTranslator elementTranslator)
      Instantiates a new collection translator instance for collections of type targetType translatable by elementTranslator.
      Parameters:
      targetType - type of collection elements
      elementTranslator - translator for translating elements of collection
    • CollectionValueTranslator

      public CollectionValueTranslator(CollectionType targetType, AbstractValueTranslator elementTranslator, char delimiter)
      Not public constructors for testing purposes. Additionally to the regular constructor, you can specify the delimiters to use for item separation.
      Parameters:
      targetType - type of collection elements
      elementTranslator - translator for translating elements of collection
      delimiter - delimiter to use for element separation
  • Method Details

    • validate

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

      public void init(StandardColumnDescriptor descriptor)
      Description copied from class: AbstractValueTranslator
      Called once per header creation to allow configuring this translator using column modifiers etc.
      Overrides:
      init in class AbstractValueTranslator
      Parameters:
      descriptor - descriptor where the value to translate belongs to
    • importValue

      public Object importValue(String valueExpr, Item forItem) throws JaloInvalidParameterException
      Description copied from class: AbstractValueTranslator
      Translates a tokenized csv value for import usage. This means that the result object must be a instance of the expected attribute type.
      Specified by:
      importValue in class AbstractValueTranslator
      Parameters:
      valueExpr - expression to translate
      forItem - 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
    • processItem

      protected boolean processItem(String token, Item forItem, Collection col, boolean append, boolean allowNull)
      Translates given token to an value (item attribute) and adds or removes it to given list.
      Parameters:
      token - string representation of one value
      forItem - existing item if exist (can be null)
      col - existing collection for adding/removing (non null)
      append - add (true) or remove (false) attribute to/from existing collection?
      allowNull - if the string is translated to null, do you want to ignore it?
      Returns:
      true, if an attribute was added/removed to the collection, false otherwise
    • processItem

      protected boolean processItem(String token, Item forItem, Collection col, ImpExConstants.ImpExActions append, boolean allowNull)
      Translates given token to an value (item attribute) and adds or removes it to given list.
      Parameters:
      token - string representation of one value
      forItem - existing item if exist (can be null)
      col - existing collection for adding/removing (non null)
      append - add (ImpExActions.ADD), remove (ImpExActions.REMOVE) or merge (ImpExActions.MERGE) attribute to/from existing collection?
      allowNull - if the string is translated to null, do you want to ignore it?
      Returns:
      true, if an attribute was added/removed to the collection, false otherwise
    • processItems

      protected void processItems(List<String> expressions, Item forItem, BitSet doAppendSet, Collection coll, boolean allowNull)
      Processes all expressions at once. This applies to item expressions only!

      Internally this method calls ItemExpressionTranslator.convertAllToJalo(Item, List, List) to perform a single query fetching *all* items at once to avoid database roundtrip.

      Parameters:
      expressions -
      forItem -
      doAppendSet -
      coll -
      allowNull -
    • processItems

      protected void processItems(List<String> expressions, Item forItem, List<ImpExConstants.ImpExActions> doAppendSet, Collection coll, boolean allowNull)
      Processes all expressions at once. This applies to item expressions only!

      Internally this method calls ItemExpressionTranslator.convertAllToJalo(Item, List, List) to perform a single query fetching *all* items at once to avoid database roundtrip.

      Parameters:
      expressions -
      forItem -
      doAppendSet -
      coll -
      allowNull -
    • exportValue

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

      public AbstractValueTranslator getElementTranslator()
      Returns the used translator for an single element of collection.
      Returns:
      used translator
    • isEmpty

      protected boolean isEmpty(String collStr)
      Checks if given expression is empty.
      Parameters:
      collStr - collection expression to check
      Returns:
      true if expression is empty (null or length of 0), false otherwise
    • joinAndEscape

      protected String joinAndEscape(List strings)
      Concats collection element strings into one string delimited by the configured delimiter. If needed the element strings are escaped in case they contain delimiter or other special characters.

      As default this simply calls CSVUtils.joinAndEscape(List, char[], char, boolean).

      Parameters:
      strings - the collection element strings
      Returns:
      the complete cell string
    • splitAndUnescape

      protected List<String> splitAndUnescape(String valueExpr)
      Used for tokenizing the cell string into several collection element tokens. Also this method does unescaping in case the collection element tokens contain escaped delimiters or other special characters.

      As default this calls simply CSVUtils.splitAndUnescape(String, char[], boolean).

      Parameters:
      valueExpr - the cell value
      Returns:
      the list of element tokens
    • getCollectionValueDelimiter

      protected char getCollectionValueDelimiter()
      Returns the used element delimiter in collections for defined descriptor.
      Returns:
      used element delimiter
    • isDelimiter

      @Deprecated(since="ages", forRemoval=false) protected final boolean isDelimiter(String collStr, int pos, char character)
      Deprecated.
      since ages - not needed any more - to hook in tokenizing overridesplitAndUnescape(String) instead!