We have used the REST API for fetching, updating, and adding actions to the business process and will also use it when we want to work with tasks. To access a task, we have to use the GET method with the URL /runtime/tasks
and perform the following steps:
/runtime/tasks
, as shown in the following screenshot:getTasks
method in the Process_Deployment
class, which will provide the list of tasks, as shown in the following code:public static JSONArray getTasks() throws JSONException, IOException { String uri = REST_URI + "/runtime/tasks"; Representation response = getClientResource(uri).get(MediaType.APPLICATION_JSON); JSONObject object = new JSONObject(response.getText()); if (object != null) { JSONArray taskArray = (JSONArray) object.get("data"); return taskArray; } return null; }
.. /runtime/tasks/{taskId}
in combination with the GET
method. To execute the task, we need it to be claimed by a specific person using the POST
method. For that, we need to set values for the action
and assignee
parameters. We can create the claimTask
method in the Process_Deployment
class as follows:public static void claimTask(int id) throws JSONException, IOException { String uri = REST_URI + "/runtime/tasks/" + id; JSONObject my_data = new JSONObject(); my_data.put("action", "claim"); my_data.put("assignee", "kermit"); Representation response = getClientResource(uri).post(my_data); }
action
parameter to complete
along with the POST
method, as shown in the following code:public static void completeTask(int id) throws JSONException, IOException { String uri = REST_URI + "/runtime/tasks/" + id; JSONObject my_data = new JSONObject(); my_data.put("action", "complete"); Representation response = getClientResource(uri).post(my_data); }