Examples to inspire ideas for new capabilities and features that can be achieved with Server-side EPM Automate with Groovy
Read my post How to run Server-side EPM Automate with Groovy to get the basics and fundamentals before you dive into the examples.
The examples in this post are meant to demonstrate very simple use cases to give you an idea of how to use the methods available in Groovy related to
- executing EPM Automate commands; and
- retrieving the status/output
Example 1: Exporting Data Security to a CSV file
Forget about writing command line instructions or running .BAT files in the command prompt to extract the security in a CSV file. You can launch a simple Groovy rule and download the file from your Cloud instances Inbox/Outbox.
/*RTPS:*/
String timestamp = (new Date()).format("yyyyMMdd_HHmmss")
class ConnectionDetails {
static String username = "<<USERNAME>>"
static String password = "<<PASSWORD>>"
static String url = "<<URL>>"
}
EpmAutomate automate = getEpmAutomate()
EpmAutomateStatus status = automate.execute("login", ConnectionDetails.username, ConnectionDetails.password , ConnectionDetails.url)
if (status.getStatus() != 0) {
throwVetoException("Login status: ${status.getOutput()}")
}
status = automate.execute("exportAppSecurity", "secFile_${timestamp}.csv")
if (status.getStatus() != 0) {
throwVetoException("Export Security status: ${status.getOutput()}")
}
status = automate.execute("logout")
if (status.getStatus() != 0) {
throwVetoException("Logout status: ${status.getOutput()}")
}
The Groovy script and the jobs that it triggers using EPM Automate can be viewed in the Jobs console.
It generates the secFile (I like to keep the same name as the legacy output we’ve used for many years now) in a CSV format.
This file can then easily be download from your cloud interface if necessary.
Flipping the Use Case: Importing Security
The reverse is also very easy to deploy, where a pre-formatted CSV can be uploaded to the server directly, and a Groovy script designed to Import Security can use this file to update the artifact security.
Example 2: Viewing the List of Files
This example demonstrates how to use the getItemList with EPM Automate commands to generate or display a list.
/*RTPS:*/
class ConnectionDetails {
static String username = "<<USERNAME>>"
static String password = "<<PASSWORD>>"
static String url = "<<URL>>"
}
EpmAutomate automate = getEpmAutomate()
EpmAutomateStatus status = automate.execute("login", ConnectionDetails.username, ConnectionDetails.password , ConnectionDetails.url)
if (status.getStatus() != 0) {
throwVetoException("Login status: ${status.getOutput()}")
}
status = automate.execute("listFiles")
if (status.getStatus() != 0) {
throwVetoException("List Files status: ${status.getOutput()}")
}
def filesList = status.getItemsList()
filesList.eachWithIndex() { file, idx ->
println("${idx+1}: ${file}")
}
status = automate.execute("logout")
if (status.getStatus() != 0) {
throwVetoException("Logout status: ${status.getOutput()}")
}
… the Groovy script runs successfully …
This will return an Array/List object with the contents (in our case an array of filenames that are available on the server).
1: secFile.csv
2: users.csv
Applying this to a Use-Case: Checking if the File Exists
This can be pretty useful if you want to check if a file already exists in case you want to use a pre-defined name for a file that is the source for loading data.
These two examples show the usage of all the methods that you need to know in order to execute server-side EPM Automate commands from a Groovy script
- getEPMAutomate
Retrieves an instance of EpmAutomate that can then be used to invoke EPM Automate commands - execute
This method of EpmAutomate class is used to execute an EPM Automate command. Returns an instance of EpmAutomateStatus class - getStatus
This method of EPMAutomateStatus class returns the execution status returned by the command. Return value 0 indicates success while a non-zero value means command failure - getOutput
This method of EPMAutomateStatus class returns the string output of the command - getItemsList
This method of EPMAutomateStatus class returns the list output of the command
A few lines of code in Groovy and you can execute any EPM Automate command (almost!). It is up to your creativity how you leverage the ability to execute EPM Automate commands on the server-side, to create new functionality that makes end-user or admin tasks more intuitive and easier.