Search in sources :

Example 1 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project acs-community-packaging by Alfresco.

the class WorkflowBean method getTasksCompleted.

/**
 * Returns a list of nodes representing the completed tasks the
 * current user has.
 *
 * @return List of completed tasks
 */
public List<Node> getTasksCompleted() {
    if (this.completedTasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // get the current in progress tasks for the current user
            ClientConfigElement clientConfig = (ClientConfigElement) Application.getConfigService(context).getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
            WorkflowTaskQuery query = new WorkflowTaskQuery();
            query.setActive(null);
            query.setActorId(userName);
            query.setTaskState(WorkflowTaskState.COMPLETED);
            query.setLimit(clientConfig.getTasksCompletedMaxResults());
            List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
            // create a list of transient nodes to represent
            this.completedTasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.completedTasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added completed task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
        }
    }
    return this.completedTasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) ClientConfigElement(org.alfresco.web.config.ClientConfigElement) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 2 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery 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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowTaskState(org.alfresco.service.cmr.workflow.WorkflowTaskState) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery 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;
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 4 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class ActivitiWorkflowServiceIntegrationTest method checkQueryTasksInactiveWorkflow.

@Override
protected void checkQueryTasksInactiveWorkflow(String workflowInstanceId) {
    WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED);
    taskQuery.setActive(false);
    taskQuery.setProcessId(workflowInstanceId);
    List<WorkflowTask> tasks = workflowService.queryTasks(taskQuery);
    assertNotNull(tasks);
    assertEquals(3, tasks.size());
    taskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED);
    taskQuery.setActive(true);
    taskQuery.setProcessId(workflowInstanceId);
    checkNoTasksFoundUsingQuery(taskQuery);
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 5 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class AbstractWorkflowServiceIntegrationTest method checkProcessNameQuery.

@SuppressWarnings("deprecation")
protected void checkProcessNameQuery(List<String> expectedTaskIds, WorkflowTaskState state) {
    WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(state);
    // Test depricated method, using QName
    taskQuery.setProcessName(getAdhocProcessName());
    checkTasksFoundUsingQuery(expectedTaskIds, taskQuery);
    taskQuery = createWorkflowTaskQuery(state);
    taskQuery.setProcessName(QName.createQName("dummyProcessName"));
    checkNoTasksFoundUsingQuery(taskQuery);
    // Test method, using String
    taskQuery.setWorkflowDefinitionName(getAdhocProcessName().toPrefixString());
    checkTasksFoundUsingQuery(expectedTaskIds, taskQuery);
    taskQuery = createWorkflowTaskQuery(state);
    taskQuery.setWorkflowDefinitionName("dummyProcessName");
    checkNoTasksFoundUsingQuery(taskQuery);
}
Also used : WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Aggregations

WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)34 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)20 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)14 Serializable (java.io.Serializable)9 ArrayList (java.util.ArrayList)6 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)5 Test (org.junit.Test)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)4 Map (java.util.Map)3 Task (org.activiti.engine.task.Task)3 Date (java.util.Date)2 List (java.util.List)2 FacesContext (javax.faces.context.FacesContext)2 UserTransaction (javax.transaction.UserTransaction)2 TaskQuery (org.activiti.engine.task.TaskQuery)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTaskState (org.alfresco.service.cmr.workflow.WorkflowTaskState)2 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)2