Run Extract from EDMCS to Oracle (E)PBCS using Groovy & REST API

We had an requirement where-in we had to extract few of the details from EDMCS to PBCS for calculation purpose and were looking to automate the extraction process. Our first inclination was towards using pipeline feature, however, pipeline doesn't yet support extract from EDMCS. That's when we decided to use Groovy.

The first step is to create the connection in PBCS for EDMCS & PBCS application (not going in details on how to create it various blogs can be found for the same) 

Below is the logic for running the extract from EDMCS

Step 1 - Connect to EDMCS and execute the Extract.

/*Calling EDMCS REST API to run the extract*/
HttpResponse<String> jsonResponse = operation.application.getConnection("EDMCS").post("/rest/v1/dimensions/byName/extract")
.body(json([
"applicationName": "EDMCS Application Name",
    "dimensionName": "EMDCS Dimension Name",
    "fileName": "Provide the Extract File Name",
    "extractName" : "Extract Name"
]))
.asString();
if (!(200..299).contains(jsonResponse.status)) 
throwVetoException("Error occured: $jsonResponse.statusText")

we can monitor the status of the extract using the below code

ReadContext ctx = JsonPath.parse(jsonResponse.body)

String jobUrl = ""

ctx.read('$.links').each {  

if(it['rel'] == "results") {

jobUrl = it['href']

}

}


String jobID

jobID = jobUrl.split("/")[-1]


jobUrl = jobID


String Status = "RUNNING"


if(Status == "RUNNING") {

Status = checkResponse("EDMCS", jobUrl)

    for(long delay = 50; Status == "RUNNING"; delay = Math.min(1000, delay * 2)) {

        sleep(delay)

        Status = checkResponse("EDMCS", jobUrl)

    }

    println("${Status == 'COMPLETED' ? "successful" : "failed"}.\n")

}


if(Status == "COMPLETED") {

println("Process completed...")

}


String checkResponse (String connectionName, String jobUrl) {

HttpResponse<String> pingResponse = operation.application.getConnection("EDMCS").get("/rest/v1/jobRuns/$jobUrl").asString()

    println(pingResponse.body)

    println(JsonPath.parse(pingResponse.body).read('$.status'))

    return JsonPath.parse(pingResponse.body).read('$.status')

}

 The above generates the file in the EDMCS temp location which needs to be downloaded and uploaded to PBCS server.

Step 2 - Downloads the file content from EDMCS server 

jsonResponse = operation.application.getConnection("EDMCS").get("/rest/v1/files/staging/EDMCS File Name Provided in the Step 1")

.header("Content-Type", "application/octet-stream")

.asString();

if (!(200..299).contains(jsonResponse.status)) 

throwVetoException("Error occured: $jsonResponse.statusText")

Step 3 - Upload the file content to PBCS inbox/outbox directory

HttpResponse<String> apendFile = operation.application.getConnection("PLanning Connection Name")

.post("/interop/rest/11.1.2.3.600/applicationsnapshots/File Name to be in inboxoutbox directory/contents")

.header("Content-Type", "application/octet-stream")

.body(jsonResponse.body)

.asString()


Once the file is in the inbox/outbox directory one can use csvIterator to read the file and perform different actions as required. 

The above shows how can we extract the details from EDMCS to PBCS using Groovy & REST API.

 

Comments