如何查询流程实例的位置? [英] How to query the position of a process instance?

查看:201
本文介绍了如何查询流程实例的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的进程中获取单个实例的当前位置。是否可以将id的活动名称作为返回值加上?

I want to get the current position of a single instance in my process. Is it possible to get the name of the activity additionaly to the id as return value?

推荐答案

您可以使用下面的代码,这也将给你活动的名称让你的流程实例的当前位置当进程在多个位置等待时。

You can get the current position of your process instance using the following code, which will also give you the name of the activity(ies) when the process waits in multiple position.

package org.camunda.bpm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;

public class AllActiveActivities {

  public Map<String, String> getAllActiveActivities(String processInstanceId) {
    // get engine services
    ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine()
    RuntimeService runtimeService = processEngine.getRuntimeService();
    RepositoryService repositoryService = processEngine.getRepositoryService();

    // get the process instance
    ProcessInstance processInstance =
        runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();

    HashMap<String, String> activityNameByActivityId = new HashMap<String, String>();

    // get all active activities of the process instance
    List<String> activeActivityIds =
        runtimeService.getActiveActivityIds(processInstance.getId());

    // get bpmn model of the process instance
    BpmnModelInstance bpmnModelInstance =
        repositoryService.getBpmnModelInstance(processInstance.getProcessDefinitionId());

    for (String activeActivityId : activeActivityIds) {
      // get the speaking name of each activity in the diagram
      ModelElementInstance modelElementById =
          bpmnModelInstance.getModelElementById(activeActivityId);
      String activityName = modelElementById.getAttributeValue("name");

      activityNameByActivityId.put(activeActivityId, activityName);
    }

    // map contains now all active activities
    return activityNameByActivityId;
  }

}

这篇关于如何查询流程实例的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