cancel
Showing results for 
Search instead for 
Did you mean: 

Create Custom Resolve function

Former Member
0 Kudos

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

Former Member
0 Kudos

Do you guys have any suggestion ?

Regards, Rasika

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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>
      
      
Former Member
0 Kudos

@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?

Former Member
0 Kudos

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)

Former Member
0 Kudos

when I am getting error at if (!(target instanceof CanonicalProductSales)) like can not resolve CanonicalProductSales to a type. Do I need to import any thing for this?

Regards, Rasika

Former Member
0 Kudos

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.

link text

Former Member
0 Kudos

I am getting below error.my custom target extension spring.xml contains below code.

 </bean>

Any suggestion how to resolve it?link text

Former Member
0 Kudos

Try to add dependency to sapidocintegration in your custom datahub xml file

Former Member
0 Kudos

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;

Answers (0)