Search in sources :

Example 1 with HistoricProcessInstanceQuery

use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.

the class Assert method assertProcessInstanceFinished.

/**
 * Assertion to check that a process instance is finished.
 *
 * @param processInstanceId
 *            The process instance identifier
 * @param historyService
 *            The Flowable's history service used to request the Flowable engine about historic process instances.
 */
public static void assertProcessInstanceFinished(final String processInstanceId, final HistoryService historyService) {
    final HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
    final HistoricProcessInstance processInstance = query.processInstanceId(processInstanceId).finished().singleResult();
    assertNotNull(processInstance);
}
Also used : HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance)

Example 2 with HistoricProcessInstanceQuery

use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.

the class ProcessInstanceCompletedEventListener method createLogData.

@Override
protected AbstractFlowLogData createLogData(final FlowableEvent event) {
    if (event instanceof FlowableEntityEventImpl) {
        final FlowableEntityEventImpl eventImpl = (FlowableEntityEventImpl) event;
        final String processInstanceId = eventImpl.getProcessInstanceId();
        this.log.fine("The process instance '" + processInstanceId + "' is completed.");
        final HistoricProcessInstanceQuery processQuery = this.historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables();
        final HistoricProcessInstance processResult = processQuery.singleResult();
        final Map<String, Object> processVariables = processResult.getProcessVariables();
        final String flowInstanceId = (String) processVariables.get(VAR_PETALS_FLOW_INSTANCE_ID);
        final String flowStepId = (String) processVariables.get(VAR_PETALS_FLOW_STEP_ID);
        if (this.isFlowTracingEnabled(processVariables)) {
            return new ProcessInstanceFlowStepEndLogData(flowInstanceId, flowStepId);
        } else {
            return null;
        }
    } else {
        this.log.warning("Unexpected event implementation: " + event.getClass().getName());
        return null;
    }
}
Also used : HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) FlowableEntityEventImpl(org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl) ProcessInstanceFlowStepEndLogData(org.ow2.petals.flowable.monitoring.ProcessInstanceFlowStepEndLogData)

Example 3 with HistoricProcessInstanceQuery

use of org.flowable.engine.history.HistoricProcessInstanceQuery in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method myProcess.

/**
 * 我发起的流程
 *
 * @return
 */
@Override
public TableDataInfo<WfTaskVo> myProcess(PageQuery pageQuery) {
    Page<WfTaskVo> page = new Page<>();
    Long userId = LoginHelper.getUserId();
    HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().startedBy(userId.toString()).orderByProcessInstanceStartTime().desc();
    int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
    List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.listPage(offset, pageQuery.getPageSize());
    page.setTotal(historicProcessInstanceQuery.count());
    List<WfTaskVo> taskVoList = new ArrayList<>();
    for (HistoricProcessInstance hisIns : historicProcessInstances) {
        WfTaskVo taskVo = new WfTaskVo();
        taskVo.setCreateTime(hisIns.getStartTime());
        taskVo.setFinishTime(hisIns.getEndTime());
        taskVo.setProcInsId(hisIns.getId());
        // 计算耗时
        if (Objects.nonNull(hisIns.getEndTime())) {
            long time = hisIns.getEndTime().getTime() - hisIns.getStartTime().getTime();
            taskVo.setDuration(getDate(time));
        } else {
            long time = System.currentTimeMillis() - hisIns.getStartTime().getTime();
            taskVo.setDuration(getDate(time));
        }
        // 流程部署实例信息
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(hisIns.getDeploymentId()).singleResult();
        taskVo.setDeployId(hisIns.getDeploymentId());
        taskVo.setProcDefId(hisIns.getProcessDefinitionId());
        taskVo.setProcDefName(hisIns.getProcessDefinitionName());
        taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());
        taskVo.setCategory(deployment.getCategory());
        // 当前所处流程 todo: 本地启动放开以下注释
        // List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).list();
        // if (CollectionUtils.isNotEmpty(taskList)) {
        // flowTask.setTaskId(taskList.get(0).getId());
        // } else {
        // List<HistoricTaskInstance> historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisIns.getId()).orderByHistoricTaskInstanceEndTime().desc().list();
        // flowTask.setTaskId(historicTaskInstance.get(0).getId());
        // }
        taskVoList.add(taskVo);
    }
    page.setRecords(taskVoList);
    return TableDataInfo.build(page);
}
Also used : HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) Deployment(org.flowable.engine.repository.Deployment) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 4 with HistoricProcessInstanceQuery

use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.

the class AdminOperations method purgeProcessInstance.

/**
 * Admin utility operation associated to {@link AdminRuntimeService#purgeProcessInstance(String, boolean)}
 */
