You are on page 1of 1

// compare given date from current date and update the xml AND SET PROPERTY

import com.sap.gateway.ip.core.customdev.util.Message;
import java.time.LocalDate;
import groovy.xml.MarkupBuilder;

def Message processData(Message message) {


def body = message.getBody(String);
def xml = new XmlSlurper().parseText(body)

// extract date from EndDate tag


def endDate = xml.EndDate.text()
endDate = endDate.split('T')[0]

def currDate = LocalDate.now()


//convert/parse endDate to LocalDate
endDate = LocalDate.parse(endDate)

//updating status
def status = (endDate.isEqual(currDate) || endDate.isAfter(currDate)) ?
"COMPLETED" : "PENDING"

// creating markup builder


def writer = new StringWriter()
def builder = new MarkupBuilder(writer)

//updating Status tag in xml


xml.Status[0] = status

// creating xml using markup builder


builder.EmployeeTime {
UserId(xml.UserId.text())
Status(xml.Status.text())
EndDate(xml.EndDate.text())
}

// GETTING AND SETTING PROPERTY


def property = message.getProperties();
def valProp = property.get("Status")
println ("status " +valProp)
message.setProperty("Status",status);

println writer
message.setBody(writer.toString())
return message;
}

You might also like