2
내 프로세스에서 단일 인스턴스의 현재 위치를 가져오고 싶습니다. id에 반환 값으로 액티비티의 이름을 추가 할 수 있습니까?프로세스 인스턴스의 위치를 쿼리하는 방법은 무엇입니까?
내 프로세스에서 단일 인스턴스의 현재 위치를 가져오고 싶습니다. id에 반환 값으로 액티비티의 이름을 추가 할 수 있습니까?프로세스 인스턴스의 위치를 쿼리하는 방법은 무엇입니까?
다음 코드를 사용하여 프로세스 인스턴스의 현재 위치를 알 수 있습니다. 그러면 프로세스가 여러 위치에서 대기 할 때 활동의 이름이 표시됩니다.
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;
}
}