cancel
Showing results for 
Search instead for 
Did you mean: 

Create Custom Datahub extension erpproduct

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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>
       
      
      

Former Member
0 Kudos

Extension got uploaded successfully.But when I try to replicate data I found below error link text

Former Member
0 Kudos

I'm not sure your class will execute. Check the screen shot and - how did you get brands to iterate ? - why do you need empty strings to array list

If this was not complete code can you attach source code .

  • are you trying to add argument values to category list returned from super class ?

Former Member
0 Kudos

Please find below for complete code. link text

Answers (0)