Merged BRANCHES/DEV/BELARUS/HEAD_2010_08_17 to HEAD:

21853: ALF-4304 : F101 All relevant REST APIs have filtering capabilities i.e. authority, state, priority and date range
               ALF-3902: F77 REST API to get all task instances

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21899 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2010-08-20 12:31:58 +00:00
parent 55bd4fc42e
commit 79c700b6fb
5 changed files with 413 additions and 216 deletions

View File

@@ -4,7 +4,7 @@
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?}&amp;state={state?}&amp;properties={properties?}&amp;detailed={detailed?}</url> <url>/api/task-instances?authority={authority?}&amp;state={state?}&amp;priority={priority?}&amp;dueBefore={dueBefore?}&amp;dueAfter={dueAfter?}&amp;properties={properties?}&amp;detailed={detailed?}</url>
<format default="json"/> <format default="json"/>
<authentication>user</authentication> <authentication>user</authentication>
<transaction allow="readonly">required</transaction> <transaction allow="readonly">required</transaction>

View File

@@ -1,8 +1,8 @@
<webscript> <webscript>
<shortname>Get Workflow Instance Collection</shortname> <shortname>Get Workflow Instance Collection</shortname>
<description>Retrieves all workflow instances, the returned list can be optionally filtered by the state of the workflow instance and by the authority that initiated the workflow instance.</description> <description>Retrieves all workflow instances, the returned list can be optionally filtered by the state of the workflow instance and by the authority that initiated the workflow instance.</description>
<url>/api/workflow-instances?state={state?}&amp;initiator={initiator?}&amp;priority={priority?}</url> <url>/api/workflow-instances?state={state?}&amp;initiator={initiator?}&amp;priority={priority?}&amp;dueBefore={dueBefore?}&amp;dueAfter={dueAfter?}&amp;startedBefore={startedBefore?}&amp;startedAfter={startedAfter?}&amp;completedBefore={completedBefore?}&amp;completedAfter={completedAfter?}</url>
<url>/api/workflow-definitions/{workflow_definition_id}/workflow-instances?state={state?}&amp;initiator={initiator?}&amp;date={date?}&amp;priority={priority?}</url> <url>/api/workflow-definitions/{workflow_definition_id}/workflow-instances?state={state?}&amp;initiator={initiator?}&amp;priority={priority?}&amp;dueBefore={dueBefore?}&amp;dueAfter={dueAfter?}&amp;startedBefore={startedBefore?}&amp;startedAfter={startedAfter?}&amp;completedBefore={completedBefore?}&amp;completedAfter={completedAfter?}</url>
<format default="json"/> <format default="json"/>
<authentication>user</authentication> <authentication>user</authentication>
<transaction allow="readonly">required</transaction> <transaction allow="readonly">required</transaction>

View File

