import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String; //get message body as String
def messageLog = messageLogFactory.getMessageLog(message);
if(messageLog != null){
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment") //set property for log
messageLog.addAttachmentAsString("SF_Picklist:", body, "application/xml"); //generate attachment with content type application/xml
}
return message;
}
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.XmlUtil;
import groovy.util.XmlParser;
def Message processData(Message message) {
//message Body
def records = message.getBody(java.lang.String) as String;
//accessing Global_picklist from Properties
def map = message.getProperties();
def picklist = map.get("Global_Picklist");
// Define XML parser and builder for picklist and records
def xlm_records = new XmlParser().parseText(records);
def xml_picklist = new XmlParser().parseText(picklist);
//getting picklist values in HashMaps------------------------------------------------------------
//bloodGroup
HashMap<String, String> bloodGroup = new HashMap<String, String>(); //create a new Hashmap object
xml_picklist.PicklistOption.findAll { p ->
p.picklistId[0].text().toString().equals("bloodGroup") //finding all bloodGroup picklistid entities
}.each { p ->
bloodGroup.put(p.externalCode[0].text().toString(),(p.en_US[0].text().toString().toUpperCase())) //put all key(externalCode) value(en_US->UpperCase) pairs in Hashmap
}
//salutation
HashMap<String, String> salutation = new HashMap<String, String>(); //create a new Hashmap object
xml_picklist.PicklistOption.findAll { p ->
p.picklistId[0].text().toString().equals("salutation") //finding all salutation picklistid entities
}.each { p ->
salutation.put(p.id[0].text().toString(),(p.en_US[0].text().toString().toUpperCase())) //put all key(id) value(en_US->UpperCase) pairs in Hashmap
}
//addressType
HashMap<String, String> addressType = new HashMap<String, String>(); //create a new Hashmap object
xml_picklist.PicklistOption.findAll { p ->
p.picklistId[0].text().toString().equals("addressType") //finding all addressType picklistid entities
}.each { p ->
addressType.put(p.id[0].text().toString(),(p.en_US[0].text().toString().toUpperCase())) //put all key(id) value(en_US->UpperCase) pairs in Hashmap
}
//Updating corresponding keys into the xml records---------------------------------------------------------
//loop for multiple records in message body
int result_size = xlm_records.results.size();
int count = 0;
while(count < result_size)
{
//----------------------------------------Blood group---------------------------------------------------------------------
def check_exist_bloodGroup = xlm_records.results[count].BLOOD_GROUP.isEmpty(); // Checking if exists
if(check_exist_bloodGroup.toString().equals("false")){
def temp_variable = xlm_records.results[count].BLOOD_GROUP.text().toString().toUpperCase(); //get value of blood Group in UpperCase in temp_variable
for (Map.Entry<String, String> entry : bloodGroup.entrySet()) { //looping bloodGroup Hashmap to search corresponding value
if(entry.getValue().equals(temp_variable)){ //Finding value of temp_variable in corresponding hashmap
def lv_val = entry.getKey().toString(); //access and store corresponding key in lv_val variable
xlm_records.results[count].BLOOD_GROUP[0].value = lv_val; //replace value of particular xml element with unique key
}
}
} //IF End for Blood group
//-------------------------------------------Salutation-------------------------------------------------------------------------
def check_exist_saluation = xlm_records.results[count].TITLE.isEmpty(); // Checking for Title, is exists
if(check_exist_saluation.toString().equals("false")){
def temp_variable = xlm_records.results[count].TITLE.text().toString().toUpperCase(); //get value of Title in UpperCase in temp_variable
for (Map.Entry<String, String> entry : salutation.entrySet()) { //looping bloodGroup Hashmap to search corresponding value
if(entry.getValue().equals(temp_variable)){ //Finding value of temp_variable in corresponding hashmap
def lv_val = entry.getKey().toString(); //access and store corresponding key in lv_val variable
if(lv_val.contains("-")){
lv_val = entry.getKey().toString().split("-"); //removing unwanted piece of from string if any
xlm_records.results[count].TITLE[0].value = lv_val[1]; //replace value of particular xml element with unique key
}
else{
xlm_records.results[count].TITLE[0].value = lv_val;
}
}
}
} //IF End for TITLE
//-------------------------------------------Address_type-------------------------------------------------------------------------
def check_exist_addresstype = xlm_records.results[count].Address_type.isEmpty(); // Checking for Title, is exists
if(check_exist_addresstype.toString().equals("false")){
def temp_variable = xlm_records.results[count].Address_type.text().toString().toUpperCase(); //get value of Title in UpperCase in temp_variable
for (Map.Entry<String, String> entry : addressType.entrySet()) { //looping bloodGroup Hashmap to search corresponding value
if(entry.getValue().equals(temp_variable)){ //Finding value of temp_variable in corresponding hashmap
def lv_val = entry.getKey().toString(); //access and store corresponding key in lv_val variable
if(lv_val.contains("-")){
lv_val = entry.getKey().toString().split("-"); //removing unwanted piece of from string if any
xlm_records.results[count].Address_type[0].value = lv_val[1]; //replace value of particular xml element with unique key
}
else{
xlm_records.results[count].Address_type[0].value = lv_val;
}
}
}
} //IF End for TITLE
count++;
}
// Generating response payload attachment
def newXml = XmlUtil.serialize(xlm_records);
def messageLog = messageLogFactory.getMessageLog(message);
if(messageLog != null){
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment")
messageLog.addAttachmentAsString("XMLresponse:", newXml, "text/plain");
}
//Set output with the upadted xml
message.setBody(newXml);
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |