use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstances.
@Test
public void testGetProcessInstances() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
final ProcessInfo process2 = startAdhocProcess(requestContext, null);
final ProcessInfo process3 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
Map<String, ProcessInfo> processMap = new HashMap<String, ProcessInfo>();
for (ProcessInfo processRest : processList.getList()) {
processMap.put(processRest.getId(), processRest);
}
assertTrue(processMap.containsKey(process1.getId()));
assertTrue(processMap.containsKey(process2.getId()));
assertTrue(processMap.containsKey(process3.getId()));
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
assertNull(processList.getList().get(0).getProcessVariables());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc2')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "2");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(2, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "3");
paramMap.put("skipCount", "1");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(2, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "5");
paramMap.put("skipCount", "2");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
paramMap.put("maxItems", "5");
paramMap.put("skipCount", "5");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'completed')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'any')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'active')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(status = 'active2')");
try {
processList = processesClient.getProcesses(paramMap);
fail();
} catch (PublicApiException e) {
// expected exception
}
// Test the variable where-clause
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority = 'd_int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority = 'd:int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority > 'd:int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority >= 'd:int 1')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority < 'd:int 5')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority <= 'd:int 4')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(3, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/bpm_priority = 'd_int 5')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
// test with date variable
Calendar dateCal = Calendar.getInstance();
Map<String, Object> variablesToSet = new HashMap<String, Object>();
variablesToSet.put("testVarDate", dateCal.getTime());
activitiProcessEngine.getRuntimeService().setVariables(process1.getId(), variablesToSet);
paramMap = new HashMap<String, String>();
paramMap.put("where", "(variables/testVarDate = 'd_datetime " + ISO8601DateFormat.format(dateCal.getTime()) + "')");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
// include process variables as well
paramMap = new HashMap<String, String>();
paramMap.put("where", "(includeVariables=true)");
paramMap.put("maxItems", "1");
paramMap.put("skipCount", "0");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
paramMap.put("maxItems", "1");
paramMap.put("skipCount", "0");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(1, processList.getList().size());
ProcessInfo processInfo = processList.getList().get(0);
assertNotNull(processInfo.getProcessVariables());
boolean foundDescription = false;
boolean foundAssignee = false;
for (Variable variable : processInfo.getProcessVariables()) {
if ("bpm_description".equals(variable.getName())) {
assertEquals("d:text", variable.getType());
assertNull(variable.getValue());
foundDescription = true;
} else if ("bpm_assignee".equals(variable.getName())) {
assertEquals("cm:person", variable.getType());
assertEquals(requestContext.getRunAsUser(), variable.getValue());
foundAssignee = true;
}
}
assertTrue(foundDescription);
assertTrue(foundAssignee);
// include process variables with paging
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
paramMap.put("maxItems", "3");
paramMap.put("skipCount", "1");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(2, processList.getList().size());
processInfo = processList.getList().get(0);
assertNotNull(processInfo.getProcessVariables());
foundDescription = false;
foundAssignee = false;
for (Variable variable : processInfo.getProcessVariables()) {
if ("bpm_description".equals(variable.getName())) {
assertEquals("d:text", variable.getType());
assertNull(variable.getValue());
foundDescription = true;
} else if ("bpm_assignee".equals(variable.getName())) {
assertEquals("cm:person", variable.getType());
assertEquals(requestContext.getRunAsUser(), variable.getValue());
foundAssignee = true;
}
}
assertTrue(foundDescription);
assertTrue(foundAssignee);
// include process variables with paging outside boundaries
paramMap = new HashMap<String, String>();
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
paramMap.put("maxItems", "4");
paramMap.put("skipCount", "5");
processList = processesClient.getProcesses(paramMap);
assertNotNull(processList);
assertEquals(0, processList.getList().size());
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessTasks.
@Test
public void testGetProcessTasks() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
RequestContext otherPersonContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
Map<String, String> paramMap = new HashMap<String, String>();
JSONObject tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
JSONArray entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
JSONObject taskJSONObject = (JSONObject) ((JSONObject) entriesJSON.get(0)).get("entry");
assertNotNull(taskJSONObject.get("id"));
assertEquals(process1.getId(), taskJSONObject.get("processId"));
assertEquals(process1.getProcessDefinitionId(), taskJSONObject.get("processDefinitionId"));
assertEquals("adhocTask", taskJSONObject.get("activityDefinitionId"));
assertEquals("Adhoc Task", taskJSONObject.get("name"));
assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
assertEquals(2l, taskJSONObject.get("priority"));
assertEquals("wf:adhocTask", taskJSONObject.get("formResourceKey"));
assertNull(taskJSONObject.get("endedAt"));
assertNull(taskJSONObject.get("durationInMs"));
paramMap = new HashMap<String, String>();
paramMap.put("status", "active");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
paramMap = new HashMap<String, String>();
paramMap.put("status", "completed");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 0);
paramMap = new HashMap<String, String>();
try {
processesClient.getTasks("fakeid", paramMap);
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: fakeid was not found", expected.getHttpResponse());
}
// get tasks with admin from the same tenant as the process initiator
publicApiClient.setRequestContext(adminContext);
paramMap = new HashMap<String, String>();
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
// get tasks with admin from another tenant as the process initiator
publicApiClient.setRequestContext(otherContext);
paramMap = new HashMap<String, String>();
try {
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
// get task with other not-involved person
publicApiClient.setRequestContext(otherPersonContext);
paramMap = new HashMap<String, String>();
try {
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
fail("forbidden expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
}
// involve other person and get task
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(process1.getId()).singleResult();
activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPersonContext.getRunAsUser());
publicApiClient.setRequestContext(otherPersonContext);
paramMap = new HashMap<String, String>();
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 1);
// complete task and get tasks
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
publicApiClient.setRequestContext(requestContext);
paramMap = new HashMap<String, String>();
paramMap.put("status", "any");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
publicApiClient.setRequestContext(otherPersonContext);
paramMap = new HashMap<String, String>();
paramMap.put("status", "any");
tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
assertNotNull(tasksJSON);
entriesJSON = (JSONArray) tasksJSON.get("entries");
assertNotNull(entriesJSON);
assertTrue(entriesJSON.size() == 2);
} finally {
cleanupProcessInstance(process1.getId());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testDeleteProcessInstanceByIdUnexisting.
@Test
public void testDeleteProcessInstanceByIdUnexisting() throws Exception {
initApiClientWithTestUser();
ProcessesClient processesClient = publicApiClient.processesClient();
try {
processesClient.deleteProcessById("unexisting");
fail("Exception expected");
} catch (PublicApiException expected) {
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
}
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessItem.
@Test
public void testGetProcessItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
assertNotNull(processRest);
final String newProcessInstanceId = processRest.getId();
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject itemJSON = processesClient.findProcessItem(newProcessInstanceId, docNodeRefs[0].getId());
assertNotNull(itemJSON);
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
assertEquals("Test Doc1", itemJSON.get("name"));
assertEquals("Test Doc1 Title", itemJSON.get("title"));
assertEquals("Test Doc1 Description", itemJSON.get("description"));
assertNotNull(itemJSON.get("createdAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
assertNotNull(itemJSON.get("modifiedAt"));
assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
assertNotNull(itemJSON.get("size"));
assertNotNull(itemJSON.get("mimeType"));
cleanupProcessInstance(processRest.getId());
}
use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testGetProcessInstancesWithPaging.
@Test
public void testGetProcessInstancesWithPaging() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
final ProcessInfo process2 = startAdhocProcess(requestContext, null);
final ProcessInfo process3 = startAdhocProcess(requestContext, null);
try {
ProcessesClient processesClient = publicApiClient.processesClient();
// Test with existing processDefinitionId
Map<String, String> params = new HashMap<String, String>();
params.put("processDefinitionId", process1.getProcessDefinitionId());
JSONObject processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
JSONObject paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
JSONArray jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(3, jsonEntries.size());
// Test with existing processDefinitionId and max items
params.clear();
params.put("maxItems", "2");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
// Test with existing processDefinitionId and skip count
params.clear();
params.put("skipCount", "1");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(1l, paginationJSON.get("skipCount"));
// MNT-10977: Workflow process retrieval returns incorrect hasMoreItems value
// Repository must answer 'false' for 'hasMoreItems' since the total number of items is 3, 2 items are requested and 1 is skipped
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(2, jsonEntries.size());
// Test with existing processDefinitionId and max items and skip count
params.clear();
params.put("maxItems", "3");
params.put("skipCount", "2");
params.put("processDefinitionId", process1.getProcessDefinitionId());
processListJSONObject = processesClient.getProcessesJSON(params);
assertNotNull(processListJSONObject);
paginationJSON = (JSONObject) processListJSONObject.get("pagination");
assertEquals(1l, paginationJSON.get("count"));
assertEquals(3l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
// MNT-10977: Workflow process retrieval returns incorrect hasMoreItems value
// Repository must answer 'false' for 'hasMoreItems' since the total number of items is 3 and 2 items are skipped
assertEquals(false, paginationJSON.get("hasMoreItems"));
jsonEntries = (JSONArray) processListJSONObject.get("entries");
assertEquals(1, jsonEntries.size());
} finally {
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
}
}
Aggregations