@@ -18,17 +18,21 @@
*/ */
package org.alfresco.repo.web.scripts.workflow; package org.alfresco.repo.web.scripts.workflow;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
import org.alfresco.service.cmr.workflow.WorkflowTaskState; import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.springframework.extensions.surf.util.ISO8601DateFormat;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
@@ -41,37 +45,62 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
public class TaskInstancesGet extends AbstractWorkflowWebscript public class TaskInstancesGet extends AbstractWorkflowWebscript
{ {
public static final String PARAM_AUTHORITY = "authority"; public static final String PARAM_AUTHORITY = "authority";
public static final String PARAM_STATUS= "status"; public static final String PARAM_STATE = "state";
public static final String PARAM_PRIORITY = "priority";
public static final String PARAM_DUE_BEFORE = "dueBefore";
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_DETAILED = "detailed"; public static final String PARAM_DETAILED = "detailed";
@Override @Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
Cache cache)
{ {
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
String authority = getAuthority(req); String authority = getAuthority(req);
// state is also not included into filters list, for the same reason
WorkflowTaskState state = getState(req); WorkflowTaskState state = getState(req);
filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));
filters.put(PARAM_DUE_BEFORE, getDateParameter(req, PARAM_DUE_BEFORE));
filters.put(PARAM_DUE_AFTER, getDateParameter(req, PARAM_DUE_AFTER));
List<String> properties = getProperties(req); List<String> properties = getProperties(req);
boolean detailed = "true".equals(req.getParameter(PARAM_DETAILED)); boolean detailed = "true".equals(req.getParameter(PARAM_DETAILED));
//TODO Handle possible thrown exceptions here? List<WorkflowTask> allTasks;
if (authority != null)
{
List<WorkflowTask> tasks = workflowService.getAssignedTasks(authority, state); List<WorkflowTask> tasks = workflowService.getAssignedTasks(authority, state);
List<WorkflowTask> pooledTasks = workflowService.getPooledTasks(authority); List<WorkflowTask> pooledTasks = workflowService.getPooledTasks(authority);
ArrayList<WorkflowTask> allTasks = new ArrayList<WorkflowTask>(tasks.size() + pooledTasks.size()); allTasks = new ArrayList<WorkflowTask>(tasks.size() + pooledTasks.size());
allTasks.addAll(tasks); allTasks.addAll(tasks);
allTasks.addAll(pooledTasks); allTasks.addAll(pooledTasks);
}
else
{
// authority was not provided -> return all active tasks in the system
WorkflowTaskQuery taskQuery = new WorkflowTaskQuery();
taskQuery.setTaskState(state);
allTasks = workflowService.queryTasks(taskQuery);
}
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 (detailed) if (detailed)
{ {
results.add(modelBuilder.buildDetailed(task)); results.add(modelBuilder.buildDetailed(task));
} }
else { else
{
results.add(modelBuilder.buildSimple(task, properties)); results.add(modelBuilder.buildSimple(task, properties));
} }
} }
}
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("taskInstances", results); model.put("taskInstances", results);
@@ -95,7 +124,7 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
*/ */
private WorkflowTaskState getState(WebScriptRequest req) private WorkflowTaskState getState(WebScriptRequest req)
{ {
String stateName= req.getParameter(PARAM_STATUS); String stateName = req.getParameter(PARAM_STATE);
if (stateName != null) if (stateName != null)
{ {
try try
@@ -120,11 +149,89 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
private String getAuthority(WebScriptRequest req) private String getAuthority(WebScriptRequest req)
{ {
String authority = req.getParameter(PARAM_AUTHORITY); String authority = req.getParameter(PARAM_AUTHORITY);
if(authority == null) if (authority == null || authority.length() == 0)
{ {
authority = AuthenticationUtil.getFullyAuthenticatedUser(); authority = null;
} }
return authority; return authority;
} }
private Date getDateParameter(WebScriptRequest req, String name)
{
String dateString = req.getParameter(name);
if (dateString != null)
{
try
{
return ISO8601DateFormat.parse(dateString.replaceAll(" ", "+"));
}
catch (Exception e)
{
String msg = "Invalid date value: " + dateString;
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
}
return null;
}
/*
* If workflow task matches at list one filter value or if no filter was specified, then it will be included in response
*/
private boolean matches(WorkflowTask task, Map<String, Object> filters)
{
// by default we assume that workflow task should be included to response
boolean result = true;
boolean firstFilter = true;
for (String key : filters.keySet())
{
Object filterValue = filters.get(key);
// skip null filters (null value means that filter was not specified)
if (filterValue != null)
{
// some of the filter was specified, so the decision to include or not task to response
// based on matching to filter parameter (by default false)
if (firstFilter)
{
result = false;
firstFilter = false;
}
boolean matches = false;
if (key.equals(PARAM_DUE_BEFORE))
{
Serializable dueDate = task.getProperties().get(WorkflowModel.PROP_DUE_DATE);
if (dueDate == null || ((Date) dueDate).getTime() <= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_DUE_AFTER))
{
Serializable dueDate = task.getProperties().get(WorkflowModel.PROP_DUE_DATE);
if (dueDate == null || ((Date) dueDate).getTime() >= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_PRIORITY))
{
if (filterValue.equals(task.getProperties().get(WorkflowModel.PROP_PRIORITY).toString()))
{
matches = true;
}
}
// update global result
result = result || matches;
}
}
return result;
}
} }

View File

@@ -18,11 +18,15 @@
*/ */
package org.alfresco.repo.web.scripts.workflow; package org.alfresco.repo.web.scripts.workflow;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.WorkflowModel; import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.cmr.workflow.WorkflowDefinition; import org.alfresco.service.cmr.workflow.WorkflowDefinition;
@@ -31,6 +35,7 @@ import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.springframework.extensions.surf.util.ISO8601DateFormat; import org.springframework.extensions.surf.util.ISO8601DateFormat;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
/** /**
@@ -43,8 +48,13 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
public static final String PARAM_STATE = "state"; public static final String PARAM_STATE = "state";
public static final String PARAM_INITIATOR = "initiator"; public static final String PARAM_INITIATOR = "initiator";
public static final String PARAM_DATE = "date";
public static final String PARAM_PRIORITY = "priority"; public static final String PARAM_PRIORITY = "priority";
public static final String PARAM_DUE_BEFORE = "dueBefore";
public static final String PARAM_DUE_AFTER = "dueAfter";
public static final String PARAM_STARTED_BEFORE = "startedBefore";
public static final String PARAM_STARTED_AFTER = "startedAfter";
public static final String PARAM_COMPLETED_BEFORE = "completedBefore";
public static final String PARAM_COMPLETED_AFTER = "completedAfter";
public static final String PARAM_DEFINITION_ID = "workflow_definition_id"; public static final String PARAM_DEFINITION_ID = "workflow_definition_id";
@Override @Override
@@ -53,11 +63,16 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
Map<String, String> params = req.getServiceMatch().getTemplateVars(); Map<String, String> params = req.getServiceMatch().getTemplateVars();
// get request parameters // get request parameters
Map<String, String> filters = new HashMap<String, String>(4); Map<String, Object> filters = new HashMap<String, Object>(9);
filters.put(PARAM_STATE, req.getParameter(PARAM_STATE)); filters.put(PARAM_STATE, req.getParameter(PARAM_STATE));
filters.put(PARAM_INITIATOR, req.getParameter(PARAM_INITIATOR)); filters.put(PARAM_INITIATOR, req.getParameter(PARAM_INITIATOR));
filters.put(PARAM_DATE, req.getParameter(PARAM_DATE));
filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY)); filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));
filters.put(PARAM_DUE_BEFORE, getDateParameter(req, PARAM_DUE_BEFORE));
filters.put(PARAM_DUE_AFTER, getDateParameter(req, PARAM_DUE_AFTER));
filters.put(PARAM_STARTED_BEFORE, getDateParameter(req, PARAM_STARTED_BEFORE));
filters.put(PARAM_STARTED_AFTER, getDateParameter(req, PARAM_STARTED_AFTER));
filters.put(PARAM_COMPLETED_BEFORE, getDateParameter(req, PARAM_COMPLETED_BEFORE));
filters.put(PARAM_COMPLETED_AFTER, getDateParameter(req, PARAM_COMPLETED_AFTER));
String workflowDefinitionId = params.get(PARAM_DEFINITION_ID); String workflowDefinitionId = params.get(PARAM_DEFINITION_ID);
@@ -98,9 +113,9 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
} }
/* /*
* If workflow instance matches at list one filter value or if no filter was specified, then it will included in response * If workflow instance matches at list one filter value or if no filter was specified, then it will be included in response
*/ */
private boolean matches(WorkflowInstance workflowInstance, Map<String, String> filters, WorkflowModelBuilder modelBuilder) private boolean matches(WorkflowInstance workflowInstance, Map<String, Object> filters, WorkflowModelBuilder modelBuilder)
{ {
// by default we assume that workflow instance should be included to response // by default we assume that workflow instance should be included to response
boolean result = true; boolean result = true;
@@ -108,7 +123,7 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
for (String key : filters.keySet()) for (String key : filters.keySet())
{ {
String filterValue = filters.get(key); Object filterValue = filters.get(key);
// skip null filters (null value means that filter was not specified) // skip null filters (null value means that filter was not specified)
if (filterValue != null) if (filterValue != null)
@@ -125,7 +140,7 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
if (key.equals(PARAM_STATE)) if (key.equals(PARAM_STATE))
{ {
WorkflowState filter = WorkflowState.getState(filterValue); WorkflowState filter = WorkflowState.getState(filterValue.toString());
if (filter != null) if (filter != null)
{ {
@@ -135,17 +150,66 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
} }
} }
} }
else if (key.equals(PARAM_DATE)) else if (key.equals(PARAM_DUE_BEFORE))
{ {
// only workflows that was started after specified time are returned WorkflowTask startTask = modelBuilder.getStartTaskForWorkflow(workflowInstance);
if (workflowInstance.getStartDate().getTime() >= ISO8601DateFormat.parse(filterValue.replaceAll(" ", "+")).getTime()) Serializable dueDate = startTask.getProperties().get(WorkflowModel.PROP_WORKFLOW_DUE_DATE);
if (dueDate == null || ((Date) dueDate).getTime() <= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_DUE_AFTER))
{
WorkflowTask startTask = modelBuilder.getStartTaskForWorkflow(workflowInstance);
Serializable dueDate = startTask.getProperties().get(WorkflowModel.PROP_WORKFLOW_DUE_DATE);
if (dueDate == null || ((Date) dueDate).getTime() >= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_STARTED_BEFORE))
{
Date startDate = workflowInstance.getStartDate();
if (startDate == null || startDate.getTime() <= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_STARTED_AFTER))
{
Date startDate = workflowInstance.getStartDate();
if (startDate == null || startDate.getTime() >= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_COMPLETED_BEFORE))
{
Date endDate = workflowInstance.getEndDate();
if (endDate == null || endDate.getTime() <= ((Date) filterValue).getTime())
{
matches = true;
}
}
else if (key.equals(PARAM_COMPLETED_AFTER))
{
Date endDate = workflowInstance.getEndDate();
if (endDate == null || endDate.getTime() >= ((Date) filterValue).getTime())
{ {
matches = true; matches = true;
} }
} }
else if (key.equals(PARAM_INITIATOR)) else if (key.equals(PARAM_INITIATOR))
{ {
if (workflowInstance.getInitiator() != null && nodeService.exists(workflowInstance.getInitiator()) && filterValue.equals(nodeService.getProperty(workflowInstance.getInitiator(), ContentModel.PROP_USERNAME))) if (workflowInstance.getInitiator() != null && nodeService.exists(workflowInstance.getInitiator())
&& filterValue.equals(nodeService.getProperty(workflowInstance.getInitiator(), ContentModel.PROP_USERNAME)))
{ {
matches = true; matches = true;
} }
@@ -167,6 +231,25 @@ public class WorkflowInstancesGet extends AbstractWorkflowWebscript
return result; return result;
} }
private Date getDateParameter(WebScriptRequest req, String name)
{
String dateString = req.getParameter(name);
if (dateString != null)
{
try
{
return ISO8601DateFormat.parse(dateString.replaceAll(" ", "+"));
}
catch (Exception e)
{
String msg = "Invalid date value: " + dateString;
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);
}
}
return null;
}
private enum WorkflowState private enum WorkflowState
{ {
ACTIVE ("active"), ACTIVE ("active"),

View File

@@ -56,9 +56,9 @@ import org.json.JSONObject;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.extensions.surf.util.ISO8601DateFormat; import org.springframework.extensions.surf.util.ISO8601DateFormat;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response; import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/** /**
@@ -71,6 +71,7 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
private final static String USER2 = "Jane" + GUID.generate(); private final static String USER2 = "Jane" + GUID.generate();
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_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";
@@ -90,7 +91,7 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
{ {
// Check USER2 starts with no tasks. // Check USER2 starts with no tasks.
personManager.setUser(USER2); personManager.setUser(USER2);
Response response = sendRequest(new GetRequest(URL_TASKS), 200); Response response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
assertEquals(Status.STATUS_OK, response.getStatus()); assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString(); String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr); JSONObject json = new JSONObject(jsonStr);
@@ -103,7 +104,8 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
WorkflowDefinition adhocDef = workflowService.getDefinitionByName("jbpm$wf:adhoc"); WorkflowDefinition adhocDef = workflowService.getDefinitionByName("jbpm$wf:adhoc");
Map<QName, Serializable> params = new HashMap<QName, Serializable>(); Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2)); params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
params.put(WorkflowModel.PROP_DUE_DATE, new Date()); Date dueDate = new Date();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1); params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef); params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
@@ -116,10 +118,9 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
WorkflowTask task = tasks.get(0); WorkflowTask task = tasks.get(0);
personManager.setUser(USER2); personManager.setUser(USER2);
response = sendRequest(new GetRequest(URL_TASKS), 200); response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2)), 200);
assertEquals(Status.STATUS_OK, response.getStatus()); assertEquals(Status.STATUS_OK, response.getStatus());
jsonStr = response.getContentAsString(); jsonStr = response.getContentAsString();
System.out.println(jsonStr);
json = new JSONObject(jsonStr); json = new JSONObject(jsonStr);
results = json.getJSONArray("data"); results = json.getJSONArray("data");
assertNotNull(results); assertNotNull(results);
@@ -132,8 +133,14 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
assertEquals(task.title, result.getString("title")); assertEquals(task.title, result.getString("title"));
assertEquals(task.description, result.getString("description")); assertEquals(task.description, result.getString("description"));
assertEquals(task.state.name(), result.getString("state")); assertEquals(task.state.name(), result.getString("state"));
assertEquals(task.definition.metadata.getTitle(), result.getString("typeDefinitionTitle")); assertEquals(task.definition.metadata.getName().toPrefixString(this.namespaceService),
assertEquals(false, result.getBoolean("isPooled")); result.getString("type"));
assertEquals( "api/workflow-paths/" + adhocPath.getId(), result.getString("path"));
assertFalse(result.getBoolean("isPooled"));
assertTrue(result.getBoolean("isEditable"));
assertTrue(result.getBoolean("isReassignable"));
assertFalse(result.getBoolean("isClaimable"));
assertFalse(result.getBoolean("isReleasable"));
JSONObject owner = result.getJSONObject("owner"); JSONObject owner = result.getJSONObject("owner");
assertEquals(USER2, owner.getString("userName")); assertEquals(USER2, owner.getString("userName"));
@@ -147,6 +154,13 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
assertNotNull(instance); assertNotNull(instance);
// TODO: Add more tests to check property filtering and pooled actors. // TODO: Add more tests to check property filtering and pooled actors.
// filtering
checkFiltering(URL_TASKS + "?priority=2");
checkFiltering(URL_TASKS + "?dueAfter=" + ISO8601DateFormat.format(dueDate));
checkFiltering(URL_TASKS + "?dueBefore=" + ISO8601DateFormat.format(dueDate));
} }
public void testTaskInstanceGet() throws Exception public void testTaskInstanceGet() throws Exception
@@ -455,53 +469,34 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
} }
// filter by initiator // filter by initiator
String initiatorFilter = "?initiator=" + USER1; checkFiltering(URL_WORKFLOW_INSTANCES + "?initiator=" + USER1);
Response initiatorFilteredResponse = sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + initiatorFilter), 200);
assertEquals(Status.STATUS_OK, initiatorFilteredResponse.getStatus()); // filter by startedAfter
String initiatorFilteredJsonStr = initiatorFilteredResponse.getContentAsString(); checkFiltering(URL_WORKFLOW_INSTANCES + "?startedAfter=" + ISO8601DateFormat.format(adhocInstance.getStartDate()));
JSONObject initiatorFilteredJson = new JSONObject(initiatorFilteredJsonStr);
JSONArray initiatorFilteredResult = initiatorFilteredJson.getJSONArray("data");
assertNotNull(initiatorFilteredResult);
assertEquals(1, initiatorFilteredResult.length()); // filter by startedBefore
assertEquals(adhocInstance.getId(), initiatorFilteredResult.getJSONObject(0).getString("id")); checkFiltering(URL_WORKFLOW_INSTANCES + "?startedBefore=" + ISO8601DateFormat.format(adhocInstance.getStartDate()));
// filter by date // filter by dueAfter
String dateFilter = "?date=" + ISO8601DateFormat.format(adhocInstance.startDate); checkFiltering(URL_WORKFLOW_INSTANCES + "?dueAfter=" + ISO8601DateFormat.format(dueDate));
Response dateFilteredResponse = sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + dateFilter), 200);
assertEquals(Status.STATUS_OK, dateFilteredResponse.getStatus()); // filter by dueBefore
String dateFilteredJsonStr = dateFilteredResponse.getContentAsString(); checkFiltering(URL_WORKFLOW_INSTANCES + "?dueBefore=" + ISO8601DateFormat.format(dueDate));
JSONObject dateFilteredJson = new JSONObject(dateFilteredJsonStr);
JSONArray dateFilteredResult = dateFilteredJson.getJSONArray("data");
assertNotNull(dateFilteredResult);
assertTrue(dateFilteredResult.length() > 0); if (adhocInstance.getEndDate() != null)
{
// filter by completedAfter
checkFiltering(URL_WORKFLOW_INSTANCES + "?completedAfter=" + ISO8601DateFormat.format(adhocInstance.getEndDate()));
// filter by completedBefore
checkFiltering(URL_WORKFLOW_INSTANCES + "?completedBefore=" + ISO8601DateFormat.format(adhocInstance.getEndDate()));
}
// filter by priority // filter by priority
String priorityFilter = "?priority=1"; checkFiltering(URL_WORKFLOW_INSTANCES + "?priority=1");
Response priorityFilteredResponse = sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + priorityFilter), 200);
assertEquals(Status.STATUS_OK, priorityFilteredResponse.getStatus());
String priorityFilteredJsonStr = priorityFilteredResponse.getContentAsString();
JSONObject priorityFilteredJson = new JSONObject(priorityFilteredJsonStr);
JSONArray priorityFilteredResult = priorityFilteredJson.getJSONArray("data");
assertNotNull(priorityFilteredResult);
assertTrue(priorityFilteredResult.length() > 0);
// filter by state // filter by state
String stateFilter = "?state=active"; checkFiltering(URL_WORKFLOW_INSTANCES + "?state=active");
Response stateFilteredResponse = sendRequest(new GetRequest(URL_WORKFLOW_INSTANCES + stateFilter), 200);
assertEquals(Status.STATUS_OK, stateFilteredResponse.getStatus());
String stateFilteredJsonStr = stateFilteredResponse.getContentAsString();
JSONObject stateFilteredJson = new JSONObject(stateFilteredJsonStr);
JSONArray stateFilteredResult = stateFilteredJson.getJSONArray("data");
assertNotNull(stateFilteredResult);
assertTrue(stateFilteredResult.length() > 1);
} }
public void testWorkflowInstancesForNodeGet() throws Exception public void testWorkflowInstancesForNodeGet() throws Exception
@@ -594,8 +589,7 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), COMPANY_HOME, null, namespaceService, false).get(0);
COMPANY_HOME, null, namespaceService, false).get(0);
contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef(); contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
@@ -676,4 +670,17 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
assertTrue(json.has("definitionUrl")); assertTrue(json.has("definitionUrl"));
assertTrue(json.getString("definitionUrl").startsWith(URL_WORKFLOW_DEFINITIONS)); assertTrue(json.getString("definitionUrl").startsWith(URL_WORKFLOW_DEFINITIONS));
} }
private void checkFiltering(String url) throws Exception
{
Response response = sendRequest(new GetRequest(url), 200);
assertEquals(Status.STATUS_OK, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObject json = new JSONObject(jsonStr);
JSONArray result = json.getJSONArray("data");
assertNotNull(result);
assertTrue(result.length() > 0);
}
} }