Search in sources :

Example 6 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project midpoint by Evolveum.

the class WorkItemProvider method createTaskQuery.

// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
    List<ObjectFilter> remainingClauses = components.getRemainderClauses();
    if (!remainingClauses.isEmpty()) {
        throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
    }
    final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
    final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
    final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
    final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
    TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
    if (workItemIdFilter != null) {
        Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
        if (filterValues.size() > 1) {
            throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
        }
        taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
    }
    if (assigneeFilter != null) {
        taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
    }
    if (candidateRolesFilter != null) {
        // TODO what about candidate users? (currently these are not supported)
        List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
        if (!candidateGroups.isEmpty()) {
            taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
        } else {
            // no groups -> no result
            return null;
        }
    }
    if (query != null && query.getPaging() != null) {
        ObjectPaging paging = query.getPaging();
        if (paging.getOrderingInstructions().size() > 1) {
            throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
        } else if (paging.getOrderingInstructions().size() == 1) {
            ItemPath orderBy = paging.getOrderBy();
            if (CREATED_PATH.equivalent(orderBy)) {
                taskQuery = taskQuery.orderByTaskCreateTime();
            } else {
                throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
            }
            switch(paging.getDirection()) {
                case DESCENDING:
                    taskQuery = taskQuery.desc();
                    break;
                case ASCENDING:
                default:
                    taskQuery = taskQuery.asc();
                    break;
            }
        }
    }
    if (includeVariables) {
        return taskQuery.includeTaskLocalVariables().includeProcessVariables();
    } else {
        return taskQuery;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FilterComponents(com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) TaskQuery(org.activiti.engine.task.TaskQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 7 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method internalSearch.

private PageImpl<WorkflowTaskInstanceDto> internalSearch(WorkflowFilterDto filter, Pageable pageable) {
    // if currently logged user can read all task continue
    if (!canReadAllTask()) {
        // if user can't read all task check filter
        if (filter.getCandidateOrAssigned() == null) {
            filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
        } else {
            IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
            if (!identity.getId().equals(securityService.getCurrentId())) {
                throw new ResultCodeException(CoreResultCode.FORBIDDEN, "You do not have permission for access to all tasks!");
            }
        }
    // else is filled candidate and it is equals currently logged user
    }
    String processDefinitionId = filter.getProcessDefinitionId();
    Map<String, Object> equalsVariables = filter.getEqualsVariables();
    TaskQuery query = taskService.createTaskQuery();
    query.active();
    query.includeProcessVariables();
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(filter.getProcessDefinitionKey());
    }
    if (filter.getProcessInstanceId() != null) {
        query.processInstanceId(filter.getProcessInstanceId());
    }
    if (filter.getId() != null) {
        query.taskId(filter.getId().toString());
    }
    if (filter.getCreatedAfter() != null) {
        query.taskCreatedAfter(filter.getCreatedAfter().toDate());
    }
    if (filter.getCreatedBefore() != null) {
        query.taskCreatedBefore(filter.getCreatedBefore().toDate());
    }
    if (equalsVariables != null) {
        for (Entry<String, Object> entry : equalsVariables.entrySet()) {
            query.processVariableValueEquals(entry.getKey(), entry.getValue());
        }
    }
    if (filter.getCandidateOrAssigned() != null) {
        BaseDto dto = lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
        Assert.notNull(dto);
        query.taskCandidateOrAssigned(String.valueOf(dto.getId()));
    }
    query.orderByTaskCreateTime();
    query.desc();
    long count = query.count();
    // it's possible that pageable is null
    List<Task> tasks = null;
    if (pageable == null) {
        tasks = query.list();
    } else {
        tasks = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    }
    List<WorkflowTaskInstanceDto> dtos = new ArrayList<>();
    if (tasks != null) {
        for (Task task : tasks) {
            dtos.add(toResource(task));
        }
    }
    return new PageImpl<WorkflowTaskInstanceDto>(dtos, pageable, count);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Task(org.activiti.engine.task.Task) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) TaskQuery(org.activiti.engine.task.TaskQuery) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 8 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project daijie-example by daijiejay.

the class BaseService method getProcessById.

@Override
public ModelResult<PageResult<Map<String, Object>>> getProcessById(Integer id) {
    List<Map<String, Object>> rows = new ArrayList<>();
    PageResult<Map<String, Object>> datas = new PageResult<>();
    TaskQuery query = taskService.createTaskQuery().processInstanceId(id.toString());
    List<Task> tasks = query.list();
    tasks.forEach(task -> {
        Map<String, Object> row = new HashMap<>();
        row.put("taskId", task.getId());
        row.put("taskName", task.getName());
        row.put("assignee", task.getAssignee());
        row.put("category", task.getCategory());
        row.put("createTime", task.getCreateTime());
        row.put("delegationState", task.getDelegationState());
        row.put("description", task.getDescription());
        row.put("dueDate", task.getDueDate());
        row.put("executionId", task.getExecutionId());
        row.put("formKey", task.getFormKey());
        row.put("owner", task.getOwner());
        row.put("parentTaskId", task.getParentTaskId());
        row.put("priority", task.getPriority());
        row.put("processDefinitionId", task.getProcessDefinitionId());
        row.put("processInstanceId", task.getProcessInstanceId());
        row.put("taskDefinitionKey", task.getTaskDefinitionKey());
        rows.add(row);
    });
    datas.setTotal(query.count());
    datas.setRows(rows);
    return Result.build(datas);
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) TaskQuery(org.activiti.engine.task.TaskQuery) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) PageResult(org.daijie.core.result.PageResult)

