mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
59554: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 59450: MNT-9967: Using db-count for process/task entities for retreiving counts, instead of using actual list size (activiti) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62165 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -81,6 +81,14 @@ public interface TaskComponent
|
||||
*/
|
||||
public List<WorkflowTask> queryTasks(final WorkflowTaskQuery query, boolean sameSession);
|
||||
|
||||
/**
|
||||
* Count the number of active tasks that match the given query.
|
||||
*
|
||||
* @param query the filter by which tasks are queried
|
||||
* @return number of matching tasks.
|
||||
*/
|
||||
public long countTasks(final WorkflowTaskQuery query);
|
||||
|
||||
/**
|
||||
* Update the Properties and Associations of a Task
|
||||
*
|
||||
|
@@ -489,7 +489,7 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
@Override
|
||||
public List<WorkflowInstance> getWorkflows(final WorkflowInstanceQuery workflowInstanceQuery, final int maxItems, final int skipCount)
|
||||
{
|
||||
if(workflowInstanceQuery.getWorkflowDefinitionId() == null)
|
||||
if(workflowInstanceQuery.getWorkflowDefinitionId() == null && workflowInstanceQuery.getEngineId() == null)
|
||||
{
|
||||
List<String> ids = Arrays.asList(registry.getWorkflowComponents());
|
||||
return CollectionUtils.transformFlat(ids, new Function<String, Collection<WorkflowInstance>>()
|
||||
@@ -502,7 +502,10 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
});
|
||||
}
|
||||
|
||||
String engineId = BPMEngineRegistry.getEngineId(workflowInstanceQuery.getWorkflowDefinitionId());
|
||||
String engineId = workflowInstanceQuery.getEngineId();
|
||||
if(engineId == null) {
|
||||
engineId = BPMEngineRegistry.getEngineId(workflowInstanceQuery.getWorkflowDefinitionId());
|
||||
}
|
||||
WorkflowComponent component = getWorkflowComponent(engineId);
|
||||
return component.getWorkflows(workflowInstanceQuery, maxItems, skipCount);
|
||||
}
|
||||
@@ -511,7 +514,7 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
public long countWorkflows(final WorkflowInstanceQuery workflowInstanceQuery)
|
||||
{
|
||||
// MNT-9074 My Tasks fails to render if tasks quantity is excessive
|
||||
if (workflowInstanceQuery.getWorkflowDefinitionId() == null)
|
||||
if (workflowInstanceQuery.getWorkflowDefinitionId() == null && workflowInstanceQuery.getEngineId() == null)
|
||||
{
|
||||
List<String> ids = Arrays.asList(registry.getWorkflowComponents());
|
||||
|
||||
@@ -526,11 +529,36 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
return total;
|
||||
}
|
||||
|
||||
String engineId = BPMEngineRegistry.getEngineId(workflowInstanceQuery.getWorkflowDefinitionId());
|
||||
|
||||
String engineId = workflowInstanceQuery.getEngineId();
|
||||
if(engineId == null) {
|
||||
engineId = BPMEngineRegistry.getEngineId(workflowInstanceQuery.getWorkflowDefinitionId());
|
||||
}
|
||||
WorkflowComponent component = getWorkflowComponent(engineId);
|
||||
return component.countWorkflows(workflowInstanceQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countTasks(WorkflowTaskQuery workflowTaskQuery) {
|
||||
long total = 0;
|
||||
if (workflowTaskQuery.getEngineId() != null)
|
||||
{
|
||||
TaskComponent component = registry.getTaskComponent(workflowTaskQuery.getEngineId());
|
||||
total = component.countTasks(workflowTaskQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<String> ids = Arrays.asList(registry.getTaskComponents());
|
||||
for (String id : ids)
|
||||
{
|
||||
TaskComponent component = registry.getTaskComponent(id);
|
||||
total += component.countTasks(workflowTaskQuery);
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -889,11 +917,16 @@ public class WorkflowServiceImpl implements WorkflowService
|
||||
public List<WorkflowTask> queryTasks(WorkflowTaskQuery query, boolean sameSession)
|
||||
{
|
||||
// extract task component to perform query
|
||||
String engineId = null;
|
||||
String engineId = query.getEngineId();
|
||||
|
||||
String processId = query.getProcessId();
|
||||
if (processId != null)
|
||||
{
|
||||
engineId = BPMEngineRegistry.getEngineId(processId);
|
||||
String workflowEngineId = BPMEngineRegistry.getEngineId(processId);
|
||||
if (engineId != null && !engineId.equals(workflowEngineId)) { throw new WorkflowException(
|
||||
"Cannot query for tasks across multiple task components: " + engineId + ", " + workflowEngineId);
|
||||
}
|
||||
engineId = workflowEngineId;
|
||||
}
|
||||
String taskId = query.getTaskId();
|
||||
if (taskId != null)
|
||||
|
@@ -1577,6 +1577,24 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
||||
return queryTasks(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countTasks(WorkflowTaskQuery query) {
|
||||
long totalCount = 0;
|
||||
|
||||
WorkflowTaskState taskState = query.getTaskState();
|
||||
if(WorkflowTaskState.COMPLETED.equals(taskState) == false)
|
||||
{
|
||||
totalCount += createRuntimeTaskQuery(query).count();
|
||||
}
|
||||
|
||||
// Depending on the state, history should be included/excluded as well
|
||||
if(WorkflowTaskState.IN_PROGRESS.equals(taskState) == false)
|
||||
{
|
||||
totalCount += createHistoricTaskQuery(query).count();
|
||||
}
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1604,67 +1622,7 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
||||
// so no use in querying runtime tasks if not active
|
||||
if (!Boolean.FALSE.equals(query.isActive()))
|
||||
{
|
||||
// Add task name
|
||||
TaskQuery taskQuery = taskService.createTaskQuery();
|
||||
|
||||
if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled())
|
||||
{
|
||||
// Filter by tenant domain.
|
||||
taskQuery.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
|
||||
}
|
||||
|
||||
if (query.getTaskName() != null)
|
||||
{
|
||||
// Task 'key' is stored as variable on task
|
||||
String formKey = query.getTaskName().toPrefixString(namespaceService);
|
||||
taskQuery.taskVariableValueEquals(ActivitiConstants.PROP_TASK_FORM_KEY, formKey);
|
||||
}
|
||||
|
||||
if (query.getProcessId() != null)
|
||||
{
|
||||
String processInstanceId = createLocalId(query.getProcessId());
|
||||
taskQuery.processInstanceId(processInstanceId);
|
||||
}
|
||||
|
||||
if (query.getProcessName() != null)
|
||||
{
|
||||
String processName = getProcessNameMTSafe(query.getProcessName());
|
||||
taskQuery.processDefinitionKey(processName);
|
||||
}
|
||||
|
||||
if (query.getWorkflowDefinitionName() != null)
|
||||
{
|
||||
String processName = factory.getProcessKey(query.getWorkflowDefinitionName());
|
||||
taskQuery.processDefinitionKey(processName);
|
||||
}
|
||||
|
||||
if (query.getActorId() != null)
|
||||
{
|
||||
taskQuery.taskAssignee(query.getActorId());
|
||||
}
|
||||
|
||||
if (query.getTaskId() != null)
|
||||
{
|
||||
String taskId = createLocalId(query.getTaskId());
|
||||
taskQuery.taskId(taskId);
|
||||
}
|
||||
|
||||
// Custom task properties
|
||||
if (query.getTaskCustomProps() != null)
|
||||
{
|
||||
addTaskPropertiesToQuery(query.getTaskCustomProps(), taskQuery);
|
||||
}
|
||||
|
||||
if (query.getProcessCustomProps() != null)
|
||||
{
|
||||
addProcessPropertiesToQuery(query.getProcessCustomProps(), taskQuery);
|
||||
}
|
||||
// Add ordering
|
||||
if (query.getOrderBy() != null)
|
||||
{
|
||||
WorkflowTaskQuery.OrderBy[] orderBy = query.getOrderBy();
|
||||
orderQuery(taskQuery, orderBy);
|
||||
}
|
||||
TaskQuery taskQuery = createRuntimeTaskQuery(query);
|
||||
|
||||
List<Task> results;
|
||||
int limit = query.getLimit();
|
||||
@@ -1819,7 +1777,95 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
||||
}
|
||||
}
|
||||
|
||||
private TaskQuery createRuntimeTaskQuery(WorkflowTaskQuery query)
|
||||
{
|
||||
// Add task name
|
||||
TaskQuery taskQuery = taskService.createTaskQuery();
|
||||
|
||||
if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled())
|
||||
{
|
||||
// Filter by tenant domain.
|
||||
taskQuery.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
|
||||
} else if(tenantService.isEnabled() && !TenantUtil.isCurrentDomainDefault() && !StringUtils.isEmpty(TenantUtil.getCurrentDomain())) {
|
||||
// Process definition keys are prefixed with the tenant ID, in case MT is enabled and
|
||||
// deployments are done in tenant-context
|
||||
taskQuery.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
|
||||
}
|
||||
|
||||
if (query.getTaskName() != null)
|
||||
{
|
||||
// Task 'key' is stored as variable on task
|
||||
String formKey = query.getTaskName().toPrefixString(namespaceService);
|
||||
taskQuery.taskVariableValueEquals(ActivitiConstants.PROP_TASK_FORM_KEY, formKey);
|
||||
}
|
||||
|
||||
if (query.getProcessId() != null)
|
||||
{
|
||||
String processInstanceId = createLocalId(query.getProcessId());
|
||||
taskQuery.processInstanceId(processInstanceId);
|
||||
}
|
||||
|
||||
if (query.getProcessName() != null)
|
||||
{
|
||||
String processName = getProcessNameMTSafe(query.getProcessName());
|
||||
taskQuery.processDefinitionKey(processName);
|
||||
}
|
||||
|
||||
if (query.getWorkflowDefinitionName() != null)
|
||||
{
|
||||
String processName = factory.getProcessKey(query.getWorkflowDefinitionName());
|
||||
taskQuery.processDefinitionKey(processName);
|
||||
}
|
||||
|
||||
if (query.getActorId() != null)
|
||||
{
|
||||
taskQuery.taskAssignee(query.getActorId());
|
||||
}
|
||||
|
||||
if (query.getTaskId() != null)
|
||||
{
|
||||
String taskId = createLocalId(query.getTaskId());
|
||||
taskQuery.taskId(taskId);
|
||||
}
|
||||
|
||||
// Custom task properties
|
||||
if (query.getTaskCustomProps() != null)
|
||||
{
|
||||
addTaskPropertiesToQuery(query.getTaskCustomProps(), taskQuery);
|
||||
}
|
||||
|
||||
if (query.getProcessCustomProps() != null)
|
||||
{
|
||||
addProcessPropertiesToQuery(query.getProcessCustomProps(), taskQuery);
|
||||
}
|
||||
// Add ordering
|
||||
if (query.getOrderBy() != null)
|
||||
{
|
||||
WorkflowTaskQuery.OrderBy[] orderBy = query.getOrderBy();
|
||||
orderQuery(taskQuery, orderBy);
|
||||
}
|
||||
|
||||
return taskQuery;
|
||||
}
|
||||
|
||||
private List<WorkflowTask> queryHistoricTasks(WorkflowTaskQuery query)
|
||||
{
|
||||
HistoricTaskInstanceQuery historicQuery = createHistoricTaskQuery(query);
|
||||
|
||||
List<HistoricTaskInstance> results;
|
||||
int limit = query.getLimit();
|
||||
if (limit > 0)
|
||||
{
|
||||
results = historicQuery.listPage(0, limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
results = historicQuery.list();
|
||||
}
|
||||
return getValidHistoricTasks(results);
|
||||
}
|
||||
|
||||
private HistoricTaskInstanceQuery createHistoricTaskQuery(WorkflowTaskQuery query)
|
||||
{
|
||||
HistoricTaskInstanceQuery historicQuery = historyService.createHistoricTaskInstanceQuery().finished();
|
||||
|
||||
@@ -1827,6 +1873,10 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
||||
{
|
||||
// Filter by tenant domain
|
||||
historicQuery.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
|
||||
} else if(tenantService.isEnabled() && !TenantUtil.isCurrentDomainDefault() && !StringUtils.isEmpty(TenantUtil.getCurrentDomain())) {
|
||||
// Process definition keys are prefixed with the tenant ID, in case MT is enabled and
|
||||
// deployments are done in tenant-context
|
||||
historicQuery.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
|
||||
}
|
||||
|
||||
if (query.getTaskId() != null)
|
||||
@@ -1891,17 +1941,7 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
||||
orderQuery(historicQuery, query.getOrderBy());
|
||||
}
|
||||
|
||||
List<HistoricTaskInstance> results;
|
||||
int limit = query.getLimit();
|
||||
if (limit > 0)
|
||||
{
|
||||
results = historicQuery.listPage(0, limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
results = historicQuery.list();
|
||||
}
|
||||
return getValidHistoricTasks(results);
|
||||
return historicQuery;
|
||||
}
|
||||
|
||||
private void addTaskPropertiesToQuery(Map<QName, Object> taskCustomProps,
|
||||
@@ -2271,6 +2311,12 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
||||
query = historyService.createHistoricProcessInstanceQuery().finished();
|
||||
}
|
||||
|
||||
if(activitiUtil.isMultiTenantWorkflowDeploymentEnabled() && tenantService.isEnabled() && !TenantUtil.isCurrentDomainDefault() && !StringUtils.isEmpty(TenantUtil.getCurrentDomain())) {
|
||||
// Process definition keys are prefixed with the tenant ID, in case MT is enabled and
|
||||
// deployments are done in tenant-context
|
||||
query.processDefinitionKey("@" + TenantUtil.getCurrentDomain() + "@%");
|
||||
}
|
||||
|
||||
if(processDefId!=null)
|
||||
{
|
||||
query = query.processDefinitionId(processDefId);
|
||||
|
@@ -906,6 +906,11 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
return getWorkflows(workflowInstanceQuery).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countTasks(WorkflowTaskQuery query) {
|
||||
return queryTasks(query).size();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<ProcessInstance> getProcessInstances(final WorkflowInstanceQuery query)
|
||||
{
|
||||
|
@@ -40,6 +40,7 @@ public class WorkflowInstanceQuery
|
||||
private Date endBefore;
|
||||
private Date endAfter;
|
||||
private List<String> excludedDefinitions;
|
||||
private String engine;
|
||||
|
||||
// Custom properties
|
||||
// Value for Date property must be Map<DatePosition, Date>
|
||||
@@ -146,4 +147,12 @@ public class WorkflowInstanceQuery
|
||||
this.excludedDefinitions = excludedDefinitions;
|
||||
}
|
||||
|
||||
public void setEngineId(String engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public String getEngineId() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -508,6 +508,14 @@ public interface WorkflowService
|
||||
@Auditable(parameters = {"query"})
|
||||
public List<WorkflowTask> queryTasks(WorkflowTaskQuery query, boolean sameSession);
|
||||
|
||||
/**
|
||||
* Get the number of tasks matching the given query
|
||||
*
|
||||
* @param workflowTaskQuery the filter by which tasks are queried
|
||||
* @return count of matching tasks
|
||||
*/
|
||||
public long countTasks(WorkflowTaskQuery workflowTaskQuery);
|
||||
|
||||
/**
|
||||
* Update the Properties and Associations of a Task
|
||||
*
|
||||
|
Reference in New Issue
Block a user