public static List<String> purgeProcessInstance(final String procInstId, final boolean returnsCorrelatedFlows, final ProcessEngine flowableEngine) throws PetalsException {
    assert procInstId != null;
    assert !procInstId.trim().isEmpty();
    final List<String> result = new LinkedList<>();
    final HistoricProcessInstanceQuery procInstQuery = flowableEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(procInstId).includeProcessVariables();
    final HistoricProcessInstance procInst = procInstQuery.singleResult();
    if (procInst == null) {
        throw new ProcessInstanceNotFoundException(procInstId);
    } else {
        final String procInstFlowId = (String) procInst.getProcessVariables().get(FlowableSEConstants.Flowable.VAR_PETALS_FLOW_INSTANCE_ID);
        if (procInstFlowId != null) {
            result.add(procInstFlowId);
        }
        if (returnsCorrelatedFlows) {
            final String procInstCorrelatedFlowId = (String) procInst.getProcessVariables().get(FlowableSEConstants.Flowable.VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
            if (procInstCorrelatedFlowId != null) {
                result.add(procInstCorrelatedFlowId);
            }
            final HistoricTaskInstanceQuery procInstTasksQuery = flowableEngine.getHistoryService().createHistoricTaskInstanceQuery().processInstanceId(procInstId).includeTaskLocalVariables();
            // TODO: We should be able to filter on task local variable, but it seems to not work
            // .taskVariableExists(FlowableSEConstants.Flowable.VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
            final List<HistoricTaskInstance> procInstTasks = procInstTasksQuery.list();
            for (final HistoricTaskInstance procInstTask : procInstTasks) {
                final String procInstTaskCorrelatedFlowId = (String) procInstTask.getTaskLocalVariables().get(FlowableSEConstants.Flowable.VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
                if (procInstTaskCorrelatedFlowId != null) {
                    result.add(procInstTaskCorrelatedFlowId);
                }
            }
        }
        flowableEngine.getHistoryService().deleteHistoricProcessInstance(procInstId);
        return result;
    }
}
Also used : HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) ProcessInstanceNotFoundException(org.ow2.petals.se.flowable.clientserver.api.admin.exception.ProcessInstanceNotFoundException) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) LinkedList(java.util.LinkedList)

Example 5 with HistoricProcessInstanceQuery

use of org.flowable.engine.history.HistoricProcessInstanceQuery in project petals-se-flowable by petalslink.

the class AdminOperations method undeployProcessDefinition.

/**
 * Admin utility operation associated to {@link AdminRuntimeService#undeployProcessDefinition(String, int)}
 */
public static void undeployProcessDefinition(final String procDefKey, final int procDefVer, final ProcessEngine flowableEngine) throws PetalsException {
    // We look for the process definition
    final ProcessDefinition procDef = flowableEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(procDefKey).processDefinitionVersion(procDefVer).singleResult();
    if (procDef == null) {
        throw new ProcessDefinitionNotFoundException(procDefKey, procDefVer);
    }
    // Check if pending (active or suspended) process instances exist
    final ProcessInstanceQuery procInstsQuery = flowableEngine.getRuntimeService().createProcessInstanceQuery().processDefinitionKey(procDefKey).processDefinitionVersion(procDefVer);
    if (procInstsQuery.count() > 0) {
        // Pending process instance exist for the given process definition. We can't undeploy it.
        throw new ProcessInstanceExistForDefinitionException(procDefKey, procDefVer);
    }
    // Check if ended process instances exist
    final HistoricProcessInstanceQuery endedProcInstsQuery = flowableEngine.getHistoryService().createHistoricProcessInstanceQuery().processDefinitionKey(procDefKey).processDefinitionVersion(procDefVer).finished();
    if (endedProcInstsQuery.count() > 0) {
        // Ended process instance exist for the given process definition. We can't undeploy it.
        throw new ProcessInstanceExistForDefinitionException(procDefKey, procDefVer);
    }
    // We undeploy the process definition
    try {
        flowableEngine.getRepositoryService().deleteDeployment(procDef.getDeploymentId());
    } catch (final RuntimeException e) {
        throw new PetalsException(String.format("An error occurs trying to undeploy the process definition '%s' in its version %d", procDefKey, procDefVer), e);
    }
}
Also used : ProcessInstanceQuery(org.flowable.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) ProcessInstanceExistForDefinitionException(org.ow2.petals.se.flowable.clientserver.api.admin.exception.ProcessInstanceExistForDefinitionException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) ProcessDefinitionNotFoundException(org.ow2.petals.se.flowable.clientserver.api.admin.exception.ProcessDefinitionNotFoundException) PetalsException(org.ow2.petals.basisapi.exception.PetalsException)

Aggregations

HistoricProcessInstanceQuery (org.flowable.engine.history.HistoricProcessInstanceQuery)8 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)7 LinkedList (java.util.LinkedList)2 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 WfTaskVo (com.ruoyi.workflow.domain.vo.WfTaskVo)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 FlowableEntityEventImpl (org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl)1 FlowableProcessCancelledEventImpl (org.flowable.engine.delegate.event.impl.FlowableProcessCancelledEventImpl)1 Deployment (org.flowable.engine.repository.Deployment)1 ProcessDefinitionQuery (org.flowable.engine.repository.ProcessDefinitionQuery)1 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)1 ProcessInstanceQuery (org.flowable.engine.runtime.ProcessInstanceQuery)1 HistoricTaskInstance (org.flowable.task.api.history.HistoricTaskInstance)1 HistoricTaskInstanceQuery (org.flowable.task.api.history.HistoricTaskInstanceQuery)1 PetalsException (org.ow2.petals.basisapi.exception.PetalsException)1 GetProcessInstances (org.ow2.petals.components.flowable.generic._1.GetProcessInstances)1 GetProcessInstancesResponse (org.ow2.petals.components.flowable.generic._1.GetProcessInstancesResponse)1