use of org.alfresco.service.cmr.workflow.WorkflowTaskState in project alfresco-remote-api by Alfresco.
the class TaskInstancesGet method buildModel.
@Override
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);
// authority is not included into filters list as it will be taken into account before filtering
String authority = getAuthority(req);
if (authority == null) {
// ALF-11036 fix, if authority argument is omitted the tasks for the current user should be returned.
authority = authenticationService.getCurrentUserName();
}
// state is also not included into filters list, for the same reason
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);
// get list of properties to include in the response
List<String> properties = getProperties(req);
// get filter param values
filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));
filters.put(PARAM_PROPERTY, req.getParameter(PARAM_PROPERTY));
processDateFilter(req, PARAM_DUE_BEFORE, filters);
processDateFilter(req, PARAM_DUE_AFTER, filters);
String excludeParam = req.getParameter(PARAM_EXCLUDE);
if (excludeParam != null && excludeParam.length() > 0) {
filters.put(PARAM_EXCLUDE, new ExcludeFilter(excludeParam));
}
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);
taskQuery.setOrderBy(new OrderBy[] { OrderBy.TaskDue_Asc });
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) {
List<WorkflowTask> tasks = workflowService.getAssignedTasks(authority, state, true);
List<WorkflowTask> pooledTasks = workflowService.getPooledTasks(authority, true);
if (pooledTasksOnly != null) {
if (pooledTasksOnly.booleanValue()) {
// only return pooled tasks the user can claim
allTasks = new ArrayList<WorkflowTask>(pooledTasks.size());
allTasks.addAll(pooledTasks);
} else {
// only return tasks assigned to the user
allTasks = new ArrayList<WorkflowTask>(tasks.size());
allTasks.addAll(tasks);
}
} else {
// include both assigned and unassigned tasks
allTasks = new ArrayList<WorkflowTask>(tasks.size() + pooledTasks.size());
allTasks.addAll(tasks);
allTasks.addAll(pooledTasks);
}
// sort tasks by due date
Collections.sort(allTasks, taskComparator);
} else {
// authority was not provided -> return all active tasks in the system
WorkflowTaskQuery taskQuery = new WorkflowTaskQuery();
taskQuery.setTaskState(state);
taskQuery.setActive(null);
taskQuery.setOrderBy(new OrderBy[] { OrderBy.TaskDue_Asc });
allTasks = workflowService.queryTasks(taskQuery);
}
}
int maxItems = getIntParameter(req, PARAM_MAX_ITEMS, DEFAULT_MAX_ITEMS);
int skipCount = getIntParameter(req, PARAM_SKIP_COUNT, DEFAULT_SKIP_COUNT);
int totalCount = 0;
ArrayList<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
// Filter results
for (WorkflowTask task : allTasks) {
if (matches(task, filters)) {
// Total-count needs to be based on matching tasks only, so we can't just use allTasks.size() for this
totalCount++;
if (totalCount > skipCount && (maxItems < 0 || maxItems > results.size())) {
// Only build the actual detail if it's in the range of items we need. This will
// drastically improve performance over paging after building the model
results.add(modelBuilder.buildSimple(task, properties));
}
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("taskInstances", results);
if (maxItems != DEFAULT_MAX_ITEMS || skipCount != DEFAULT_SKIP_COUNT) {
// maxItems or skipCount parameter was provided so we need to include paging into response
model.put("paging", ModelUtil.buildPaging(totalCount, maxItems == DEFAULT_MAX_ITEMS ? totalCount : maxItems, skipCount));
}
// create and return results, paginated if necessary
return model;
}
use of org.alfresco.service.cmr.workflow.WorkflowTaskState in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method makeTask.
private WorkflowTask makeTask(Date date) {
String description = "Task Desc";
String id = "testId$1";
String name = "Task Name";
WorkflowTaskState state = WorkflowTaskState.IN_PROGRESS;
String title = "Task Title";
WorkflowPath path = makePath();
WorkflowTaskDefinition definition = makeTaskDefinition();
HashMap<QName, Serializable> properties = makeTaskProperties(date);
return new WorkflowTask(id, definition, name, title, description, state, path, properties);
}
Aggregations