Execute Job Code Samples

Example 5-1 Java Sample – executeJob.java

//
// BEGIN - Execute a Job (EXPORT_DATA, EXPORT_METADATA, IMPORT_DATA, IMPORT_METADATA, CUBE_REFRESH, ...)
//
public void executeJob(String jobType, String jobName, String parameters) throws Exception {	
	String urlString = String.format("%s/HyperionPlanning/rest/%s/applications/%s/jobs", serverUrl, apiVersion, applicationName);
	JSONObject payload = new JSONObject();
	payload.put("jobName",jobName);
	payload.put("jobType",jobType);
	payload.put("parameters",new JSONObject(parameters));
	String response = executeRequest(urlString, "POST", payload.toString());
	System.out.println("Job started successfully");
	getJobStatus(fetchPingUrlFromResponse(response, "self"), "GET");		
}
//
// END - Execute a Job (EXPORT_DATA, EXPORT_METADATA, IMPORT_DATA, IMPORT_METADATA, CUBE_REFRESH, ...)
//
	

Example 5-2 cURL Sample – ExecuteJob.sh

funcExecuteJob() {
	url="$SERVER_URL/HyperionPlanning/rest/$API_VERSION/applications/$APP_NAME/jobs"
	encodedJobName=$(echo $2 | sed -f urlencode.sed)
	if [ ! -z "$3" ]; then
			param="{\"jobType\":\"$1\",\"jobName\":\"$encodedJobName\",\"parameters\":$3}"
	else
			param="{\"jobType\":\"$1\",\"jobName\":\"$encodedJobName\"}"
	fi
	funcExecuteRequest "POST" $url $param


	output=`cat response.txt`
	status=`echo $output | jq '.status'`
    if [ $status == -1 ]; then
        echo "Started executing job successfully"
		funcGetStatus "GET"
    else
        error=`echo $output | jq '.details'`
        echo "Error occurred. " $error
    fi
	funcRemoveTempFiles "respHeader.txt" "response.txt"
}

Example 5-3 Groovy Sample – ExecuteJob.groovy

def executeJob(jobType, jobName, parameters) {
	def url = new URL(serverUrl + "/HyperionPlanning/rest/" + apiVersion + "/applications/" + appName + "/jobs");
        JSONObject payload = new JSONObject();
        try {	
			if (parameters != null) {
					JSONObject params = new JSONObject();
					def args = parameters.split(';');
					for (int i = 0; i < args.length; i++) {
							if (args[i].indexOf("=") != -1) {
									String[] param = args[i].split("=");
									if (param[0].equalsIgnoreCase("clearData")) {
											params.put("clearData",Boolean.valueOf(param[1]));
									}
									else {
											params.put(param[0],param[1]);
									}
							}
					}
					payload.put("jobName",jobName);
					payload.put("jobType",jobType);
					payload.put("parameters",params);
			}
			else {
					payload.put("jobName",jobName);
					payload.put("jobType",jobType);
			}
	} catch (MalformedURLException e) {
		println "Malformed URL. Please pass valid URL"
		System.exit(0);
	}
	response = executeRequest(url, "POST", payload);
	if (response != null) {
		getJobStatus(fetchPingUrlFromResponse(response, "self"), "GET");
	}
}