use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method testTaskInstancesForWorkflowGet.
public void testTaskInstancesForWorkflowGet() throws Exception {
// Check starts with no workflow.
personManager.setUser(USER2);
sendRequest(new GetRequest(MessageFormat.format(URL_WORKFLOW_TASKS, "Foo")), Status.STATUS_INTERNAL_SERVER_ERROR);
// Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Calendar dueDateCal = Calendar.getInstance();
Date dueDate = dueDateCal.getTime();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
String workflowId = adhocPath.getInstance().getId();
workflows.add(workflowId);
// End start task.
WorkflowTask startTask = workflowService.getStartTask(workflowId);
String startTaskId = startTask.getId();
workflowService.endTask(startTaskId, null);
// Check USER2 now has one task.
List<WorkflowTask> tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
assertEquals(1, tasks.size());
WorkflowTask task = tasks.get(0);
// Retrieve tasks using the workflow instance
String baseUrl = MessageFormat.format(URL_WORKFLOW_TASKS, workflowId);
// Check returns the completed start task.
String adhocTaskId = task.getId();
checkTasksMatch(baseUrl, startTaskId);
String completedUrl = baseUrl + "?state=" + WorkflowTaskState.COMPLETED;
checkTasksMatch(completedUrl, startTaskId);
personManager.setUser(USER2);
String inProgressUrl = baseUrl + "?state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(inProgressUrl, adhocTaskId);
String user1Url = baseUrl + "?authority=" + USER1;
checkTasksMatch(user1Url, startTaskId);
String user2Url = baseUrl + "?authority=" + USER2;
checkTasksMatch(user2Url, adhocTaskId);
String user1CompletedURL = user1Url + "&state=" + WorkflowTaskState.COMPLETED;
checkTasksMatch(user1CompletedURL, startTaskId);
String user1InProgressURL = user1Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(user1InProgressURL);
String user2CompletedURL = user2Url + "&state=" + WorkflowTaskState.COMPLETED;
checkTasksMatch(user2CompletedURL);
String user2InProgressURL = user2Url + "&state=" + WorkflowTaskState.IN_PROGRESS;
checkTasksMatch(user2InProgressURL, adhocTaskId);
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowTaskDetailed.
@SuppressWarnings("unchecked")
public void testBuildWorkflowTaskDetailed() throws Exception {
Date date = new Date();
WorkflowTask workflowTask = makeTask(date);
Map<String, Object> model = builder.buildDetailed(workflowTask);
Object id = model.get(WorkflowModelBuilder.TASK_ID);
assertEquals(workflowTask.getId(), id);
Object url = model.get(WorkflowModelBuilder.TASK_URL);
assertEquals("api/task-instances/" + workflowTask.getId(), url);
assertEquals(workflowTask.getName(), model.get(WorkflowModelBuilder.TASK_NAME));
assertEquals(workflowTask.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE));
assertEquals(workflowTask.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION));
assertEquals(workflowTask.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
Map<String, Object> owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, owner.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, owner.get(WorkflowModelBuilder.PERSON_LAST_NAME));
Map<String, Object> props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
assertEquals(workflowTask.getProperties().size() + 1, props.size());
Map<String, Object> workflowInstance = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE);
WorkflowInstance instance = workflowTask.getPath().getInstance();
assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDateStr = ISO8601DateFormat.format(instance.getStartDate());
String startDateBuilderStr = ISO8601DateFormat.formatToZulu((String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
assertEquals(startDateStr, startDateBuilderStr);
WorkflowDefinition workflowDef = instance.getDefinition();
assertEquals(workflowDef.getName(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME));
assertEquals(workflowDef.getTitle(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE));
assertEquals(workflowDef.getDescription(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION));
Map<String, Object> actualDefinition = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_DEFINITION);
WorkflowTaskDefinition taskDef = workflowTask.getDefinition();
assertEquals(taskDef.getId(), actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_ID));
Map<String, Object> actualType = (Map<String, Object>) actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_TYPE);
TypeDefinition taskType = taskDef.getMetadata();
assertEquals(taskType.getName(), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_NAME));
assertEquals(taskType.getTitle(dictionaryService), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_TITLE));
assertEquals(taskType.getDescription(dictionaryService), actualType.get(WorkflowModelBuilder.TYPE_DEFINITION_DESCRIPTION));
Map<String, Object> actualNode = (Map<String, Object>) actualDefinition.get(WorkflowModelBuilder.TASK_DEFINITION_NODE);
WorkflowNode taskNode = taskDef.getNode();
assertEquals(taskNode.getName(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_NAME));
assertEquals(taskNode.getTitle(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_TITLE));
assertEquals(taskNode.getDescription(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_DESCRIPTION));
assertEquals(taskNode.isTaskNode(), actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_IS_TASK_NODE));
List<Map<String, Object>> transitions = (List<Map<String, Object>>) actualNode.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITIONS);
WorkflowTransition[] taskTransitions = taskNode.getTransitions();
int i = 0;
for (Map<String, Object> transition : transitions) {
WorkflowTransition workflowTransition = taskTransitions[i];
assertEquals(workflowTransition.getId(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_ID));
assertEquals(workflowTransition.getTitle(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_TITLE));
assertEquals(workflowTransition.getDescription(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_DESCRIPTION));
assertEquals(workflowTransition.isDefault(), transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_IS_DEFAULT));
assertEquals(false, transition.get(WorkflowModelBuilder.WORKFLOW_NODE_TRANSITION_IS_HIDDEN));
i++;
}
}
use of org.alfresco.service.cmr.workflow.WorkflowTask 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.WorkflowTask in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilder method buildDetailed.
/**
* Returns a detailed representation of a {@link WorkflowInstance}.
* @param workflowInstance The workflow instance to be represented.
* @param includeTasks should we include task in model?
* @return Map
*/
public Map<String, Object> buildDetailed(WorkflowInstance workflowInstance, boolean includeTasks) {
Map<String, Object> model = buildSimple(workflowInstance);
Serializable startTaskId = null;
WorkflowTask startTask = workflowService.getStartTask(workflowInstance.getId());
if (startTask != null) {
startTaskId = startTask.getId();
}
if (workflowService.hasWorkflowImage(workflowInstance.getId())) {
model.put(TASK_WORKFLOW_INSTANCE_DIAGRAM_URL, getDiagramUrl(workflowInstance));
}
model.put(TASK_WORKFLOW_INSTANCE_START_TASK_INSTANCE_ID, startTaskId);
model.put(TASK_WORKFLOW_INSTANCE_DEFINITION, buildDetailed(workflowInstance.getDefinition()));
if (includeTasks) {
// get all tasks for workflow
WorkflowTaskQuery tasksQuery = new WorkflowTaskQuery();
tasksQuery.setTaskState(null);
tasksQuery.setActive(null);
tasksQuery.setProcessId(workflowInstance.getId());
List<WorkflowTask> tasks = workflowService.queryTasks(tasksQuery);
ArrayList<Map<String, Object>> results = new ArrayList<Map<String, Object>>(tasks.size());
for (WorkflowTask task : tasks) {
results.add(buildSimple(task, null));
}
model.put(TASK_WORKFLOW_INSTANCE_TASKS, results);
}
return model;
}
use of org.alfresco.service.cmr.workflow.WorkflowTask in project acs-community-packaging by Alfresco.
the class TaskInfoBean method sendTaskResources.
/**
* Returns the resource list for the workflow task identified by the 'taskId'
* parameter found in the ExternalContext.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendTaskResources() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String taskId = (String) context.getExternalContext().getRequestParameterMap().get("taskId");
if (taskId == null || taskId.length() == 0) {
throw new IllegalArgumentException("'taskId' parameter is missing");
}
WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
if (task != null) {
Repository.getServiceRegistry(context).getTemplateService().processTemplate("/alfresco/templates/client/task_resource_panel.ftl", getModel(task), out);
} else {
out.write("<span class='errorMessage'>Task could not be found.</span>");
}
}
Aggregations