Professional Documents
Culture Documents
If we want to check condition for any attribute of any itemtype before saving them into database for
this reason translator comes into picture.
While importing impex value lines,sometime it is required to modify the value based on some
business logic rather than directly inserting the value.
Note:
1. public abstract Object importValue( final String valueExpr, final Item toItem ):
when we import impex file then at that time valueExpr value become as attribute value for
which we have written translators and Item become same as Item type for which we have
written translators.
Ex.
INSERT_UPDATE
PriceRow;productId[unique=true];unit(code[unique=true,default=pieces]);currency(isocode)[uni
que=true];price[translator=de.hybris.platform.acceleratorservices.dataimport.batch.converter.
MyPriceTranslator];minqtd;unitFactor;net
;300441142;pieces;GBP;8.46;1;1;false
Implement the translation logic for the export case here, The given object has to be translated to
a String that has to be returned.
To apply translator on impex we must need to call custom translator class in impex file by
assigning fully qualified name of custom translator class.
Ex.
price[translator=de.hybris.platform.acceleratorservices.dataimport.batch.converter.MyPriceTra
nslator];
Ex.
Let take one scenario where we want to insert value of price which is non-negative.
Step.1 : create class by implementing AbstractValueTranslator and impelemnt the method
Of This class.
@Override
@Override
if (!StringUtils.isBlank(valueExpr))
try
result = Double.valueOf(valueExpr);
setError();
setError();
}
return result;
INSERT_UPDATE
PriceRow;productId[unique=true];unit(code[unique=true,default=pieces]);currency(is
ocode)[unique=true];price[translator=
com.pragiti.translator.TranslaotrdemoStandalone];minqtd;unitFactor;net
;300441142;pieces;GBP;8.46;1;1;false
Note : for translators there is no need to write bean class in spring file just write class that’s it.
Decorator:
Cell Decorator is used to obtain the specific cell of value line after parsing but before translating it.
We can then decorate the cell value based on business logic. Decorating cell value means modifying
the cell value based on some business requirement