Search in sources :

Example 1 with QueryVariableHolder

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker.QueryVariableHolder in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method getProcesses.

@Override
public CollectionWithPagingInfo<ProcessInfo> getProcesses(Parameters parameters) {
    Paging paging = parameters.getPaging();
    MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(PROCESS_COLLECTION_EQUALS_QUERY_PROPERTIES, null);
    propertyWalker.setSupportedGreaterThanParameters(PROCESS_COLLECTION_GREATERTHAN_QUERY_PROPERTIES);
    propertyWalker.setSupportedLessThanParameters(PROCESS_COLLECTION_LESSTHAN_QUERY_PROPERTIES);
    propertyWalker.enableVariablesSupport(namespaceService, dictionaryService);
    if (parameters.getQuery() != null) {
        QueryHelper.walk(parameters.getQuery(), propertyWalker);
    }
    String status = propertyWalker.getProperty("status", WhereClauseParser.EQUALS);
    String processDefinitionId = propertyWalker.getProperty("processDefinitionId", WhereClauseParser.EQUALS);
    String businessKey = propertyWalker.getProperty("businessKey", WhereClauseParser.EQUALS);
    String processDefinitionKey = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.EQUALS);
    String startUserId = propertyWalker.getProperty("startUserId", WhereClauseParser.EQUALS);
    Date startedAtGreaterThan = propertyWalker.getProperty("startedAt", WhereClauseParser.GREATERTHAN, Date.class);
    Date startedAtLessThan = propertyWalker.getProperty("startedAt", WhereClauseParser.LESSTHAN, Date.class);
    Date endedAtGreaterThan = propertyWalker.getProperty("endedAt", WhereClauseParser.GREATERTHAN, Date.class);
    Date endedAtLessThan = propertyWalker.getProperty("endedAt", WhereClauseParser.LESSTHAN, Date.class);
    Boolean includeVariables = propertyWalker.getProperty("includeVariables", WhereClauseParser.EQUALS, Boolean.class);
    if (status != null && PROCESS_STATUS_LIST.contains(status) == false) {
        throw new InvalidArgumentException("Invalid status parameter: " + status);
    }
    List<SortColumn> sortList = parameters.getSorting();
    SortColumn sortColumn = null;
    if (sortList != null && sortList.size() > 0) {
        if (sortList.size() != 1) {
            throw new InvalidArgumentException("Only one order by parameter is supported");
        }
        sortColumn = sortList.get(0);
    }
    final HistoricProcessInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery();
    if (processDefinitionId != null)
        query.processDefinitionId(processDefinitionId);
    if (businessKey != null)
        query.processInstanceBusinessKey(businessKey);
    if (processDefinitionKey != null) {
        if (tenantService.isEnabled() && deployWorkflowsInTenant) {
            if (processDefinitionKey.startsWith("@" + TenantUtil.getCurrentDomain() + "@")) {
                query.processDefinitionKey(processDefinitionKey);
            } else {
                query.processDefinitionKey("@" + TenantUtil.getCurrentDomain() + "@" + processDefinitionKey);
            }
        } else {
            query.processDefinitionKey(processDefinitionKey);
        }
    }
    if (startUserId != null)
        query.startedBy(startUserId);
    if (startedAtGreaterThan != null)
        query.startedAfter(startedAtGreaterThan);
    if (startedAtLessThan != null)
        query.startedBefore(startedAtLessThan);
    if (endedAtGreaterThan != null)
        query.finishedAfter(endedAtGreaterThan);
    if (endedAtLessThan != null)
        query.finishedBefore(endedAtLessThan);
    if (status == null || PROCESS_STATUS_ACTIVE.equals(status)) {
        query.unfinished();
    } else if (PROCESS_STATUS_COMPLETED.equals(status)) {
        query.finished();
        query.notDeleted();
    } else if (PROCESS_STATUS_DELETED.equals(status)) {
        query.deleted();
    }
    if (includeVariables != null && includeVariables) {
        query.includeProcessVariables();
    }
    List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
    if (variableProperties != null) {
        for (QueryVariableHolder queryVariableHolder : variableProperties) {
            if (queryVariableHolder.getOperator() == WhereClauseParser.EQUALS) {
                query.variableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
            } else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHAN) {
                query.variableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
            } else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHANOREQUALS) {
                query.variableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
            } else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHAN) {
                query.variableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
            } else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHANOREQUALS) {
                query.variableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
            } else if (queryVariableHolder.getOperator() == WhereClauseParser.MATCHES) {
                if (queryVariableHolder.getPropertyValue() instanceof String == false) {
                    throw new InvalidArgumentException("the matches operator can only be used with a String value for property " + queryVariableHolder.getPropertyName());
                }
                if (((String) queryVariableHolder.getPropertyValue()).startsWith("(?i)")) {
                    query.variableValueLikeIgnoreCase(queryVariableHolder.getPropertyName(), ((String) queryVariableHolder.getPropertyValue()).substring("(?i)".length()).toLowerCase());
                } else {
                    query.variableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
                }
            } else if (queryVariableHolder.getOperator() == WhereClauseParser.NEGATION) {
                query.variableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
            } else {
                throw new InvalidArgumentException("variable " + queryVariableHolder.getPropertyName() + " can only be used with an =, >, >=, <=, <, not, matches comparison type");
            }
        }
    }
    if (authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
        // Admin is allowed to read all processes in the current tenant
        if (tenantService.isEnabled()) {
            query.variableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
        }
    } else {
        // If non-admin user, involvement in the process is required (either owner, assignee or externally involved).
        query.involvedUser(AuthenticationUtil.getRunAsUser());
    }
    if (sortColumn != null) {
        if (PROCESS_COLLECTION_SORT_PROPERTIES.contains(sortColumn.column)) {
            if ("processDefinitionId".equalsIgnoreCase(sortColumn.column)) {
                query.orderByProcessDefinitionId();
            } else if ("id".equalsIgnoreCase(sortColumn.column)) {
                query.orderByProcessInstanceId();
            } else if ("businessKey".equalsIgnoreCase(sortColumn.column)) {
                query.orderByProcessInstanceBusinessKey();
            } else if ("startedAt".equalsIgnoreCase(sortColumn.column)) {
                query.orderByProcessInstanceStartTime();
            } else if ("endedAt".equalsIgnoreCase(sortColumn.column)) {
                query.orderByProcessInstanceEndTime();
            } else if ("durationInMillis".equalsIgnoreCase(sortColumn.column)) {
                query.orderByProcessInstanceDuration();
            }
        } else {
            throw new InvalidArgumentException("sort " + sortColumn.column + " is not supported, supported items are " + Arrays.toString(PROCESS_COLLECTION_SORT_PROPERTIES.toArray()));
        }
        if (sortColumn.asc) {
            query.asc();
        } else {
            query.desc();
        }
    } else {
        query.orderByProcessInstanceStartTime().desc();
    }
    List<HistoricProcessInstance> processInstances = query.listPage(paging.getSkipCount(), paging.getMaxItems());
    int totalCount = (int) query.count();
    List<ProcessInfo> page = new ArrayList<ProcessInfo>(processInstances.size());
    Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
    for (HistoricProcessInstance processInstance : processInstances) {
        ProcessInfo processInfo = createProcessInfo(processInstance);
        if (includeVariables != null && includeVariables) {
            if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId()) == false) {
                StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processInfo.getProcessDefinitionId());
                if (startFormData != null) {
                    String formKey = startFormData.getFormKey();
                    definitionTypeMap.put(processInfo.getProcessDefinitionId(), getWorkflowFactory().getTaskFullTypeDefinition(formKey, true));
                }
            }
            if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId())) {
                // Convert raw variables to Variable objects
                List<Variable> resultingVariables = restVariableHelper.getVariables(processInstance.getProcessVariables(), definitionTypeMap.get(processInfo.getProcessDefinitionId()));
                processInfo.setProcessVariables(resultingVariables);
            }
        }
        page.add(processInfo);
    }
    return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
