on 12-12-2017 2:21 PM - last edited on 02-04-2024 3:29 AM by postmig_api_4
Hi All,
I am referring below link to create custom resolve(). my requirement is I have to take 5 attributes of one canonicalItem and perform some operations on it to create value for category attribute of product target file. But I am not getting how to get/fetch value of these 5 attribute in custom resolve ?and how to use custom resolve in transportexpression of target file?
Can anyone provide sample code for the same?
Long back I have created custom resolver to fetch promotion description. It may help for you
usage will be like below inside target xml :
<attribute>
<name>description</name>
<collection>false</collection>
<transformationExpression>determinePromotionDescription(baseproductID,productID)</transformationExpression>
<exportCode>description</exportCode>
</attribute>
we can pass number of parameters to this method
Create java class by implements MethodResolver, MethodExecutor
there are two method to over ride "resolve" and "execute"
public class DeterminePromotionDescription implements MethodResolver, MethodExecutor
{
protected CanonicalItemService canonicalItemService;
protected DataHubFeedService feedService;
protected DataItemService dataItemService;
protected static final String METHOD_NAME = "determinePromotionDescription";
protected static final TypedValue IGNORE = new TypedValue("<ignore>");
protected static final TypedValue EMPTY = new TypedValue("");
@Override
public MethodExecutor resolve(final EvaluationContext ec, final Object target, final String method,
final List<TypeDescriptor> argumentTypes) throws AccessException
{
if (!METHOD_NAME.equals(method))
{
return null;
}
if (!(target instanceof CanonicalCustomProductFixedPricePromotion))
{
return null;
}
return this;
}
@Override
public TypedValue execute(final EvaluationContext ec, final Object target, final Object... args) throws AccessException
{
final DataHubPool pool = feedService.findPoolByName("GLOBAL");
String baseProduct = (String)args[0];
String productId = (String)args[1];
//here your logic goes
final Object promotionDesc = "";
return new TypedValue(promotionDesc);
}
}
I didn't add getter and setter methods above code
Register class in datahub extensions spring file
<bean id="determinePromotionDescription" class="com.datahub.impl.DeterminePromotionDescription">
<property name="canonicalItemService" ref="canonicalItemService"></property>
<property name="dataItemService" ref="dataItemService" />
<property name="feedService" ref="dataHubFeedService" />
</bean>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@kiranKumar,
Thanks for your reply. from above code if (!(target instanceof CanonicalCustomProductFixedPricePromotion)) please clarify "CanonicalCustomProductFixedPricePromotion" is the name of canonicalItem ? Code line: public TypedValue execute(final EvaluationContext ec, final Object target, final Object... args)
please clarify "args" contains canonical attributes?
CanonicalCustomProductFixedPricePromotion is the canonical item from which target is populating .
args contains the parameters that we are passing from transformation expression method. You can pass as many parameters you needs (from canonical item attributes).
determinePromotionDescription(baseproductID,productID)
The sample code I have given from earlier version, that time we had models for each canonical types. See the attachment for 6.x version code sample. Even you can remove that check.
sapidocintegration is already their, in my custom resolver I am trying to extend standard category resolver defualtcaterogy.class ,so do I need to add any thing in my custom extension as it is depend on standard defualtcaterogy.class? I just have added import com.hybris.datahub.saperpproduct.publication.DetermineSupercategories;
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.