Search in sources :

Example 1 with LazyActivitiWorkflowTask

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

the class ActivitiWorkflowEngine method getPooledTasks.

/**
 * {@inheritDoc}
 */
public List<WorkflowTask> getPooledTasks(List<String> authorities, boolean lazyInitialization) {
    try {
        if (authorities != null && authorities.size() > 0) {
            // As an optimisation, we assume the first authority CAN be a user. All the
            // others are groups to which the user (or group) belongs. This way, we don't have to
            // check for the type of the authority.
            String firstAuthority = authorities.get(0);
            // Use a map, can be that a task has multiple candidate-groups, which are inside the list
            // of authorities
            Map<String, Task> resultingTasks = new HashMap<String, Task>();
            if (authorityManager.isUser(firstAuthority)) {
                // Candidate user
                addTasksForCandidateUser(firstAuthority, resultingTasks);
                if (authorities.size() > 1) {
                    List<String> remainingAuthorities = authorities.subList(1, authorities.size());
                    addTasksForCandidateGroups(remainingAuthorities, resultingTasks);
                }
            } else {
                // Candidate group
                addTasksForCandidateGroups(authorities, resultingTasks);
            }
            List<WorkflowTask> tasks = new ArrayList<WorkflowTask>();
            WorkflowTask currentTask = null;
            // Only tasks that have NO assignee, should be returned
            for (Task task : resultingTasks.values()) {
                if (task.getAssignee() == null) {
                    // have a group with the same name
                    if (lazyInitialization) {
                        String workflowDefinitionName = typeConverter.getWorkflowDefinitionName(task.getProcessDefinitionId());
                        try {
                            workflowDefinitionName = tenantService.getBaseName(workflowDefinitionName);
                            currentTask = new LazyActivitiWorkflowTask(task, typeConverter, tenantService, workflowDefinitionName);
                        } catch (RuntimeException re) {
                            // Domain mismatch, don't use this task
                            currentTask = null;
                        }
                    } else {
                        currentTask = typeConverter.convert(task, true);
                    }
                    if (currentTask != null) {
                        tasks.add(currentTask);
                    }
                }
            }
            return tasks;
        }
        return Collections.emptyList();
    } catch (ActivitiException ae) {
        String authorityString = null;
        if (authorities != null) {
            authorityString = StringUtils.join(authorities.iterator(), ", ");
        }
        String msg = messageService.getMessage(ERR_GET_POOLED_TASKS, authorityString);
        if (logger.isDebugEnabled()) {
            logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask) Task(org.activiti.engine.task.Task) ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) ArrayList(java.util.ArrayList) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask)

Example 2 with LazyActivitiWorkflowTask

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

the class ActivitiWorkflowEngine method getAssignedTasks.

/**
 * {@inheritDoc}
 */
public List<WorkflowTask> getAssignedTasks(String authority, WorkflowTaskState state, boolean lazyInitialization) {
    try {
        if (state == WorkflowTaskState.IN_PROGRESS) {
            TaskQuery taskQuery = taskService.createTaskQuery().taskAssignee(authority);
            if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled()) {
                taskQuery.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
            }
            List<Task> tasks = taskQuery.list();
            List<WorkflowTask> resultingTasks = new ArrayList<WorkflowTask>();
            for (Task task : tasks) {
                if (lazyInitialization) {
                    resultingTasks.add(new LazyActivitiWorkflowTask(task, typeConverter, tenantService, typeConverter.getWorkflowDefinitionName(task.getProcessDefinitionId())));
                } else {
                    resultingTasks.add(typeConverter.convert(task));
                }
            }
            return resultingTasks;
        } else {
            HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(authority).finished();
            if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled()) {
                taskQuery.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
            }
            List<HistoricTaskInstance> historicTasks = taskQuery.list();
            List<WorkflowTask> resultingTasks = new ArrayList<WorkflowTask>();
            for (HistoricTaskInstance historicTask : historicTasks) {
                if (lazyInitialization) {
                    resultingTasks.add(new LazyActivitiWorkflowTask(historicTask, typeConverter, tenantService));
                } else {
                    resultingTasks.add(typeConverter.convert(historicTask));
                }
            }
            return resultingTasks;
        }
    } catch (ActivitiException ae) {
        String msg = messageService.getMessage(ERR_GET_ASSIGNED_TASKS);
        if (logger.isDebugEnabled()) {
            logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask) Task(org.activiti.engine.task.Task) ActivitiException(org.activiti.engine.ActivitiException) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) ArrayList(java.util.ArrayList) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) TaskQuery(org.activiti.engine.task.TaskQuery) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Aggregations

ArrayList (java.util.ArrayList)2 ActivitiException (org.activiti.engine.ActivitiException)2 Task (org.activiti.engine.task.Task)2 LazyActivitiWorkflowTask (org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask)2 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)2 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)2 HashMap (java.util.HashMap)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)1 TaskQuery (org.activiti.engine.task.TaskQuery)1 WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)1