这里我们已知流程已经部署,我的需求是获取当前流程的所有任务节点,我使用instanceof关键字来进行匹配
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| private List<UserTask> getProcessUserTasks(String processInstanceId) { ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); BpmnModel bpmnModel = repositoryService.getBpmnModel( processInstance.getProcessDefinitionId()); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); Process process = bpmnModel.getProcessById(processDefinition.getKey()); Collection<FlowElement> flowElements = process.getFlowElements(); List<UserTask> userTaskList = new ArrayList<>(); for (FlowElement flowElement : flowElements) { if (flowElement instanceof UserTask) { UserTask userTask = ((UserTask) flowElement); userTaskList.add(userTask); } } return userTaskList; }
|