Example 9 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project daijie-example by daijiejay.

the class BaseService method getProcessByOperator.

@Override
public ModelResult<PageResult<Map<String, Object>>> getProcessByOperator(String assignee) {
    List<Map<String, Object>> rows = new ArrayList<>();
    PageResult<Map<String, Object>> datas = new PageResult<>();
    TaskQuery query = taskService.createTaskQuery().taskAssignee(assignee);
    List<Task> tasks = query.list();
    tasks.forEach(task -> {
        Map<String, Object> taskVariables = taskService.getVariables(task.getId());
        Map<String, Object> row = new HashMap<>();
        row.put("taskId", task.getId());
        row.put("taskName", task.getName());
        row.put("assignee", task.getAssignee());
        row.put("category", task.getCategory());
        row.put("createTime", task.getCreateTime());
        row.put("delegationState", task.getDelegationState());
        row.put("description", task.getDescription());
        row.put("dueDate", task.getDueDate());
        row.put("executionId", task.getExecutionId());
        row.put("formKey", task.getFormKey());
        row.put("owner", task.getOwner());
        row.put("parentTaskId", task.getParentTaskId());
        row.put("priority", task.getPriority());
        row.put("processDefinitionId", task.getProcessDefinitionId());
        row.put("processInstanceId", task.getProcessInstanceId());
        row.put("taskDefinitionKey", task.getTaskDefinitionKey());
        row.put("checkUserId", taskVariables.get("checkUserId"));
        rows.add(row);
    });
    datas.setTotal(query.count());
    datas.setRows(rows);
    return Result.build(datas);
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) TaskQuery(org.activiti.engine.task.TaskQuery) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) PageResult(org.daijie.core.result.PageResult)

Example 10 with TaskQuery

use of org.activiti.engine.task.TaskQuery in project carbon-business-process by wso2.

the class UserSubstitutionUtils method bulkReassign.

/**
 * Reassign the given tasks or all the tasks if the given task list is null, to the given substitute
 * @param assignee - original user of the tasks
 * @param substitute - user who getting assigned
 * @param taskList - list of tasks to reassign. Leave this null to reassign all tha tasks of the assignee.
 */
public static void bulkReassign(String assignee, String substitute, List<String> taskList) {
    if (taskList != null) {
        // reassign the given tasks
        reassignFromTaskIdsList(taskList, substitute);
    } else {
        // reassign all existing tasks for assignee
        TaskQuery taskQuery = BPMNServerHolder.getInstance().getEngine().getTaskService().createTaskQuery();
        taskQuery.taskAssignee(assignee);
        reassignFromTasksList(taskQuery.list(), substitute);
        transformUnclaimedTasks(assignee, substitute);
    }
// should mark bulk reassign done
}
Also used : TaskQuery(org.activiti.engine.task.TaskQuery)

Aggregations

TaskQuery (org.activiti.engine.task.TaskQuery)120 Task (org.activiti.engine.task.Task)47 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)21 ActivitiException (org.activiti.engine.ActivitiException)20 ArrayList (java.util.ArrayList)18 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)12 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 HashMap (java.util.HashMap)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)4 Test (org.junit.jupiter.api.Test)4 Map (java.util.Map)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)3 Job (org.activiti.engine.runtime.Job)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 HashSet (java.util.HashSet)2 List (java.util.List)2