Also used : Variable(org.alfresco.rest.workflow.api.model.Variable) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HashMap(java.util.HashMap) Paging(org.alfresco.rest.framework.resource.parameters.Paging) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) QueryVariableHolder(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker.QueryVariableHolder) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) Date(java.util.Date) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) StartFormData(org.activiti.engine.form.StartFormData)

Example 2 with QueryVariableHolder

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker.QueryVariableHolder in project alfresco-remote-api by Alfresco.

the class TasksImpl method getTasks.

@Override
public CollectionWithPagingInfo<Task> getTasks(Parameters parameters) {
    Paging paging = parameters.getPaging();
    MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(TASK_COLLECTION_EQUALS_QUERY_PROPERTIES, TASK_COLLECTION_MATCHES_QUERY_PROPERTIES);
    propertyWalker.setSupportedGreaterThanParameters(TASK_COLLECTION_GREATERTHAN_QUERY_PROPERTIES);
    propertyWalker.setSupportedGreaterThanOrEqualParameters(TASK_COLLECTION_GREATERTHANOREQUAL_QUERY_PROPERTIES);
    propertyWalker.setSupportedLessThanParameters(TASK_COLLECTION_LESSTHAN_QUERY_PROPERTIES);
    propertyWalker.setSupportedLessThanOrEqualParameters(TASK_COLLECTION_LESSTHANOREQUAL_QUERY_PROPERTIES);
    propertyWalker.enableVariablesSupport(namespaceService, dictionaryService);
    if (parameters.getQuery() != null) {
        QueryHelper.walk(parameters.getQuery(), propertyWalker);
    }
    String status = propertyWalker.getProperty("status", WhereClauseParser.EQUALS);
    String assignee = propertyWalker.getProperty("assignee", WhereClauseParser.EQUALS);
    String assigneeLike = propertyWalker.getProperty("assignee", WhereClauseParser.MATCHES);
    String owner = propertyWalker.getProperty("owner", WhereClauseParser.EQUALS);
    String ownerLike = propertyWalker.getProperty("owner", WhereClauseParser.MATCHES);
    String candidateUser = propertyWalker.getProperty("candidateUser", WhereClauseParser.EQUALS);
    String candidateGroup = propertyWalker.getProperty("candidateGroup", WhereClauseParser.EQUALS);
    String name = propertyWalker.getProperty("name", WhereClauseParser.EQUALS);
    String nameLike = propertyWalker.getProperty("name", WhereClauseParser.MATCHES);
    String description = propertyWalker.getProperty("description", WhereClauseParser.EQUALS);
    String descriptionLike = propertyWalker.getProperty("description", WhereClauseParser.MATCHES);
    Integer priority = propertyWalker.getProperty("priority", WhereClauseParser.EQUALS, Integer.class);
    Integer priorityGreaterThanOrEquals = propertyWalker.getProperty("priority", WhereClauseParser.GREATERTHANOREQUALS, Integer.class);
    Integer priorityLessThanOrEquals = propertyWalker.getProperty("priority", WhereClauseParser.LESSTHANOREQUALS, Integer.class);
    String processInstanceId = propertyWalker.getProperty("processId", WhereClauseParser.EQUALS);
    String processInstanceBusinessKey = propertyWalker.getProperty("processBusinessKey", WhereClauseParser.EQUALS);
    String processInstanceBusinessKeyLike = propertyWalker.getProperty("processBusinessKey", WhereClauseParser.MATCHES);
    String activityDefinitionId = propertyWalker.getProperty("activityDefinitionId", WhereClauseParser.EQUALS);
    String activityDefinitionIdLike = propertyWalker.getProperty("activityDefinitionId", WhereClauseParser.MATCHES);
    String processDefinitionId = propertyWalker.getProperty("processDefinitionId", WhereClauseParser.EQUALS);
    String processDefinitionKey = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.EQUALS);
    String processDefinitionKeyLike = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.MATCHES);
    String processDefinitionName = propertyWalker.getProperty("processDefinitionName", WhereClauseParser.EQUALS);
    String processDefinitionNameLike = propertyWalker.getProperty("processDefinitionName", WhereClauseParser.MATCHES);
    Date startedAt = propertyWalker.getProperty("startedAt", WhereClauseParser.EQUALS, Date.class);
    Date startedAtGreaterThan = propertyWalker.getProperty("startedAt", WhereClauseParser.GREATERTHAN, Date.class);
    Date startedAtLessThan = propertyWalker.getProperty("startedAt", WhereClauseParser.LESSTHAN, Date.class);
    Date endedAt = propertyWalker.getProperty("endedAt", WhereClauseParser.EQUALS, Date.class);
    Date endedAtGreaterThan = propertyWalker.getProperty("endedAt", WhereClauseParser.GREATERTHAN, Date.class);
    Date endedAtLessThan = propertyWalker.getProperty("endedAt", WhereClauseParser.LESSTHAN, Date.class);
    Date dueAt = propertyWalker.getProperty("dueAt", WhereClauseParser.EQUALS, Date.class);
    Date dueAtGreaterThan = propertyWalker.getProperty("dueAt", WhereClauseParser.GREATERTHAN, Date.class);
    Date dueAtLessThan = propertyWalker.getProperty("dueAt", WhereClauseParser.LESSTHAN, Date.class);
    Boolean includeProcessVariables = propertyWalker.getProperty("includeProcessVariables", WhereClauseParser.EQUALS, Boolean.class);
    Boolean includeTaskVariables = propertyWalker.getProperty("includeTaskVariables", WhereClauseParser.EQUALS, Boolean.class);
    List<SortColumn> sortList = parameters.getSorting();
    SortColumn sortColumn = null;
    if (sortList != null && sortList.size() > 0) {
        if (sortList.size() != 1) {
            throw new InvalidArgumentException("Only one order by parameter is supported");
        }
        sortColumn = sortList.get(0);
    }
    List<Task> page = null;
    int totalCount = 0;
    if (status == null || STATUS_ACTIVE.equals(status)) {
        TaskQuery query = activitiProcessEngine.getTaskService().createTaskQuery();
        if (assignee != null)
            query.taskAssignee(assignee);
        if (assigneeLike != null)
            query.taskAssigneeLike(assigneeLike);
        if (owner != null)
            query.taskOwner(owner);
        if (ownerLike != null)
            query.taskOwner(ownerLike);
        if (candidateUser != null) {
            Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, candidateUser, false);
            if (parents != null) {
                List<String> authorities = new ArrayList<String>();
                authorities.addAll(parents);
                // there's a limitation in at least Oracle for using an IN statement with more than 1000 items
                if (parents.size() > 1000) {
                    authorities = authorities.subList(0, 1000);
                }
                if (authorities.size() > 0) {
                    query.taskCandidateGroupIn(authorities);
                } else {
                    query.taskCandidateUser(candidateUser);
                }
            }
        }
        if (candidateGroup != null)
            query.taskCandidateGroup(candidateGroup);
        if (name != null)
            query.taskName(name);
        if (nameLike != null)
            query.taskNameLike(nameLike);
        if (description != null)
            query.taskDescription(description);
        if (descriptionLike != null)
            query.taskDescriptionLike(descriptionLike);
        if (priority != null)
            query.taskPriority(priority);
        if (priorityGreaterThanOrEquals != null)
            query.taskMinPriority(priorityGreaterThanOrEquals);
        if (priorityLessThanOrEquals != null)
            query.taskMaxPriority(priorityLessThanOrEquals);
        if (processInstanceId != null)
            query.processInstanceId(processInstanceId);
        if (processInstanceBusinessKey != null)
            query.processInstanceBusinessKey(processInstanceBusinessKey);
        if (processInstanceBusinessKeyLike != null)
            query.processInstanceBusinessKeyLike(processInstanceBusinessKeyLike);
        if (activityDefinitionId != null)
            query.taskDefinitionKey(activityDefinitionId);
        if (activityDefinitionIdLike != null)
            query.taskDefinitionKey(activityDefinitionIdLike);
        if (processDefinitionId != null)
            query.processDefinitionId(processDefinitionId);
        if (processDefinitionKey != null)
            query.processDefinitionKey(processDefinitionKey);
        if (processDefinitionKeyLike != null)
            query.processDefinitionKeyLike(processDefinitionKeyLike);
        if (processDefinitionName != null)
            query.processDefinitionName(processDefinitionName);
        if (processDefinitionNameLike != null)
            query.processDefinitionNameLike(processDefinitionNameLike);
        if (dueAt != null)
            query.dueDate(dueAt);
        if (dueAtGreaterThan != null)
            query.dueAfter(dueAtGreaterThan);
        if (dueAtLessThan != null)
            query.dueBefore(dueAtLessThan);
        if (startedAt != null)
            query.taskCreatedOn(startedAt);
        if (startedAtGreaterThan != null)
            query.taskCreatedAfter(startedAtGreaterThan);
        if (startedAtLessThan != null)
            query.taskCreatedBefore(startedAtLessThan);
        if (includeProcessVariables != null && includeProcessVariables) {
            query.includeProcessVariables();
        }
        if (includeTaskVariables != null && includeTaskVariables) {
            query.includeTaskLocalVariables();
        }
        // use the limit set in alfresco-global.properties
        query.limitTaskVariables(taskVariablesLimit);
        List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
        setQueryUsingVariables(query, variableProperties);
        // Add tenant-filtering
        if (tenantService.isEnabled()) {
            query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
        }
        // Add involvement filtering if user is not admin
        if (processInstanceId == null && !authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser()) && candidateUser == null && candidateGroup == null) {
            query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
        }
        setSorting(query, sortColumn);
        List<org.activiti.engine.task.Task> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
        totalCount = (int) query.count();
        page = new ArrayList<Task>(tasks.size());
        Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
        for (org.activiti.engine.task.Task taskInstance : tasks) {
            Task task = new Task(taskInstance);
            task.setFormResourceKey(getFormResourceKey(taskInstance));
            if ((includeProcessVariables != null && includeProcessVariables) || (includeTaskVariables != null && includeTaskVariables)) {
                addVariables(task, includeProcessVariables, includeTaskVariables, taskInstance.getProcessVariables(), taskInstance.getTaskLocalVariables(), definitionTypeMap);
            }
            page.add(task);
        }
    } else if (STATUS_COMPLETED.equals(status) || STATUS_ANY.equals(status)) {
        // Candidate user and group is only supported with STATUS_ACTIVE
        if (candidateUser != null) {
            throw new InvalidArgumentException("Filtering on candidateUser is only allowed in combination with status-parameter 'active'");
        }
        if (candidateGroup != null) {
            throw new InvalidArgumentException("Filtering on candidateGroup is only allowed in combination with status-parameter 'active'");
        }
        HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery();
        if (STATUS_COMPLETED.equals(status))
            query.finished();
        if (assignee != null)
            query.taskAssignee(assignee);
        if (assigneeLike != null)
            query.taskAssigneeLike(assigneeLike);
        if (owner != null)
            query.taskOwner(owner);
        if (ownerLike != null)
            query.taskOwnerLike(ownerLike);
        if (name != null)
            query.taskName(name);
        if (nameLike != null)
            query.taskNameLike(nameLike);
        if (description != null)
            query.taskDescription(description);
        if (descriptionLike != null)
            query.taskDescriptionLike(descriptionLike);
        if (priority != null)
            query.taskPriority(priority);
        if (priorityGreaterThanOrEquals != null)
            query.taskMinPriority(priorityGreaterThanOrEquals);
        if (priorityLessThanOrEquals != null)
            query.taskMaxPriority(priorityLessThanOrEquals);
        if (processInstanceId != null)
            query.processInstanceId(processInstanceId);
        if (processInstanceBusinessKey != null)
            query.processInstanceBusinessKey(processInstanceBusinessKey);
        if (processInstanceBusinessKeyLike != null)
            query.processInstanceBusinessKeyLike(processInstanceBusinessKeyLike);
        if (activityDefinitionId != null)
            query.taskDefinitionKey(activityDefinitionId);
        if (activityDefinitionIdLike != null)
            query.taskDefinitionKey(activityDefinitionIdLike);
        if (processDefinitionId != null)
            query.processDefinitionId(processDefinitionId);
        if (processDefinitionKey != null)
            query.processDefinitionKey(processDefinitionKey);
        if (processDefinitionKeyLike != null)
            query.processDefinitionKeyLike(processDefinitionKeyLike);
        if (processDefinitionName != null)
            query.processDefinitionName(processDefinitionName);
        if (processDefinitionNameLike != null)
            query.processDefinitionNameLike(processDefinitionNameLike);
        if (dueAt != null)
            query.taskDueDate(dueAt);
        if (dueAtGreaterThan != null)
            query.taskDueAfter(dueAtGreaterThan);
        if (dueAtLessThan != null)
            query.taskDueBefore(dueAtLessThan);
        if (startedAt != null)
            query.taskCreatedOn(startedAt);
        if (startedAtGreaterThan != null)
            query.taskCreatedAfter(startedAtGreaterThan);
        if (startedAtLessThan != null)
            query.taskCreatedBefore(startedAtLessThan);
        if (endedAt != null)
            query.taskCompletedOn(endedAt);
        if (endedAtGreaterThan != null)
            query.taskCompletedAfter(endedAtGreaterThan);
        if (endedAtLessThan != null)
            query.taskCompletedBefore(endedAtLessThan);
        if (includeProcessVariables != null && includeProcessVariables) {
            query.includeProcessVariables();
        }
        if (includeTaskVariables != null && includeTaskVariables) {
            query.includeTaskLocalVariables();
        }
        List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
        setQueryUsingVariables(query, variableProperties);
        // Add tenant filtering
        if (tenantService.isEnabled()) {
            query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
        }
        // Add involvement filtering if user is not admin
        if (processInstanceId == null && !authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
            query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
        }
        setSorting(query, sortColumn);
        List<HistoricTaskInstance> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
        totalCount = (int) query.count();
        page = new ArrayList<Task>(tasks.size());
        Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
        for (HistoricTaskInstance taskInstance : tasks) {
            Task task = new Task(taskInstance);
            if ((includeProcessVariables != null && includeProcessVariables) || (includeTaskVariables != null && includeTaskVariables)) {
                addVariables(task, includeProcessVariables, includeTaskVariables, taskInstance.getProcessVariables(), taskInstance.getTaskLocalVariables(), definitionTypeMap);
            }
            page.add(task);
        }
    } else {
        throw new InvalidArgumentException("Invalid status parameter: " + status);
    }
    return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
Also used : Task(org.alfresco.rest.workflow.api.model.Task) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryVariableHolder(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker.QueryVariableHolder) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) TaskQuery(org.activiti.engine.task.TaskQuery) List(java.util.List) ArrayList(java.util.ArrayList) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) Paging(org.alfresco.rest.framework.resource.parameters.Paging) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) Date(java.util.Date) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 Paging (org.alfresco.rest.framework.resource.parameters.Paging)2 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)2 QueryVariableHolder (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker.QueryVariableHolder)2 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2 List (java.util.List)1 Map (java.util.Map)1 StartFormData (org.activiti.engine.form.StartFormData)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)1 TaskQuery (org.activiti.engine.task.TaskQuery)1 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)1 Task (org.alfresco.rest.workflow.api.model.Task)1 Variable (org.alfresco.rest.workflow.api.model.Variable)1