Skip to Content
author's profile photo Former Member
Former Member

Create Custom Resolve function

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?

link text

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 12, 2017 at 04:36 PM

    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>
        
        
    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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;

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.