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.
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();
}
}
<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>
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;
}
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;
}
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;
}
<?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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
18 | |
12 | |
11 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 |