Groovy Sample – CreateFlatFileApplication.groovy for Profitability and Cost Management
Prerequisites: json.jar
Common functions: See Appendix C: Common Helper Functions for Groovy.
def createFlatFileApplication() {
JSONObject json = new JSONObject();
json.put("description", "Flat file based application");
json.put("ruleDimensionName", "Rule");
json.put("balanceDimensionName", "Balance");
String urlString = serverUrl + "/epm/rest/"+ apiVersion + "/fileApplications/" + "BksML13";
def url;
try {
url = new URL(urlString)
} catch (MalformedURLException e) {
println "Malformed URL. Please pass valid URL"
System.exit(0);
}
String response = executeRequest(url, "POST", json.toString(), "application/json")
JSONObject jsonObj = new JSONObject(response);
int resStatus = jsonObj.getInt("status");
if(resStatus == 0) {
println "Application created successfully"
} else {
println "Application creation failed"
}
}