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

Create Custom Datahub extension erpproduct

Hi All,

To create custom categories of product,I have created custom Datahub extension.Where I need to create custom Resolver to create custom categories in custom erpproduct target extension, which is extending standard category resolver i.e defaulltcategories. code is as below. package com.cgi.datahub.spel;

import java.util.ArrayList;

/ [y] hybris Platform Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved. This software is the confidential and proprietary information of SAP ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with SAP. /

import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Optional;

import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Required; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.MethodExecutor; import org.springframework.expression.MethodResolver; import org.springframework.expression.TypedValue;

import com.hybris.datahub.model.CanonicalItem; import com.hybris.datahub.runtime.domain.DataHubPool; import com.hybris.datahub.service.CanonicalItemService; import com.hybris.datahub.saperpproduct.publication.DetermineSupercategories;

public class CategoryResolv extends DetermineSupercategories implements MethodResolver, MethodExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(CategoryResolv.class); protected static final TypedValue NONE = new TypedValue(""); protected static TypedValue typedValue = new TypedValue(""); private static final String PRODH1 = "PRODH1"; protected CanonicalItemService canonicalItemService;

 @Override
 public TypedValue execute(final EvaluationContext ec, final Object target, final Object... args) throws AccessException
 {
     
     typedValue = super.execute(ec, target, args);
     if (args[0] == null)
     {
         return NONE;
     }
     LOGGER.info(" Excute Method of custom Resolv");
     final CanonicalItem item = (CanonicalItem) target;
     final DataHubPool pool = item.getDataPool();
     final Map<String, String> keys = new HashMap<>();
     
     String creationSystem = (String)item.getField("creationSystem");
     /*  49 */       String productID = (String)item.getField("productID");

     /*  54 */       keys.put("creationSystem", creationSystem);
     /*  55 */       keys.put("productID", productID);

     final CanonicalItem category = canonicalItemService.findLatestValidItem("CanonicalProductSales", keys, pool);
     if (category != null)
     {
         
         String category_str; 

// custom logic Object obj = typedValue.getValue(); ArrayList category_list=(ArrayList) obj;

          Iterator itr=brands.iterator();  
           while(itr.hasNext()){  
           category_list.add(category_str) ;  
           }
           
     final Object DeterminSupercategories = category_list ;
     LOGGER.info("Succesfully created categories.");
     
         return new TypedValue(DeterminSupercategories);
     }
     else
     {
         LOGGER.info("No Value found.");
     }
     return NONE;
 }

 @Override
 public MethodExecutor resolve(final EvaluationContext ec, final Object target, final String method, final List<TypeDescriptor> argumentTypes) throws AccessException
 {
     LOGGER.info(" Return Method of custom Resolv");
     if (!"CategoryResolv".equals(method))
     {
         return null;
     }
     if (Optional.ofNullable(argumentTypes) //
             .filter(list -> list.size() == 1) //
             .map(list -> list.get(0)) //
             .map(TypeDescriptor::getType) //
             .orElse(null) != String.class)
     {
         LOGGER.info(" Nullpoint Exception");
         return null;
     }
     if (Optional.ofNullable(target) //
             .filter(t -> t instanceof CanonicalItem) //
             .map(CanonicalItem.class::cast) //
             .map(item -> item.getAttributeDefinition(PRODH1))//
             .map(o -> o.orNull()).orElse(null) == null)
     {
         LOGGER.info(" Nullpoint Exception");
         return null;
     }
     LOGGER.info("True from Resolv");
     return this;
 }

 @Required
 public void setCanonicalItemService(final CanonicalItemService canonicalItemService)
 {
     this.canonicalItemService = canonicalItemService;
 }

}

In target extension their is no any spring file so how to define bean for this? As this java class is depend on standard DetermineSupercategories how to provide this dependancy?

I create spring.xml mannualy in custom erpproduct extension aand added below code

 </bean>
 
 </beans>

Provided corresponding Standard extension(saperpproduct raw/canonical/target) dependencies in each (Raw,canonical,target)extension.xml and sapidocintegration dependancy as well.

Also I have added below code in pom.xml of erpproduct extension com.hybris.datahub datahub-rest-client ${datahub.version} test

         <dependency>
             <groupId>com.hybris.datahub</groupId>
             <artifactId>datahub-extension-sdk</artifactId>
             <version>6.5.0.3-RC2</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>datahub-core-export-service</artifactId>
                     <version>${datahub.version}</version>
                     <scope>provided</scope>
                 </dependency>
                 <dependency>
                         <groupId>com.hybris.datahub</groupId>
                     <artifactId>datahub-webapp</artifactId>
                     <version>${datahub.version}</version>
                     <type>war</type>
                     <scope>provided</scope>
                 </dependency>
                 <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>sapcoreconfiguration</artifactId>
                     <version>${sap.datahub.version}</version>
                 </dependency>
                 <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>sapidocintegration</artifactId>
                     <version>${sap.datahub.version}</version>
                 </dependency>
                 <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>sapidocoutboundadapter</artifactId>
                     <version>${sap.datahub.version}</version>
                 </dependency>
                 <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>saperpproduct-raw</artifactId>
                     <version>${sap.datahub.version}</version>
                 </dependency>
                 <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>saperpproduct-canonical</artifactId>
                     <version>${sap.datahub.version}</version>
                 </dependency>
                 <dependency>
                     <groupId>com.hybris.datahub</groupId>
                     <artifactId>saperpproduct-target</artifactId>
                     <version>${sap.datahub.version}</version>
                 </dependency>

for dependancy.

but still I am getting below error

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 15, 2017 at 08:12 PM

    You can create spring file under custom target extension in same location of datahub xml (customsaperpproduct-target-datahub-extension-spring.xml).

    • add below line in spring file

          <bean id="customSapDetermineSupercategories" class="com.cgi.datahub.spel.CategoryResolv" parent="sapDetermineSupercategories"/>
      
      
      • add dependency in target datahub xml file. Some thing like

           <dependencies>
                     <dependency>
                         <extension>customsaperpproduct-canonical</extension>
                     </dependency>
                     <dependency>
                         <extension>saperpproduct-target</extension>
                     </dependency>
                 </dependencies>
         
        
        

    alt text


    10076-c.png (62.1 kB)
    Add a comment
    10|10000 characters needed characters exceeded

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.