PBCS REST APIs Using Groovy Scripts

PBCS REST APIs Using Groovy Scripts

In this post, we’ll cover the basics of using PBCS/EPBCS REST APIs using Groovy Scripts.

With the release of the REST APIs, you now have the ability to develop robust applications using Java, Groovy, and CURL.  Let’s see how we can use PBCS REST APIs.  

For the purposes of this post, it is assumed that you are using a Windows Operating System, though Groovy can also be installed on Mac/Linux.

Here is a summary of the topics we’ll cover in this post:

  • Install and Configure Java
  • Install and Configure Groovy
  • Groovy Console
  • The First Groovy Program

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, keeping the default options.

In my case, I downloaded the 64-bit version, as shown below.

 Once Java is installed, make sure to:

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

For further explanation on how to complete the above two configurations, click here. Be sure to restart your system after making changes to the environment variables.

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

Install and Configure Groovy

The second step in this process is to install Groovy. Head over to the Groovy Language website, scroll down, and download the “Windows Installer“, keeping all default values.

Next, download the java-json.jar file. Head over to the Java2s website to download the file. Copy the java-json.jar file to the Groovy Library folder.

In my case, it is “C:\Program Files (x86)\Groovy\Groovy-3.0.0\lib”.

Now, you’re all set to start invoking PBCS REST APIs using Groovy!

The Groovy Console

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

  • Toolbar
  • Editor – Write the code here
  • Output Area – Check error messages and output messages here

You should also become familiar with the “Execute” and “Clear” buttons, as shown in the image below.

The First Groovy Program

Oracle has provided some excellent examples and sample code for using PBCS REST APIs using Groovy. Head over to Oracle Docs for details. We’ll be working with the “List Files” function. Before we start, though, let’s 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’ll include the following:

import org.json.JSONObject
import groovy.json.JsonSlurper

Variables

Assuming you are already familiar with variables, allow me to dive right in and explain the variables we’ll be using:

  • serverUrl:  Stores the planning URL. Be 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.

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

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

Methods or Functions

We’ll re-use the functions and methods from Oracle’s documentation. Grab the code for the following:

  • fetchResponse ( )
  • fetchJobStatusFromResponse ( )
  • executeRequest ( )
  • listFiles ( )

You’re all set!

Now for the fun part – seeing the results. Before we go ahead and execute the code, let’s add the following line to invoke the process:

listFiles();

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

As always, don’t hesitate to leave us a comment below with any questions.  Thanks for stopping by!

*You might also want to check out an earlier post, Testing PBCS REST APIs Using SoapUI.

Tagged with: , , , , , , , ,

Leave a Reply

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

*