We could follow the below code for the different logic covered.
1. Timer is 15 mins in the iflow and if hours = 00,09,12,15,18 only then the router triggers the message.
2. HTTP query formed in the iflow.
3. Current date time - one hour and Current date time - one day.
Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def cal = Calendar.instance;
def date = cal.time;
def dateFormat1 = 'yyyy-MM-dd\'T\'HH:mm:ss';
def datemin = '14';
def dateFormat = '00';
def dayFormat = 'dd';
def curhour =Integer.parseInt(date.format(dateFormat));
// Current datetime hour - 3 hours
def hour =Integer.parseInt(date.format(dateFormat)) -03;
//Current date - 1 day (previous day)
def pastday=Integer.parseInt(date.format(dayFormat)) -1;
def min=Integer.parseInt(date.format(datemin));
def flag;
def curDateTime = "";
curDateTime ='' + date.format(dateFormat1)+'';
def curDatePastOneHour = curDateTime.substring(0,11)+hour+curDateTime.substring(13,curDateTime.length());
def curDatePastOneDay = curDateTime.substring(0,8)+pastday+curDateTime.substring(10,curDateTime.length());
// Need a validation in my logic to send in router, if hours equals 00, only once the flow should run
if (dateFormat=='00' && datemin<='14')
{
flag = '00'
message.setProperty("flag",flag);
// HTTP Query formation to filter the data from current datetime - previous one hour and status Failed
def datequery = "((LogStart ge datetime"+"'"+curDatePastOneHour+"'"+") and (LogEnd le datetime"+"'"+curDateTime+"'"+"))"+" and CustomStatus eq 'FAILED'"
//Set property for the query
message.setProperty("datequery",datequery);
}
else{
flag = '11'
message.setProperty("flag",flag);
}
// Interface runs every 15 mins(Timer) - Logic should run only once at the hours equals 00,09,12,15,18. every hour has 4 times - i.e HH:mm - 00:00, 00:15, 00:30, 00:45
if((dateFormat=='00' && datemin<='14') || (dateFormat=='09' && datemin<='14') || (dateFormat=='12' && datemin<='14') || (dateFormat=='15' && datemin<='14') || (dateFormat=='18' || dateFormat=='21'))
{
flag = '22'
// HTTP Query formation to filter the data from current datetime - previous one day and status is completed
def datequerycount = "((LogStart ge datetime"+"'"+curDatePastOneDay+"'"+") and (LogEnd le datetime"+"'"+curDateTime+"'"+"))"+" and Status eq 'COMPLETED'"
message.setProperty("datequerycount",datequerycount);
}else{
flag = '33'
message.setProperty("flag",flag);
}
message.setProperty("hour",hour);
message.setProperty("curhour",curhour);
message.setProperty("min",min);
return message;
}
1. Timer is 15 mins in the iflow and if hours = 00,09,12,15,18 only then the router triggers the message.
2. HTTP query formed in the iflow.
3. Current date time - one hour and Current date time - one day.
Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def cal = Calendar.instance;
def date = cal.time;
def dateFormat1 = 'yyyy-MM-dd\'T\'HH:mm:ss';
def datemin = '14';
def dateFormat = '00';
def dayFormat = 'dd';
def curhour =Integer.parseInt(date.format(dateFormat));
// Current datetime hour - 3 hours
def hour =Integer.parseInt(date.format(dateFormat)) -03;
//Current date - 1 day (previous day)
def pastday=Integer.parseInt(date.format(dayFormat)) -1;
def min=Integer.parseInt(date.format(datemin));
def flag;
def curDateTime = "";
curDateTime ='' + date.format(dateFormat1)+'';
def curDatePastOneHour = curDateTime.substring(0,11)+hour+curDateTime.substring(13,curDateTime.length());
def curDatePastOneDay = curDateTime.substring(0,8)+pastday+curDateTime.substring(10,curDateTime.length());
// Need a validation in my logic to send in router, if hours equals 00, only once the flow should run
if (dateFormat=='00' && datemin<='14')
{
flag = '00'
message.setProperty("flag",flag);
// HTTP Query formation to filter the data from current datetime - previous one hour and status Failed
def datequery = "((LogStart ge datetime"+"'"+curDatePastOneHour+"'"+") and (LogEnd le datetime"+"'"+curDateTime+"'"+"))"+" and CustomStatus eq 'FAILED'"
//Set property for the query
message.setProperty("datequery",datequery);
}
else{
flag = '11'
message.setProperty("flag",flag);
}
// Interface runs every 15 mins(Timer) - Logic should run only once at the hours equals 00,09,12,15,18. every hour has 4 times - i.e HH:mm - 00:00, 00:15, 00:30, 00:45
if((dateFormat=='00' && datemin<='14') || (dateFormat=='09' && datemin<='14') || (dateFormat=='12' && datemin<='14') || (dateFormat=='15' && datemin<='14') || (dateFormat=='18' || dateFormat=='21'))
{
flag = '22'
// HTTP Query formation to filter the data from current datetime - previous one day and status is completed
def datequerycount = "((LogStart ge datetime"+"'"+curDatePastOneDay+"'"+") and (LogEnd le datetime"+"'"+curDateTime+"'"+"))"+" and Status eq 'COMPLETED'"
message.setProperty("datequerycount",datequerycount);
}else{
flag = '33'
message.setProperty("flag",flag);
}
message.setProperty("hour",hour);
message.setProperty("curhour",curhour);
message.setProperty("min",min);
return message;
}
No comments:
Post a Comment