PROBLEM
There is plenty information regarding the use of Groovy on the Groovy website and in various Groovy books. In most cases a developer using Groovy with Skyway Builder will want to interact with the data (stored in variables) that exists in the respective component. For example if a developer is using Groovy in the implementation of a Controller, she's likely going to need to access the model variables. If the developer is using Groovy in the implementation of an operation, she's likely going to need access to input, output, and operation variables.
SOLUTION
Since the Skyway modeling artifacts are being generated to standard java code, there really isn't anything special with accessing data access objectd in variables from the Invoke Groovy Step. Variables within the repsective components are implicitly accessible to the Invoke Groovy Step.
HOW IT WORKS
Here's an example of some Groovy code that's accessing operation variables. There are several variables defined in the GetFlickrContent operation of the the FlickrViewer sample project.
As shown in the following code that's used in the Groovy step, the service variables are natively available to the Groovy script.
Example 3.4. Accessing data using Groovy
System.out.println("inFeed: "+inFeed);
def xmlFeed = new XmlParser().parse(inFeed);
def idx = 0;
xmlFeed.channel.item.each { item ->
idx++;
def title = item.title.text()
currentEntry = new flickrviewer.domain.Entry();
currentEntry.id = idx;
currentEntry.flickrlink = item.link.text()
currentEntry.imagelink = item.media.'@url'.text()
System.out.println("DEBUG: "+item.'media:content'.text());
currentEntry.title = item.title.text()
currentEntry.content = item.description.text()
System.out.println("Title: "+currentEntry.title);
System.out.println("Link: "+currentEntry.imagelink);
entries.add(currentEntry);
}
RELATED RECIPES