Search in sources :

Example 16 with HistoricTaskInstanceQuery

use of org.activiti.engine.history.HistoricTaskInstanceQuery in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method createHistoricTaskQuery.

private HistoricTaskInstanceQuery createHistoricTaskQuery(WorkflowTaskQuery query) {
    HistoricTaskInstanceQuery historicQuery = historyService.createHistoricTaskInstanceQuery().finished();
    if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled()) {
        // 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) {
        String taskId = createLocalId(query.getTaskId());
        historicQuery.taskId(taskId);
    }
    if (query.getProcessId() != null) {
        String processInstanceId = createLocalId(query.getProcessId());
        historicQuery.processInstanceId(processInstanceId);
    }
    if (query.getTaskName() != null) {
        historicQuery.taskDefinitionKey(query.getTaskName().toPrefixString());
    }
    if (query.getActorId() != null) {
        historicQuery.taskAssignee(query.getActorId());
    }
    if (query.getProcessName() != null) {
        String processName = getProcessNameMTSafe(query.getProcessName());
        historicQuery.processDefinitionKey(processName);
    }
    if (query.getWorkflowDefinitionName() != null) {
        String processName = factory.getProcessKey(query.getWorkflowDefinitionName());
        historicQuery.processDefinitionKey(processName);
    }
    if (query.getTaskCustomProps() != null) {
        addTaskPropertiesToQuery(query.getTaskCustomProps(), historicQuery);
    }
    if (query.getProcessCustomProps() != null) {
        addProcessPropertiesToQuery(query.getProcessCustomProps(), historicQuery);
    }
    if (query.isActive() != null) {
        if (query.isActive()) {
            historicQuery.processUnfinished();
        } else {
            historicQuery.processFinished();
        }
    }
    // Order query
    if (query.getOrderBy() != null) {
        orderQuery(historicQuery, query.getOrderBy());
    }
    return historicQuery;
}
Also used : HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery)

Example 17 with HistoricTaskInstanceQuery

use of org.activiti.engine.history.HistoricTaskInstanceQuery in project my_curd by qinyou.

the class MyCompleteTaskController method query.

// 表格数据
public void query() {
    int pageNumber = getInt("page", 1);
    int pageSize = getInt("rows", 30);
    HistoricTaskInstanceQuery query = ActivitiUtils.getHistoryService().createHistoricTaskInstanceQuery().taskAssignee(WebUtils.getSessionUsername(this)).finished();
    String instanceId = getPara("extra_instanceId");
    if (StringUtils.notEmpty(instanceId)) {
        query.processInstanceId(instanceId);
    }
    String taskName = getPara("extra_taskName");
    if (StringUtils.notEmpty(taskName)) {
        query.taskNameLike("%" + taskName + "%");
    }
    Long total = query.count();
    List<Map<String, Object>> list = new ArrayList<>();
    // 流程实例id 和 发起时间正相关,所以此处排序无问题
    query.orderByProcessInstanceId().desc().orderByHistoricTaskInstanceEndTime().asc().listPage((pageNumber - 1) * pageSize, pageSize).forEach(task -> {
        Map<String, Object> info = new HashMap<>();
        // 任务id
        info.put("id", task.getId());
        // 任务开始时间
        info.put("startTime", task.getStartTime());
        // 任务完成时间
        info.put("endTime", task.getEndTime());
        // 任务名称
        info.put("taskName", task.getName());
        // 任务持续时长(毫秒)
        info.put("duration", task.getDurationInMillis());
        // 流程实例id
        info.put("instanceId", task.getProcessInstanceId());
        HistoricProcessInstance instance = ActivitiUtils.getHistoricProcessInstance(task.getProcessInstanceId(), false);
        info.put("instanceName", instance.getName());
        // 流程发起人
        info.put("startUser", instance.getStartUserId());
        list.add(info);
    });
    renderDatagrid(list, total.intValue());
}
Also used : HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)17 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)14 ArrayList (java.util.ArrayList)7 Deployment (org.activiti.engine.test.Deployment)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 TaskQuery (org.activiti.engine.task.TaskQuery)3 List (java.util.List)2 Map (java.util.Map)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 HistoryService (org.activiti.engine.HistoryService)2 Task (org.activiti.engine.task.Task)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 Paging (org.alfresco.rest.framework.resource.parameters.Paging)2 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)2 Task (org.alfresco.rest.workflow.api.model.Task)2 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)2 WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)1