Monday, February 15, 2016

Run Groovy from Java

Why do we want to mix Groovy with Java:
One common requirement in java is to keep core logic in groovy and then evaluate it at runtime. This gives a flexibility as groovy can be referred from xml file, property file or database. That way customer can change groovy anytime and without deployment java code can start working with new groovy expression.

One common example could be calculating salary components. We definitely want to give customer a flexibility to write his own logic to determine salary components. We don't want to hard code that logic in java code. In such cases we can store groovy expression in database table and read it at runtime and evaluate it from java. End user can change groovy expressions anytime in database.

Basic requirement from groovy to java integration would be
a. Somehow we should be able to pass java variables to groovy code. These are called environment variables.
b. Somehow we should be able to parse and run groovy from java. We have Groovy apis for that.
c. Somehow values calculated by groovy should be passed back to java.

Below code show how we can do it.

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;

import java.util.HashMap;
import java.util.Map;

public class GroovyUtil {
    public GroovyUtil() {
    public static Map evaluateGroovy(Map paramMap,String scriptText){
       System.out.println("Evaluating groovy: " + scriptText);     
        System.out.println("Input Map: " + paramMap);

       //Environment variables passed to groovy using Binding.
        Binding binding = new Binding(paramMap);
        GroovyShell shell = new GroovyShell();       
        Script script = shell.parse(scriptText);

        //bindings.getVariables() returns all variables of groovy including input and other local variables
        System.out.println("Output Map: " + binding.getVariables());      
        return binding.getVariables();
    public static void main(String[] args){
        String scriptText = "println('Sctipt execution Started');\n" +
        "    sum = a + b;\n" +
        "    println('script finished');";
        Map inputMap = new HashMap();
        Map outputMap = evaluateGroovy(inputMap,scriptText);

Output looks like
Evaluating groovy: println('Sctipt execution Started');
    sum = a + b;
    println('script finished');
Input Map: {b=20, a=10}
Sctipt execution Started
script finished
Output Map: {b=20, a=10, sum=30}
{b=20, a=10, sum=30}

For such kind of code there must be an understanding between groovy and java code about input and output variable names.

Sunday, February 14, 2016

Taleo: Installing Taleo (TCC) Client

This blog is first in my upcoming blogs of Taleo (TCC). In this I would like to show how we can install Taleo Client TCC.

2. Sign in / Register. (OTN SSO username/password will be used)  
3. Select Product "Oracle Taleo Plateform Cloud Service - Connect" and Plateform Window-32

    Select Continue
4. Read and Accept ‘Terms and Conditions’

5. Download TCC Application Datamodel and TCC Application Installer for windows

6. Once downloaded unzip both zip files. They both contains an exe file each.

7. Install ‘Taleo Connect Client Application Data Model ( for Microsoft Windows.exe’ first. NOTE: its installation location. It will be required in second installation.

8. Install ‘Taleo Connect Client Application Installer ( for Microsoft Windows.exe’. Provide pip location as the location of where you installed datamodel.

9. Launch Taleo Client.
10. If you are launching first time, you need to pint Taleo server. Select Product and provide, Host Port (generally 443 for https), username/password

Tuesday, February 9, 2016

ADF 12c: Debugging Groovy

Oracle has provided a new feature in 12.1.3 to debug a groovy code. Feature is very much required and very simple to use.

Ideally you just need to select Groovy Line at design time and then run debugger. Jdeveloper will stop while running that line of groovy and you will be able to check values of local variables in Jdeveloper data window.

One thing that you need to notice is Dont use source mode to select groovy expression. Use Declarative mode (overview tab). In below diagram I am showing how EO validation is selected.

As a result when you run debugger you will see application stops when groovy is getting executed and you can go line by line from there, while viewing local variables in data window of debugger.

Even you get handle of this variable, which can be used to view other values.

Simple but very very useful feature in ADF. So no more println(varname)