I want to import media in such a way that if code is null, then hybris should ignore it otherwise it will pass it. Here is my Impex
INSERT_UPDATE Media;mediaFormat(qualifier);code[unique=true][allownull=true];youtubeURL;mime[default='video/mp4'];$catalogVersion;folder(qualifier)[default=images]
I have one CSV file which having multiple set of data for products. Some products having media, some are not. So I am trying to allowing null in code attribute but its not working.
I checked with impex.legacy.mode=true
also but no luck. Its still throwing error. May be it can be possible through beanshell but not sure how to do. I dont want to write custom translator for that. Please give me some possible solutions.
After lot of thinking, i could not find any proper solution except to create my own processor. Here is the Solution
public class MediaProcessor extends DefaultImportProcessor
{
@Override
public void init(final ImpExImportReader reader)
{
super.init(reader);
}
@Override
public Item processItemData(final ValueLine valueLine) throws ImpExException
{
Item item = null;
final ValueEntry codeEntry = valueLine.getValueEntry(2);
final String mediaCode = codeEntry.getCellValue();
if (StringUtils.isNotEmpty(mediaCode))
{
item = super.processItemData(valueLine);
}
return item;
}
}
Impex should be like this ..
INSERT_UPDATE Media[processor=com.hybris.core.impex.processor.MediaProcessor];mediaFormat(qualifier);code[unique=true];youtubeURL;mime[default='video/mp4'];$catalogVersion;folder(qualifier)[default=images]
This won't rescue error. But it will not throw Null Pointer Exception as i was getting in my console (A big one really hate this). So if code = null
System will dump that line and proceed to next.
A quick hack solved my problem. Here is a proper solution to dump a complete line if code = null (as per my requirement)
One line made everything working like a charm!!!
valueLine.resolve(item, Collections.EMPTY_LIST);
public class MediaProcessor extends DefaultImportProcessor
{
@Override
public void init(final ImpExImportReader reader)
{
super.init(reader);
}
@Override
public Item processItemData(final ValueLine valueLine) throws ImpExException
{
Item item = null;
final ValueEntry codeEntry = valueLine.getValueEntry(2);
final String mediaCode = codeEntry.getCellValue();
if (StringUtils.isNotEmpty(mediaCode))
{
item = super.processItemData(valueLine);
}
else
{
valueLine.resolve(item, Collections.EMPTY_LIST);
}
return item;
}
}