Skip to Content

When implementing SuccessFactors integrations using Boomi we commonly define cache’s and Picklist lookups.  The following example describes how to replicate the lookup feature using the HCI platform. 

In this example we are going to replace code values in inbound XML with descriptions. We have hard-coded picklist entities in Hashmap and Key is Custom-Object. This is very important information in this solution.Custom-Object is a Groovy class that identifies different kinds of Picklists (eg. CountryCode, EventReason, etc.).  The Groovy class (Custom-Object) will be placed in the “main.resoruces.script” folder.

Step 1:
______

Define Groovy class (Custom-Object) and override equals and hashCode methods of object and place the Groovy/Object file in  “main.resoruces.script” folder.

 


Contents of Custom Object, Groovy class:

package src.main.resources.script

class KeyMapping {
		private String str1;
		private String str2;
		public KeyMapping(String string, String string1) {
				this.str1 = string;
				this.str2 = string1;
	    }
	//@Override
		public boolean equals(Object obj) {
			return obj.str1.equals(str1) && obj.str2.equals(str2)
		}
	//@Override
		public int hashCode()
		{
		return (str1 + str2).hashCode();
		}
}


Contents of Inbound message:

<xml>
<person>
<name>gbk</name>
<code>US</code>   <!-- Picklist code that will be repalced with Description -->
</person>
<person>
<name>user1</name>
<code>UK</code>  <!-- Picklist code that will be repalced with Description -->
</person>
<person>
<name>user2</name>
<code>JP</code>   <!-- Picklist code that will be repalced with Description -->
</person>
</xml>

Step 2:
______

Next step is to initialize Hashmap object that will hold Picklist Entities. This Hashmap will hold our Custom-Object as Key and value mapping.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import src.main.resources.script.KeyMapping;

def Message processData(Message message) {
	HashMap<KeyMapping, String> cacheData = new HashMap<KeyMapping, String>();
	message.setHeader("cacheEntity",cacheData);
return message;
}

Step 3:
______

Contents of load cache:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import src.main.resources.script.KeyMapping;

def Message processData(Message message) {

    //body
    def body = message.getBody();
	
	def map = message.getHeaders();
	//Get initialized cached entity form Header
	HashMap<KeyMapping, String> cacheData = map.get("cacheEntity");
	
	//to get all externalParameters defined.
	def propertyMap = message.getProperties()
		
		//Example to add pickList_Name (CountryCodes) and ExternalCode	
		KeyMapping one = new KeyMapping("CountryCodes","US");
		KeyMapping two = new KeyMapping("CountryCodes","UK");
		KeyMapping three = new KeyMapping("CountryCodes","JP");
    
		//Setting the pickLists to Cache entity 
		cacheData.put(one,"United States");
		cacheData.put(two,"United Kingdom");
		cacheData.put(three,"Japan");

		 //set cache object in Header Set Picklist back to Header with same property that we  initialized in step 2
		 message.setHeader("cacheEntity",cacheData);
 
     return message;
}

Step 4:
______

Now that we loaded data into Cache Entity (Look up object) next step is replace code values in inbound XML with actual description.

For this to happen we first construct key for look-up with our Custom-Object and pass this key object to HaspMap entity to read Description for the key object.

Contents of Lookup:

 

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.lang.StringBuffer;

import java.io.InputStream;
import org.jaxen.jdom.JDOMXPath;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

import src.main.resources.script.KeyMapping;

def Message processData(Message message) {
	
	//Body 
	def body = message.getBody(java.lang.String);
	
	def messageLog = messageLogFactory.getMessageLog(message);
	
	//to get all externalParameters defined.
	def propertyMap = message.getProperties()
		
	//Headers , Get cached data from Header set in step 3
	def map = message.getHeaders();
	def pickList = map.get("cacheEntity");
       
       //Lookup and replace the message contents
	def finalStr = evaluateMessage(body, pickList, message);
	message.setBody(finalStr);
	
	return message;
}

//Function to lookup and replace Code with Description
def String evaluateMessage(String body, HashMap pickList, Message message){

SAXBuilder builder = new SAXBuilder();
InputStream is = new ByteArrayInputStream(body.getBytes("UTF-8"));
Document doc = builder.build(is);

def xPathCode = new JDOMXPath("//person");
def messageLog = messageLogFactory.getMessageLog(message);

for (Element child : xPathCode.selectNodes(doc)) {
    //Get all elements with code and replace with Desc
     if(child.getChild("code")!=null){  
        //replace with picklist
        String code = child.getChild("code").getText();
       //Construct Key with code and retireve Description PickList:CountryCodes
        KeyMapping vo = new KeyMapping("CountryCodes",code);
        String desc = pickList.get(vo);   
   	//update inbound node with Desc
        child.getChild("code").setText(desc);
    }
  
}
XMLOutputter outputter = new XMLOutputter();
def xmlString = outputter.outputString(doc);
      return xmlString;
}

 

Step 5:
______

Updated inbound XML with description in Datastore or SFTP.

<?xml version="1.0" encoding="UTF-8"?>
<xml>
<person>
<name>gbk</name>
<code>United States</code>    <!-- Udpated with Desc -->
</person>
<person>
<name>user1</name>
<code>United Kingdom</code>  <!-- Udpated with Desc -->
</person>
<person>
<name>user2</name>
<code>Japan</code>   <!-- Udpated with Desc -->
</person>
</xml>


Thanks,
Bhargav

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

  1. Wesley Johnson

    Looks excellent, Bhargav!  The lookup functionality is so key for many integration use cases and sharing this flexible approach will be a great additional for anybody’s HCI tool belt. Thanks!
    -Wes

    (1) 
  2. Ashwini Sharma

    Hello Bhargav,

    Thanks for sharing this .

    I have requirement of replicating marketing attributes from C4C to Hybris marketing via HCI , so i need to use lookup to differentiate account and contact data from source ,same requirement is achieved in PO via RFC lookup but i am not sure how to do this in HCI , Can you please help me on this.

    Regards,

    Ashwini

     

    (0) 
      1. Belinda Lineman

        Hey Bhargav,

        I’m getting error on last groovy script which calls, jdom….

        for example,

        import org.jdom.Document;

        gives error:

        unable to resolve class org.jdom.Document

        I also tried with org.jdom2.Document and received same error.

        Any thoughts?

         

        ~Belinda

        (0) 

Leave a Reply