In this post we will try to cover the basics of using PBCS / EPBCS REST APIs using Groovy Scripts.

Most of you may have used EPM Automate utility in your day to day activities. Although it is a great tool, it has its limitations. So lets see how we can use PBCS REST APIs.
Check my out previous post on testing the REST APIs using SOAP UI. For this post I am assuming you are using Widows OS.

Install and Configure Java

The first step is to install Java on your system. Head over to Oracle to get the latest version of Java SDK. Accept the license agreement and download the software.
Once the software is download, install Java on your system. You can keep the default options.

In my case I downloaded the 64 bit version as shown in the below screenshot.

Download Java

 

Once you install Java, make sure to add

  1. Add JAVA_HOME to Environment Variables
  2. Edit your “Path” environment variable to include the path to Java folder

Here is a link explaining how to complete the above two configurations. Make sure to restart your system after making changes to the environment variables.

Once you log back in open command prompt and type “java -version” and you should see the version displayed as shown below.

Check Java Version

Install and Configure Groovy

The second step is to install Groovy. Head over to Groovy Language website. Make sure to scroll down and download the “Windows Installer“.
You can keep all the default options while installing the software.

 

Groovy Windows Installer

 

The next step is to download java-json.jar file. Head over to Java2s website to download the file. Copy the java-json.jar fileto the Groovy Library folder.
In my case it was “C:\Program Files (x86)\Groovy\Groovy-3.0.0\lib“.

Now you are all set to start invoking PBCS REST APIs using Groovy.

The Groovy Console

Open Groovy console from the Windows start menu. The console consists of 3 main areas

I also want you to familiarize with “Execute” and “Clear” buttons as shown in the below image.

The first Program

Oracle has provided some excellent examples and sample code for using PBCS REST APIs using Groovy. Head over to Oracle Docs to take a look at the details.
We will be working with “List Files” function. Before we start, lets look at the anatomy of a groovy script.

Import Section

The import section consists of any external files (libraries) that are needed to execute the program. In our example we will include the below:

[java]
import org.json.JSONObject
import groovy.json.JsonSlurper
[/java]

Variables

I am sure you all know what a variable is. So let me dive right in and explain the variables that we will be using

serverUrl : stores the planning url. Make sure to include the port number at the end
username: PBCS / EPBCS login user name. The format to be followed is “domain.username”
password: PBCS / EPBCS login password
apiVersion: default to V3
appName: PBCS/EPBCS Application Name

Here is the sample code. To find the current version of Migration APIs click here.

[java]

serverUrl="https://planning-yoururl.oraclecloud.com:443"
username="a123456.adminuser"
password="mypassword"
apiVersion="11.1.2.3.600"
appName="Vision"

[/java]

Methods or Functions

We will re-use the functions and methods from Oracle’s documentation. Lets grab the code for the following:

You are all set!! Now comes the fun part of seeing the results. Before we go ahead and execute the code, lets add the below line to invoke the process

[java]
listFiles();
[/java]

Click the “Execute” button, take a moment to enjoy the first Groovy Script.

Groovy Script Results

I hope you were able to get the output. If you are having issues, don’t worry. Feel free to comment or connect with me on Twitter or Linkedin.

I will try to include few sample scripts for executing Business Rules, Data Copy etc in the coming weeks. Let me know if you have questions. Happy Learning!!!

I was inspired to try Groovy scripting by reading the following blogs:

Perficient Blog
Jake Turrell’s Blog

 

Leave a Reply

Your email address will not be published. Required fields are marked *