In a previous article we talked about using Groovy to execute the PING_SERVER service of our SOA enabled Content Server. Interesting, but fairly useless you might say. Let's see how we can conduct a search using Groovy and then access specific metadata from those search results.
You may want to keep the RIDC JavaDoc link handy as you explore Groovy Integration further.
First, the script, and then some discussion.
// Import needed classes from Remote Intradoc Jar
// Create the client for request/response, connect directly to server
// Create a user/security context
// Setup the request, search for two pieces of content
// Get the response
// Dump out the local data of the response
// Dump out the names of the resultsets in the response
// Dump out dDocTitle for each piece of content in the response
// Wrap it up!
In this particular case we are using the "each" closure function. Here is an excerpt from the sample script:
See that "each" statement in the second line? The word each followed by curly brackets forges the wrapping closure and the code inside is what becomes executed when the closure is invoked. In this case, our closure is invoked for each key in the Key Set of the Local Data collection. Within the closure you can use the "it" variable (as in iterator) to access each key.
If you have something against the name "it" for the variable you can alter the variable name. As an example, let's change the syntax so the variable will be named "key", try this:
This is also very helpful when using a closure within a closure. An example? Sure. What if you wanted to loop the resultsets and print the value for each column for each row of each resultset? You're code might use nested closures and look something like this:
Additional Sample Scripts
Here are two additional Groovy Scripts you can download and try out: