mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REST API fixes based on mobile testing + new Activiti version
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55132 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -43,6 +43,7 @@ import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.workflow.api.model.ProcessInfo;
|
||||
import org.alfresco.rest.workflow.api.model.Variable;
|
||||
import org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -539,6 +540,16 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
assertNotNull(deletedInstance);
|
||||
assertNotNull(deletedInstance.getEndTime());
|
||||
assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
|
||||
|
||||
try
|
||||
{
|
||||
processesClient.deleteProcessById(process.getId());
|
||||
fail("expected exeception");
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -632,6 +643,7 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
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')");
|
||||
@@ -730,6 +742,85 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(1, processList.getList().size());
|
||||
|
||||
// include process variables as well
|
||||
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
|
||||
{
|
||||
@@ -885,6 +976,9 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
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
|
||||
@@ -954,6 +1048,64 @@ public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@@ -18,10 +18,14 @@
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.workflow.api.model.ProcessInfo;
|
||||
import org.alfresco.rest.workflow.api.model.Variable;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class ProcessesParser extends ListParser<ProcessInfo>
|
||||
@@ -48,6 +52,22 @@ public class ProcessesParser extends ListParser<ProcessInfo>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.impl.util.ClockUtil;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.activiti.engine.task.DelegationState;
|
||||
@@ -698,12 +699,14 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
ProcessInstance processCompleteAsOwner = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
|
||||
ProcessInstance processCompleteAsInitiator = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
|
||||
ProcessInstance processCompleteAsAdmin = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
|
||||
ProcessInstance processCompleteWithVariables = startAdhocProcess(initiator, requestContext.getNetworkId(), null);
|
||||
try
|
||||
{
|
||||
Task asAssigneeTask = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processCompleteAsAssignee.getId()).singleResult();
|
||||
Task asOwnerTask = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processCompleteAsOwner.getId()).singleResult();
|
||||
Task asInitiatorTask = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processCompleteAsInitiator.getId()).singleResult();
|
||||
Task asAdminTask = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processCompleteAsAdmin.getId()).singleResult();
|
||||
Task withVariablesTask = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processCompleteWithVariables.getId()).singleResult();
|
||||
TasksClient tasksClient = publicApiClient.tasksClient();
|
||||
|
||||
// Unclaiming the task when NOT assignee, owner, initiator or admin results in error
|
||||
@@ -755,10 +758,69 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
assertEquals("completed", result.get("state"));
|
||||
assertNotNull(result.get("endedAt"));
|
||||
assertNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(asAdminTask.getId()).singleResult());
|
||||
|
||||
// Complete with variables
|
||||
requestContext.setRunAsUser(initiator);
|
||||
activitiProcessEngine.getTaskService().setAssignee(withVariablesTask.getId(), null);
|
||||
|
||||
JSONArray variablesArray = new JSONArray();
|
||||
JSONObject variableBody = new JSONObject();
|
||||
variableBody.put("name", "newGlobalVariable");
|
||||
variableBody.put("value", 1234);
|
||||
variableBody.put("scope", "global");
|
||||
variablesArray.add(variableBody);
|
||||
variableBody = new JSONObject();
|
||||
variableBody.put("name", "newLocalVariable");
|
||||
variableBody.put("value", 5678);
|
||||
variableBody.put("scope", "local");
|
||||
variablesArray.add(variableBody);
|
||||
|
||||
taskBody.put("variables", variablesArray);
|
||||
selectedFields.add("variables");
|
||||
result = tasksClient.updateTask(withVariablesTask.getId(), taskBody, selectedFields);
|
||||
assertEquals("completed", result.get("state"));
|
||||
assertNotNull(result.get("endedAt"));
|
||||
assertNull(activitiProcessEngine.getTaskService().createTaskQuery().taskId(withVariablesTask.getId()).singleResult());
|
||||
HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery()
|
||||
.taskId(withVariablesTask.getId())
|
||||
.includeProcessVariables()
|
||||
.includeTaskLocalVariables()
|
||||
.singleResult();
|
||||
|
||||
assertEquals(1234, historyTask.getProcessVariables().get("newGlobalVariable"));
|
||||
assertEquals(5678, historyTask.getTaskLocalVariables().get("newLocalVariable"));
|
||||
|
||||
JSONObject variables = tasksClient.findTaskVariables(withVariablesTask.getId());
|
||||
assertNotNull(variables);
|
||||
JSONObject list = (JSONObject) variables.get("list");
|
||||
assertNotNull(list);
|
||||
JSONArray entries = (JSONArray) list.get("entries");
|
||||
assertNotNull(entries);
|
||||
|
||||
boolean foundGlobal = false;
|
||||
boolean foundLocal = false;
|
||||
for (Object entry : entries)
|
||||
{
|
||||
JSONObject variableObject = (JSONObject) ((JSONObject) entry).get("entry");
|
||||
if ("newGlobalVariable".equals(variableObject.get("name")))
|
||||
{
|
||||
assertEquals(1234L, variableObject.get("value"));
|
||||
foundGlobal = true;
|
||||
}
|
||||
else if ("newLocalVariable".equals(variableObject.get("name")))
|
||||
{
|
||||
assertEquals(5678L, variableObject.get("value"));
|
||||
foundLocal = true;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(foundGlobal);
|
||||
assertTrue(foundLocal);
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(processCompleteAsAssignee, processCompleteAsAdmin, processCompleteAsInitiator, processCompleteAsOwner);
|
||||
cleanupProcessInstance(processCompleteAsAssignee, processCompleteAsAdmin, processCompleteAsInitiator,
|
||||
processCompleteAsOwner, processCompleteWithVariables);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1540,7 +1602,7 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
|
||||
// Test with existing processDefinitionId
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("processDefinitionId", processDefinitionId);
|
||||
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
|
||||
JSONObject taskListJSONObject = tasksClient.findTasks(params);
|
||||
assertNotNull(taskListJSONObject);
|
||||
JSONObject paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
|
||||
@@ -1550,11 +1612,12 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
assertEquals(false, paginationJSON.get("hasMoreItems"));
|
||||
JSONArray jsonEntries = (JSONArray) taskListJSONObject.get("entries");
|
||||
assertEquals(6, jsonEntries.size());
|
||||
validateVariables((JSONObject) jsonEntries.get(0), requestContext);
|
||||
|
||||
// Test with existing processDefinitionId and max items
|
||||
params.clear();
|
||||
params.put("maxItems", "3");
|
||||
params.put("processDefinitionId", processDefinitionId);
|
||||
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
|
||||
taskListJSONObject = tasksClient.findTasks(params);
|
||||
assertNotNull(taskListJSONObject);
|
||||
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
|
||||
@@ -1564,11 +1627,12 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
assertEquals(true, paginationJSON.get("hasMoreItems"));
|
||||
jsonEntries = (JSONArray) taskListJSONObject.get("entries");
|
||||
assertEquals(3, jsonEntries.size());
|
||||
validateVariables((JSONObject) jsonEntries.get(0), requestContext);
|
||||
|
||||
// Test with existing processDefinitionId and skip count
|
||||
params.clear();
|
||||
params.put("skipCount", "2");
|
||||
params.put("processDefinitionId", processDefinitionId);
|
||||
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
|
||||
taskListJSONObject = tasksClient.findTasks(params);
|
||||
assertNotNull(taskListJSONObject);
|
||||
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
|
||||
@@ -1583,7 +1647,7 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
params.clear();
|
||||
params.put("maxItems", "3");
|
||||
params.put("skipCount", "2");
|
||||
params.put("processDefinitionId", processDefinitionId);
|
||||
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
|
||||
taskListJSONObject = tasksClient.findTasks(params);
|
||||
assertNotNull(taskListJSONObject);
|
||||
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
|
||||
@@ -1598,7 +1662,7 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
params.clear();
|
||||
params.put("maxItems", "3");
|
||||
params.put("skipCount", "4");
|
||||
params.put("processDefinitionId", processDefinitionId);
|
||||
params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
|
||||
taskListJSONObject = tasksClient.findTasks(params);
|
||||
assertNotNull(taskListJSONObject);
|
||||
paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
|
||||
@@ -1615,6 +1679,48 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
}
|
||||
}
|
||||
|
||||
protected void validateVariables(JSONObject entry, RequestContext requestContext) {
|
||||
JSONObject taskObject = (JSONObject) entry.get("entry");
|
||||
JSONArray variables = (JSONArray) taskObject.get("variables");
|
||||
boolean foundInitiator = false;
|
||||
boolean foundAssignee = false;
|
||||
boolean foundPercentageComplete = false;
|
||||
boolean foundReassignable = false;
|
||||
for (int i = 0; i < variables.size(); i++)
|
||||
{
|
||||
JSONObject variableJSON = (JSONObject) variables.get(i);
|
||||
if ("initiator".equals(variableJSON.get("name")))
|
||||
{
|
||||
assertEquals("d:noderef", variableJSON.get("type"));
|
||||
assertEquals(requestContext.getRunAsUser(), variableJSON.get("value"));
|
||||
foundInitiator = true;
|
||||
}
|
||||
else if ("bpm_assignee".equals(variableJSON.get("name")))
|
||||
{
|
||||
assertEquals("cm:person", variableJSON.get("type"));
|
||||
assertEquals(requestContext.getRunAsUser(), variableJSON.get("value"));
|
||||
foundAssignee = true;
|
||||
}
|
||||
else if ("bpm_percentComplete".equals(variableJSON.get("name")))
|
||||
{
|
||||
assertEquals("d:int", variableJSON.get("type"));
|
||||
assertEquals(0L, variableJSON.get("value"));
|
||||
foundPercentageComplete = true;
|
||||
}
|
||||
else if ("bpm_reassignable".equals(variableJSON.get("name")))
|
||||
{
|
||||
assertEquals("d:boolean", variableJSON.get("type"));
|
||||
assertEquals(Boolean.TRUE, variableJSON.get("value"));
|
||||
foundReassignable = true;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(foundInitiator);
|
||||
assertTrue(foundAssignee);
|
||||
assertTrue(foundPercentageComplete);
|
||||
assertTrue(foundReassignable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTasksWithSorting() throws Exception
|
||||
{
|
||||
@@ -1956,14 +2062,9 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
assertEquals("d:text", var.get("type"));
|
||||
assertEquals("Not Yet Started", var.get("value"));
|
||||
|
||||
var = entriesByName.get("bpm_status");
|
||||
assertNotNull(var);
|
||||
assertEquals("d:text", var.get("type"));
|
||||
assertEquals("Not Yet Started", var.get("value"));
|
||||
|
||||
var = entriesByName.get("bpm_assignee");
|
||||
assertNotNull(var);
|
||||
assertEquals("d:noderef", var.get("type"));
|
||||
assertEquals("cm:person", var.get("type"));
|
||||
|
||||
final String userName = requestContext.getRunAsUser();
|
||||
assertEquals(userName, var.get("value"));
|
||||
|
Reference in New Issue
Block a user