activiti5轉activiti7 獲取各流程節點


網上都是5或者6版本的 獲取流程圖節點,連線列表的信息。
我想知道用activiti7版本的怎么獲取流程圖各節點信息,
因為我想查出連線和節點信息去設置一些自定義的信息。

``` // 查詢當前的流程實例
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
//獲取當前流程的流程定義processDefinitionEntity,然后根據流程定義獲得所有的節點
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();

 

    processDefinitionEntity.getActivities()
最主要的是 processDefinitionEntity.getActivities() 再activiti7版本沒有這個get方法了。就不知道怎么用了。求教各位大神,幫我研究下。

有效建議:

  /**
   * 獲取流程節點
   *
   * @param definitionId 流程定義ID
   * @param processId 流程ID(可能為子流程),也就是流程定義Key
   * @return
   */
  protected List<FlowElement> getProcessDefinitionNodes(String definitionId, String processId) {
    BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId);
    List<Process> processes = Lists.newArrayList();
    if (StrUtil.isNotEmpty(processId)) {
      processes.add(bpmnModel.getProcessById(processId));
    } else {
      processes = bpmnModel.getProcesses();
    }
    List<FlowElement> flowElements = Lists.newArrayList();
    processes.forEach(process -> flowElements.addAll(process.getFlowElements()));
    return flowElements;
  }  
@GetMapping(value = "process/def/nodes/userTask")
  public AppResult getUserTaskNodes(
      @RequestParam(value = "id") String definitionId,
      @RequestParam(value = "processId", required = false) String processId) {
    List<FlowElement> flowElements = getProcessDefinitionNodes(definitionId, processId);
    List<UserTask> userTasks = Lists.newArrayList();
    flowElements.forEach(
        node -> {
          if (node instanceof UserTask) {
            userTasks.add((UserTask) node);
          }
        });
    return buildSuccess(userTasks);
  }
// 返回數據格式(節點)
{
    "code": 200,
    "message": "操作成功",
    "data": [
        {
            "id": "Activity_14xmp0o",
            "xmlRowNumber": 7,
            "xmlColumnNumber": 5,
            "name": "一級審批",
            "asynchronous": false,
            "notExclusive": false,
            "incomingFlows": [
                {
                    "id": "Flow_1s2ypsj",
                    "xmlRowNumber": 20,
                    "xmlColumnNumber": 5,
                    "sourceRef": "StartEvent_1",
                    "targetRef": "Activity_14xmp0o",
                    "waypoints": [
                        238,
                        470,
                        350,
                        470
                    ]
                }
            ],
            "outgoingFlows": [
                {
                    "id": "Flow_1xbbtsl",
                    "xmlRowNumber": 21,
                    "xmlColumnNumber": 5,
                    "sourceRef": "Activity_14xmp0o",
                    "targetRef": "Gateway_0astncq",
                    "waypoints": [
                        450,
                        470,
                        555,
                        470
                    ]
                }
            ],
            "forCompensation": false,
            "formKey": "one-level",
            "candidateGroups": [
                "one-approval"
            ],
            "extended": false,
            "exclusive": true
        },
        {
            "id": "Activity_19kus41",
            "xmlRowNumber": 11,
            "xmlColumnNumber": 5,
            "name": "二級審批",
            "asynchronous": false,
            "notExclusive": false,
            "incomingFlows": [
                {
                    "id": "Flow_101i5h2",
                    "xmlRowNumber": 34,
                    "xmlColumnNumber": 5,
                    "name": "通過",
                    "conditionExpression": "${gateway==true}",
                    "sourceRef": "Gateway_0astncq",
                    "targetRef": "Activity_19kus41",
                    "waypoints": [
                        580,
                        445,
                        580,
                        340,
                        670,
                        340
                    ]
                }
            ],
            "outgoingFlows": [
                {
                    "id": "Flow_0zdqnmv",
                    "xmlRowNumber": 42,
                    "xmlColumnNumber": 5,
                    "sourceRef": "Activity_19kus41",
                    "targetRef": "Gateway_0jvvxgy",
                    "waypoints": [
                        770,
                        340,
                        875,
                        340
                    ]
                }
            ],
            "forCompensation": false,
            "formKey": "two-level",
            "candidateGroups": [
                "two-approval"
            ],
            "extended": false,
            "exclusive": true
        }
    ]
}

原文鏈接:https://ask.csdn.net/questions/1080491

 

 

Activiti7獲取當前任務節點出口連線(動態生成處理節點)

 

Activiti7 中 PVM,ActivitiImpl,PvmTransition ,ExecutionImpl, TransitionImpl 替代方法。

PVM classes
All classes from the org.activiti.engine.impl.pvm package (and subpackages) have been removed. This is because the PVM (Process Virtual Machine) model has been removed and replaced by a simpler and more lightweight model.

This means that usages of ActivitiImpl, ProcessDefinitionImpl, ExecutionImpl, TransitionImpl are invalid.

Generally, most of the usage of these classes in version 5 came down to getting information that was contained in the process definition. In version 6, all the process definition information can be found through the BpmnModel, which is a Java representation of the BPMN 2.0 XML for the process definition (enhanced to make certain operations and searches easier).

The quickest way to get the BpmnModel for a process definition is to use the org.activiti.engine.impl.util.ProcessDefinitionUtil class:

// The whole model
ProcessDefinitionUtil.getBpmnModel(String processDefinitionId);

// Only the specific process definition
ProcessDefinitionUtil.getProcess(String processDefinitionId);

大致是說:官方為了輕量化,所以就把原來的PVM 流程引擎給優化了、
刪了后推薦我們獲取bpmnModel或者process來獲取模型的參數。

BpmnModel獲取方式可以使用官方推薦的,我這邊交互剛好只有taskId,就用這個做個demo;

// 獲取當前任務
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
//獲取當前模型
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
// 獲取當前節點
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
// 這里不轉也有方法拿到,我這是為了后人閱讀方便
UserTask userTask = (UserTask)flowElement;
//獲取節點出口線段
List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
// 我這邊暫時是解析expression 獲取條件和約定的值返回到前端構造button

原文鏈接:https://blog.csdn.net/weixin_39789689/article/details/106495938

 

Activiti7中沒有getOutgoingTransitions等方法

http://zpycloud.com/archives/1903

 

activiti 當前活動id

https://blog.csdn.net/weixin_39941298/article/details/79445850


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM