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 Summary
Constructors Constructor Description CollectionValueTranslator(CollectionType targetType, AbstractValueTranslator elementTranslator)Instantiates a new collection translator instance for collections of typetargetTypetranslatable byelementTranslator.CollectionValueTranslator(CollectionType targetType, AbstractValueTranslator elementTranslator, char delimiter)Not public constructors for testing purposes.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringexportValue(java.lang.Object value)Translates an attribute value for export usage.protected chargetCollectionValueDelimiter()Returns the used element delimiter in collections for defined descriptor.AbstractValueTranslatorgetElementTranslator()Returns the used translator for an single element of collection.java.lang.ObjectimportValue(java.lang.String valueExpr, Item forItem)Translates a tokenized csv value for import usage.voidinit(StandardColumnDescriptor descriptor)Called once per header creation to allow configuring this translator using column modifiers etc.protected booleanisDelimiter(java.lang.String collStr, int pos, char character)Deprecated.since ages - not needed any more - to hook in tokenizing overridesplitAndUnescape(String)instead!protected booleanisEmpty(java.lang.String collStr)Checks if given expression is empty.protected java.lang.StringjoinAndEscape(java.util.List strings)Concats collection element strings into one string delimited by the configured delimiter.protected booleanprocessItem(java.lang.String token, Item forItem, java.util.Collection col, boolean append, boolean allowNull)Translates given token to an value (item attribute) and adds or removes it to given list.protected voidprocessItems(java.util.List<java.lang.String> expressions, Item forItem, java.util.BitSet doAppendSet, java.util.Collection coll, boolean allowNull)Processes all expressions at once.protected java.util.List<java.lang.String>splitAndUnescape(java.lang.String valueExpr)Used for tokenizing the cell string into several collection element tokens.voidvalidate(StandardColumnDescriptor columnDescriptor)Validates the value translator once per header creation.-
Methods inherited from class de.hybris.platform.impex.jalo.translators.AbstractValueTranslator
clearStatus, createTranslator, createTranslator, createTranslator, debug, error, getColumnDescriptor, getFlexibleSearch, info, isDebugEnabled, isInfoEnabled, setEmpty, setError, warn, wasEmpty, wasUnresolved
-
-
-
-
Constructor Detail
-
CollectionValueTranslator
public CollectionValueTranslator(CollectionType targetType, AbstractValueTranslator elementTranslator)
Instantiates a new collection translator instance for collections of typetargetTypetranslatable byelementTranslator.- Parameters:
targetType- type of collection elementselementTranslator- 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 elementselementTranslator- translator for translating elements of collectiondelimiter- delimiter to use for element separation
-
-
Method Detail
-
validate
public void validate(StandardColumnDescriptor columnDescriptor) throws HeaderValidationException
Description copied from class:AbstractValueTranslatorValidates the value translator once per header creation.- Overrides:
validatein classAbstractValueTranslator- 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:AbstractValueTranslatorCalled once per header creation to allow configuring this translator using column modifiers etc.- Overrides:
initin classAbstractValueTranslator- Parameters:
descriptor- descriptor where the value to translate belongs to
-
importValue
public java.lang.Object importValue(java.lang.String valueExpr, Item forItem) throws JaloInvalidParameterExceptionDescription copied from class:AbstractValueTranslatorTranslates a tokenized csv value for import usage. This means that the result object must be a instance of the expected attribute type.- Specified by:
importValuein classAbstractValueTranslator- Parameters:
valueExpr- expression to translateforItem- 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(java.lang.String token, Item forItem, java.util.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 valueforItem- 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
-
processItems
protected void processItems(java.util.List<java.lang.String> expressions, Item forItem, java.util.BitSet doAppendSet, java.util.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 java.lang.String exportValue(java.lang.Object value) throws JaloInvalidParameterExceptionDescription copied from class:AbstractValueTranslatorTranslates 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:
exportValuein classAbstractValueTranslator- 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(java.lang.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 java.lang.String joinAndEscape(java.util.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 java.util.List<java.lang.String> splitAndUnescape(java.lang.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 protected final boolean isDelimiter(java.lang.String collStr, int pos, char character)Deprecated.since ages - not needed any more - to hook in tokenizing overridesplitAndUnescape(String)instead!
-
-