Groovy Sample – RunRuleBalancing.groovy for Profitability and Cost Management
Prerequisites: json.jar
Common functions: See Appendix C: Common Helper Functions for Groovy.
def runRuleBalancing() {
String modelViewName = null;
JSONObject json = new JSONObject();
json.put("stringDelimiter", "_");
json.put("modelViewName", modelViewName);
String povGroupMember = "2014_January_Actual";
def url;
def response;
String urlString = serverUrl + "/epm/rest/"+ apiVersion + "/applications/" + appName + "/povs/"
+ povGroupMember.trim().replaceAll(" ", "%20") + "/ruleBalance";
urlString = urlString + "?" + "queryParameter=" + json.toString();
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
println "Malformed URL. Please pass valid URL"
System.exit(0);
}
response = executeRequest(url, "GET", null, "application/json");
JSONObject jsonObj = new JSONObject(response);
int resStatus = jsonObj.getInt("status");
if(resStatus == 0) {
println "Rule Balancing ran successfully"
JSONArray itemsArray = jsonObj.getJSONArray("items");
println "Details : " + itemsArray.toString()
} else {
String details = jsonObj.getString("details");
println "Rule Balancing failed. Details : " + details
}
}