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);
}
}
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);
}
}
Aggregations