mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
ALF-3896: F69 REST API to get the history (completed tasks) of a workflow instance (GET /api/workflow-instances/{workflow_instance_id}/task-instances)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22111 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
Lists all Workflow Task Instances associated with an authority and of a given State.
|
Lists all Workflow Task Instances associated with an authority and of a given State.
|
||||||
The list of returned tasks also includes pooled tasks which the specified authority is eligible to claim.
|
The list of returned tasks also includes pooled tasks which the specified authority is eligible to claim.
|
||||||
</description>
|
</description>
|
||||||
<url>/api/task-instances?authority={authority?}&state={state?}&priority={priority?}&pooledTasks={pooledTasks?}&dueBefore={dueBefore?}&dueAfter={dueAfter?}&properties={properties?}&detailed={detailed?}&maxItems={maxItems?}&skipCount={skipCount?}&exclude={exclude?}</url>
|
<url>/api/task-instances?authority={authority?}&state={state?}&priority={priority?}&pooledTasks={pooledTasks?}&dueBefore={dueBefore?}&dueAfter={dueAfter?}&properties={properties?}&maxItems={maxItems?}&skipCount={skipCount?}&exclude={exclude?}</url>
|
||||||
|
<url>/api/workflow-instances/{workflow_instance_id}/task-instances?authority={authority?}&state={state?}&priority={priority?}&dueBefore={isoDate?}&dueAfter={isoDate?}&properties={prop1, prop2, prop3...?}&maxItems={maxItems?}&skipCount={skipCount?}&exclude={exclude?}</url>
|
||||||
<format default="json"/>
|
<format default="json"/>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction allow="readonly">required</transaction>
|
<transaction allow="readonly">required</transaction>
|
||||||
|
@@ -51,11 +51,12 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
|
|||||||
public static final String PARAM_DUE_AFTER = "dueAfter";
|
public static final String PARAM_DUE_AFTER = "dueAfter";
|
||||||
public static final String PARAM_PROPERTIES = "properties";
|
public static final String PARAM_PROPERTIES = "properties";
|
||||||
public static final String PARAM_POOLED_TASKS = "pooledTasks";
|
public static final String PARAM_POOLED_TASKS = "pooledTasks";
|
||||||
public static final String PARAM_DETAILED = "detailed";
|
public static final String VAR_WORKFLOW_INSTANCE_ID = "workflow_instance_id";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
|
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
|
||||||
{
|
{
|
||||||
|
Map<String, String> params = req.getServiceMatch().getTemplateVars();
|
||||||
Map<String, Object> filters = new HashMap<String, Object>(4);
|
Map<String, Object> filters = new HashMap<String, Object>(4);
|
||||||
|
|
||||||
// authority is not included into filters list as it will be taken into account before filtering
|
// authority is not included into filters list as it will be taken into account before filtering
|
||||||
@@ -64,9 +65,14 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
|
|||||||
// state is also not included into filters list, for the same reason
|
// state is also not included into filters list, for the same reason
|
||||||
WorkflowTaskState state = getState(req);
|
WorkflowTaskState state = getState(req);
|
||||||
|
|
||||||
|
// look for a workflow instance id
|
||||||
|
String workflowInstanceId = params.get(VAR_WORKFLOW_INSTANCE_ID);
|
||||||
|
|
||||||
|
// determine if pooledTasks should be included, when appropriate i.e. when an authority is supplied
|
||||||
Boolean pooledTasksOnly = getPooledTasks(req);
|
Boolean pooledTasksOnly = getPooledTasks(req);
|
||||||
|
|
||||||
|
// get list of properties to include in the response
|
||||||
List<String> properties = getProperties(req);
|
List<String> properties = getProperties(req);
|
||||||
boolean detailed = "true".equals(req.getParameter(PARAM_DETAILED));
|
|
||||||
|
|
||||||
// get filter param values
|
// get filter param values
|
||||||
filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));
|
filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));
|
||||||
@@ -81,6 +87,30 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
|
|||||||
|
|
||||||
List<WorkflowTask> allTasks;
|
List<WorkflowTask> allTasks;
|
||||||
|
|
||||||
|
if (workflowInstanceId != null)
|
||||||
|
{
|
||||||
|
// a workflow instance id was provided so query for tasks
|
||||||
|
WorkflowTaskQuery taskQuery = new WorkflowTaskQuery();
|
||||||
|
taskQuery.setActive(null);
|
||||||
|
taskQuery.setProcessId(workflowInstanceId);
|
||||||
|
taskQuery.setTaskState(state);
|
||||||
|
|
||||||
|
if (authority != null)
|
||||||
|
{
|
||||||
|
taskQuery.setActorId(authority);
|
||||||
|
}
|
||||||
|
|
||||||
|
allTasks = workflowService.queryTasks(taskQuery);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// default task state to IN_PROGRESS if not supplied
|
||||||
|
if (state == null)
|
||||||
|
{
|
||||||
|
state = WorkflowTaskState.IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no workflow instance id is present so get all tasks
|
||||||
if (authority != null)
|
if (authority != null)
|
||||||
{
|
{
|
||||||
List<WorkflowTask> tasks = workflowService.getAssignedTasks(authority, state);
|
List<WorkflowTask> tasks = workflowService.getAssignedTasks(authority, state);
|
||||||
@@ -116,23 +146,17 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
|
|||||||
taskQuery.setActive(null);
|
taskQuery.setActive(null);
|
||||||
allTasks = workflowService.queryTasks(taskQuery);
|
allTasks = workflowService.queryTasks(taskQuery);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// filter results
|
// filter results
|
||||||
ArrayList<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
|
ArrayList<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
|
||||||
for (WorkflowTask task : allTasks)
|
for (WorkflowTask task : allTasks)
|
||||||
{
|
{
|
||||||
if (matches(task, filters))
|
if (matches(task, filters))
|
||||||
{
|
|
||||||
if (detailed)
|
|
||||||
{
|
|
||||||
results.add(modelBuilder.buildDetailed(task));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
results.add(modelBuilder.buildSimple(task, properties));
|
results.add(modelBuilder.buildSimple(task, properties));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// create and return results, paginated if necessary
|
// create and return results, paginated if necessary
|
||||||
return createResultModel(modelBuilder, req, "taskInstances", results);
|
return createResultModel(modelBuilder, req, "taskInstances", results);
|
||||||
@@ -174,7 +198,8 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the specified {@link WorkflowTaskState}, defaults to IN_PROGRESS.
|
* Gets the specified {@link WorkflowTaskState}, null if not requested
|
||||||
|
*
|
||||||
* @param req
|
* @param req
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -193,8 +218,8 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
|
|||||||
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
|
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Defaults to IN_PROGRESS.
|
|
||||||
return WorkflowTaskState.IN_PROGRESS;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -72,6 +72,7 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
|||||||
private final static String USER3 = "Nick" + GUID.generate();
|
private final static String USER3 = "Nick" + GUID.generate();
|
||||||
private static final String URL_TASKS = "api/task-instances";
|
private static final String URL_TASKS = "api/task-instances";
|
||||||
private static final String URL_USER_TASKS = "api/task-instances?authority={0}";
|
private static final String URL_USER_TASKS = "api/task-instances?authority={0}";
|
||||||
|
private static final String URL_WORKFLOW_TASKS = "api/workflow-instances/{0}/task-instances";
|
||||||
private static final String URL_WORKFLOW_DEFINITIONS = "api/workflow-definitions";
|
private static final String URL_WORKFLOW_DEFINITIONS = "api/workflow-definitions";
|
||||||
private static final String URL_WORKFLOW_INSTANCES = "api/workflow-instances";
|
private static final String URL_WORKFLOW_INSTANCES = "api/workflow-instances";
|
||||||
private static final String URL_WORKFLOW_INSTANCES_FOR_DEFINITION = "api/workflow-definitions/{0}/workflow-instances";
|
private static final String URL_WORKFLOW_INSTANCES_FOR_DEFINITION = "api/workflow-definitions/{0}/workflow-instances";
|
||||||
@@ -194,6 +195,16 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertFalse("Found wf:submitAdhocTask when they were supposed to be excluded", adhocTasksPresent);
|
assertFalse("Found wf:submitAdhocTask when they were supposed to be excluded", adhocTasksPresent);
|
||||||
|
|
||||||
|
// retrieve tasks using the workflow instance
|
||||||
|
String workflowInstanceId = adhocPath.getInstance().getId();
|
||||||
|
response = sendRequest(new GetRequest(MessageFormat.format(URL_WORKFLOW_TASKS, workflowInstanceId)), 200);
|
||||||
|
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||||
|
jsonStr = response.getContentAsString();
|
||||||
|
json = new JSONObject(jsonStr);
|
||||||
|
results = json.getJSONArray("data");
|
||||||
|
assertNotNull(results);
|
||||||
|
assertTrue(results.length() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTaskInstanceGet() throws Exception
|
public void testTaskInstanceGet() throws Exception
|
||||||
|
Reference in New Issue
Block a user