Get the list of all dates in a flowfile between the two dates specified using ExecuteScript
We are trying to get the list of all dates in a flowfile between the two dates specified using ExecuteScript. But we are getting empty attribute.
Following is our Groovy code of ExecuteScript for the specified startdate and enddate variable specified:
flowFile = session.get();
if(!flowFile)
return;
DATE_FORMAT = 'dd-MM-yyyy';
sDate = Date.parse(DATE_FORMAT, flowFile.getAttribute("startdate"));
eDate = Date.parse(DATE_FORMAT, flowFile.getAttribute("enddate"));
aDates = "";
Calendar calendar = Calendar.getInstance();
Set aDates = new LinkedHashSet();
numbers = TimeUnit.MILLISECONDS.toDays(Math.abs(eDate - sDate))
for (int i = 1; i <= numbers; i++) {
calendar.setTime( sDate );
calendar.add( Calendar.DATE, i );
}
days.each {
day -> aDates = aDates + day + "\n";
}
flowFile = session.putAttribute(flowFile,"allDates", aDates );
session.transfer(flowFile,REL_SUCCESS)
in outgoing queue we found the attribute aDates is empty String
Please help me.
Thanks in advance.