use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class ProcessesParser method parseEntry.
@SuppressWarnings("unchecked")
@Override
public ProcessInfo parseEntry(JSONObject entry) {
ProcessInfo processesRest = new ProcessInfo();
processesRest.setId((String) entry.get("id"));
processesRest.setProcessDefinitionId((String) entry.get("processDefinitionId"));
processesRest.setProcessDefinitionKey((String) entry.get("processDefinitionKey"));
processesRest.setStartedAt(WorkflowApiClient.parseDate(entry, "startedAt"));
processesRest.setEndedAt(WorkflowApiClient.parseDate(entry, "endedAt"));
processesRest.setDurationInMs((Long) entry.get("durationInMs"));
processesRest.setDeleteReason((String) entry.get("deleteReason"));
processesRest.setBusinessKey((String) entry.get("businessKey"));
processesRest.setSuperProcessInstanceId((String) entry.get("superProcessInstanceId"));
processesRest.setStartActivityId((String) entry.get("startActivityId"));
processesRest.setStartUserId((String) entry.get("startUserId"));
processesRest.setEndActivityId((String) entry.get("endActivityId"));
processesRest.setCompleted((Boolean) entry.get("completed"));
processesRest.setVariables((Map<String, Object>) entry.get("variables"));
processesRest.setItems((Set<String>) entry.get("item"));
if (entry.get("processVariables") != null) {
List<Variable> processVariables = new ArrayList<Variable>();
JSONArray variables = (JSONArray) entry.get("processVariables");
for (int i = 0; i < variables.size(); i++) {
JSONObject variableJSON = (JSONObject) variables.get(i);
Variable variable = new Variable();
variable.setName((String) variableJSON.get("name"));
variable.setType((String) variableJSON.get("type"));
variable.setValue(variableJSON.get("value"));
processVariables.add(variable);
}
processesRest.setProcessVariables(processVariables);
}
return processesRest;
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testDeleteTaskItem.
@Test
@SuppressWarnings("unchecked")
public void testDeleteTaskItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
RequestContext otherContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
// Create test-document and add to package
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
ProcessInfo processInfo = startAdhocProcess(requestContext, docNodeRefs);
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
assertNotNull(task);
activitiProcessEngine.getTaskService().setAssignee(task.getId(), null);
try {
TasksClient tasksClient = publicApiClient.tasksClient();
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item as admin
JSONObject createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
JSONObject result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
JSONObject itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
publicApiClient.setRequestContext(adminContext);
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with candidate user
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPerson);
publicApiClient.setRequestContext(otherContext);
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with not involved user
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherPerson);
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
// delete item with user from candidate group with no assignee
List<MemberOfSite> memberships = getTestFixture().getNetwork(otherContext.getNetworkId()).getSiteMemberships(otherContext.getRunAsUser());
assertTrue(memberships.size() > 0);
MemberOfSite memberOfSite = memberships.get(0);
String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherContext.getRunAsUser());
activitiProcessEngine.getTaskService().addCandidateGroup(task.getId(), group);
publicApiClient.setRequestContext(otherContext);
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with user from candidate group with assignee
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
publicApiClient.setRequestContext(requestContext);
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
publicApiClient.setRequestContext(requestContext);
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// invalid task id
publicApiClient.setRequestContext(requestContext);
try {
tasksClient.deleteTaskItem("fakeid", docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// invalid item id
try {
tasksClient.deleteTaskItem(task.getId(), "fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item from completed task
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processInfo.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testTaskStateTransitions.
@Test
@SuppressWarnings("unchecked")
public void testTaskStateTransitions() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInstance = startAdhocProcess(requestContext, null);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
// Unclaimed to claimed
JSONObject taskBody = new JSONObject();
taskBody.put("state", "claimed");
List<String> selectedFields = new ArrayList<String>();
selectedFields.addAll(Arrays.asList(new String[] { "state", "assignee" }));
JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("claimed", result.get("state"));
// claimed to unclaimed
taskBody = new JSONObject();
taskBody.put("state", "unclaimed");
result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
assertEquals("unclaimed", result.get("state"));
} finally {
cleanupProcessInstance(processInstance.getId());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testSetOutcome.
@Test
@SuppressWarnings("unchecked")
public void testSetOutcome() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInf = startReviewPooledProcess(requestContext);
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInf.getId()).singleResult();
TasksClient tasksClient = publicApiClient.tasksClient();
activitiProcessEngine.getTaskService().saveTask(task);
Map<String, String> params = new HashMap<String, String>();
params.put("select", "state,variables");
HttpResponse response = tasksClient.update("tasks", task.getId(), null, null, "{\"state\":\"completed\",\"variables\":[{\"name\":\"wf_reviewOutcome\",\"value\":\"Approve\",\"scope\":\"local\"},{\"name\":\"bpm_comment\",\"value\":\"approved by me\",\"scope\":\"local\"}]}", params, "Failed to update task", 200);
HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().includeTaskLocalVariables().singleResult();
String outcome = (String) historyTask.getTaskLocalVariables().get("bpm_outcome");
assertEquals("Approve", outcome);
}
use of org.alfresco.rest.workflow.api.model.ProcessInfo in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testGetTaskVariablesReview.
@Test
public void testGetTaskVariablesReview() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
ProcessInfo processInstance = startParallelReviewProcess(requestContext);
try {
Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).taskAssignee(requestContext.getRunAsUser()).singleResult();
assertNotNull(task);
TasksClient tasksClient = publicApiClient.tasksClient();
JSONObject variables = tasksClient.findTaskVariables(task.getId());
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
assertNotNull(list);
JSONArray entries = (JSONArray) list.get("entries");
assertNotNull(entries);
// Check pagination object for size
JSONObject pagination = (JSONObject) list.get("pagination");
assertNotNull(pagination);
assertEquals(42L, pagination.get("count"));
assertEquals(42L, pagination.get("totalItems"));
assertEquals(0L, pagination.get("skipCount"));
assertFalse((Boolean) pagination.get("hasMoreItems"));
} finally {
cleanupProcessInstance(processInstance.getId());
}
}
Aggregations