cancel
Showing results for 
Search instead for 
Did you mean: 

Can I pass an empty Collection through impex?

Former Member
0 Kudos

Here is the sample impex.

 INSERT_UPDATE ConsumerCategory; code[unique = true]; name[lang = en]; $supercategories; $catalogversion;categoryRestrictions
 ; sample_category_1; Sample;  ;  ; ; ;

I have restrictions to make sure the category is unique under a store and a catalog revision ( I have one catalog for 20+ websites we are using restrictions to control the visibilityof categories and products per site.). I have a validator to do this.

when I create a category through HMC, an empty collection is getting passed to the validator and everything seems fine. But when I run the above impex, null is getting passed instead of an empty collection. I know I can change the validator to accommodate this, But just wanted to check if we can pass an empty List through impex somehow? I thought about writing a decorator but it returns String

Thanks -Jobin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can write a new translator overriding hybris out of the box CollectionValueTranslator. Override importValue() method to return an empty instance of collection .

INSERT_UPDATE ConsumerCategory; code[unique = true]; name[lang = en]; $supercategories[[translator=custom.translator.CustomCollectionTranslator]; $catalogversion;categoryRestrictions ; sample_category_1; Sample; ; ; ; ;

Below is the translator code :

 /**
  * 
  */
 package custom.translator;
 import de.hybris.platform.impex.jalo.translators.AbstractValueTranslator;
 import de.hybris.platform.impex.jalo.translators.CollectionValueTranslator;
 import de.hybris.platform.jalo.Item;
 import de.hybris.platform.jalo.JaloInvalidParameterException;
 import de.hybris.platform.jalo.type.CollectionType;
 
 /**
  * @author abir.p
  * 
  */
 public class CustomCollectionTranslator extends CollectionValueTranslator
 {
     private CollectionType colType;
     public CustomCollectionTranslator(final CollectionType targetType, final AbstractValueTranslator elementTranslator)
     {
         super(targetType, elementTranslator);
         this.colType = targetType;
     }
     public CustomCollectionTranslator(final CollectionType targetType, final AbstractValueTranslator elementTranslator,
             final char delimiter)
     {
         super(targetType, elementTranslator, delimiter);
         this.colType = targetType;
     }
     @Override
     public Object importValue(final String valueExpr, final Item forItem) throws JaloInvalidParameterException
     {
         final Object collection = super.importValue(valueExpr, forItem);
         if (collection != null)
         {
             return collection;
         }
         return this.colType.newInstance();
     }
     @Override
     public String exportValue(final Object value) throws JaloInvalidParameterException
     {
         return super.exportValue(value);
     }
 }
 

Let me know if it solves your problem.

Answers (1)

Answers (1)

Former Member
0 Kudos

Shall we do this without writing a decorator or translator? I was trying to look for an impex specific solution. Do we have any modifier to do this?