06-13-2014 09:01 PM
public static String claimAndCompleteTaskByProcessIdAndActorName(String processInstanceId, String actorName) throws JSONException, IOException {
String uri = REST_URI + "/runtime/tasks?candidate=" +actorName + "&size=1&order=asc";
Representation response = getClientResource(uri).get(MediaType.APPLICATION_JSON);
JSONObject object = new JSONObject(response.getText());
System.out.println("OBJECT: " + object);
if (object != null) {
JSONArray arr = (JSONArray) object.get("data");
for (int i = 0; i < arr.length(); i++) {
JSONObject ob = (JSONObject) arr.get(i);
if (ob.get("processDefinitionId").equals(processInstanceId)) {
logger.info("Returned task: " + ob);
if (ob.get("id")!=null) {
String claimUri = REST_URI + "/runtime/tasks/" + ob.get("id");
JSONStringer jsRequest = new JSONStringer();
jsRequest.object().key("action").value("claim");
jsRequest.key("assignee").value(actorName);
jsRequest.endObject();
Representation claimResponse = getClientResource(claimUri).post(jsRequest.toString(), MediaType.APPLICATION_JSON);
JSONObject claimObject = new JSONObject(claimResponse.getText());
System.out.println("Claimed task " + claimObject);
if (claimObject.get("success").equals(true)) {
String completeUri = REST_URI + "/runtime/tasks/" + ob.get("id");
Map<String, String> completeVariable = new HashMap<String, String>();
completeVariable.put("action", "complete");
Representation completeResponse = getClientResource(completeUri).post(completeVariable, MediaType.APPLICATION_JSON);
JSONObject completeObject = new JSONObject(completeResponse.getText());
System.out.println("Completed task " + completeObject);
if (completeObject.get("success").equals(true))
return ob.getString("description");
}
}
}
}
}
return null;
}
06-16-2014 03:49 AM
06-16-2014 04:26 PM
06-17-2014 01:35 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.