on 2025 Feb 10 2:08 PM
Hi Experts,
I need to ensure that the personal_information section is included in the payload only when there is a Hire, Rehire, or Subsidiary Transfer event or if any delta changes have been made to the personal_information portlet. Otherwise, this section should be filtered out before further processing via message mapping.
The relevant events can be identified using the following XPaths:
queryCompoundEmployeeResponse/CompoundEmployee/person/employment_information/job_information/event='H'
queryCompoundEmployeeResponse/CompoundEmployee/person/employment_information/job_information/event='R'
queryCompoundEmployeeResponse/CompoundEmployee/person/employment_information/job_information/event='6'
Currently, I have implemented this logic using two Groovy scripts, but I am looking for an optimized single Groovy script solution to achieve the same outcome.
I would appreciate any guidance or alternative approaches to accomplish this efficiently.
First Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.XmlUtil;
import groovy.util.XmlParser;
import groovy.util.Node;
import groovy.xml.MarkupBuilder;
import java.text.SimpleDateFormat;
import java.util.Date;
def Message processData(Message message) {
def body = message.getBody(Reader)
def Root = new XmlParser().parse(body)
def parent = "";
def action = "";
map = message.getProperties();
def Iflow_LSRD = map.get("interfaceLastRunTime").substring(0,10);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date LSRD = sdf.parse(Iflow_LSRD);
Root.CompoundEmployee.each {CE ->
CE.person.employment_information.job_information.each{JOB ->
action = JOB.action.text();
event = JOB.event.text();
event_reason = JOB.event_reason.text();
event_previous = JOB.event_previous.text();
event_reason_previous = JOB.event_reason_previous.text();
emplStatus_previous = JOB.emplStatus_previous.text();
last_modified_on = JOB.last_modified_on.text().substring(0,10);
Date LMD = sdf.parse(last_modified_on);
if(((event == 'H') && (LMD >= LSRD)) || ((event == 'R') && (LMD >= LSRD)) || ((event == 'GA') && (LMD >= LSRD)))
{
CE.appendNode("EventFlag", "X");
}
action = "";
}
}
message.setBody(XmlUtil.serialize(Root));
return message;
}Second Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.XmlUtil;
import groovy.util.XmlParser;
import groovy.util.Node;
import groovy.xml.MarkupBuilder;
import java.text.SimpleDateFormat;
import java.util.Date;
def Message processData(Message message) {
def body = message.getBody(Reader)
def Root = new XmlParser().parse(body)
def parent = "";
map = message.getProperties();
def Iflow_LSRD = map.get("interfaceLastRunTime").substring(0,10);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date LSRD = sdf.parse(Iflow_LSRD);
def dnicard_code = " 1";
def arncard_code = " 6";
def pascard_code = " 2";
Root.CompoundEmployee.each {CE ->
/* CE.person.employment_information.job_information.each{JOB ->
action = JOB.action.text();
event = JOB.event.text();
event_reason = JOB.event_reason.text();
event_previous = JOB.event_previous.text();
event_reason_previous = JOB.event_reason_previous.text();
emplStatus_previous = JOB.emplStatus_previous.text();
last_modified_on = JOB.last_modified_on.text().substring(0,10);
Date LMD = sdf.parse(last_modified_on);
if(((event == 'H') && (LMD >= LSRD)) || ((event == 'R') && (LMD >= LSRD)) || ((event == 'GA') && (LMD >= LSRD)))
{
CE.appendNode("EventFlag", "X");
}
action = "";
} */
def FlagCheck = CE.EventFlag.text();
CE.person.personal_information.each{PER ->
/* FlagCheck = PER.parent();
check = FlagCheck.EventFlag.text(); */
def action = PER.action.text();
def first_name_previous = PER.first_name_previous.text();
def last_name_previous = PER.last_name_previous.text();
def gender_previous = PER.gender_previous.text();
def salutation_previous = PER.salutation_previous.text();
def marital_status_previous = PER.marital_status_previous.text();
def last_modified_on = PER.last_modified_on.text().substring(0,10);
Date LMD = sdf.parse(last_modified_on);
if((action == 'INSERT') ||(FlagCheck == 'X') || ((first_name_previous != null ) && (first_name_previous.trim().length() > 0))|| ((last_name_previous != null ) && (last_name_previous.trim().length() > 0)) || ((gender_previous != null ) && (gender_previous.trim().length() > 0))||((salutation_previous != null ) && (salutation_previous.trim().length() > 0))||
((marital_status_previous != null ) && (marital_status_previous.trim().length() > 0))||
(LMD >= LSRD))
{
}
else
{
parent = PER.parent();
parent.remove(PER);
parent = "";
}
action = "";
}
CE.person.national_id_card.each{NAT ->
def action = NAT.action.text();
def card_type = NAT.card_type.text();
def national_id = NAT.national_id.text();
def card_type_previous = NAT.card_type_previous.text();
def national_id_previous = NAT.national_id_previous.text();
def last_modified_on_NAT = NAT.last_modified_on.text().substring(0,10);
Date LMD_NAT = sdf.parse(last_modified_on_NAT);
if((action == 'INSERT') || ((card_type_previous != null ) && (card_type_previous.trim().length() > 0))|| ((national_id_previous != null ) && (national_id_previous.trim().length() > 0)) || (LMD_NAT >= LSRD))
{
if((national_id != '') && (card_type == 'DNI')){
national_id = national_id.concat(dnicard_code);
NAT.appendNode("national_id", national_id);
}
if (national_id != '' && card_type == 'NIE'){
national_id = national_id.concat(arncard_code);
NAT.appendNode("national_id", national_id);
}
if (national_id != '' && card_type == 'PAS'){
national_id = national_id.concat(pascard_code);
NAT.appendNode("national_id", national_id);
}
}
else
{
parent = NAT.parent();
parent.remove(NAT);
parent = "";
}
action = "";
}
}
message.setBody(XmlUtil.serialize(Root));
return message;
}Regards,
Pavan
Request clarification before answering.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.