@GetMapping("/bpmn/getExtensionElementsText")
public ResponseData getExtensionElementsText(BpmnModelParam bpmnModelParam){
InputStream processModel = ProcessEngines
.getDefaultProcessEngine()
.getRepositoryService()
.getProcessModel("Process_0uz4e7e:11:30b89d94-236f-11ec-82fb-861b7790c7c0");
BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(processModel);
// 通过id获取元素
// StartEvent startEvent = (StartEvent) bpmnModelInstance.getModelElementById("StartEvent_1");
// 通过任务类型查找
// ModelElementType type = bpmnModelInstance.getModel().getType(StartEvent.class);
// Collection<ModelElementInstance> taskInstances = bpmnModelInstance.getModelElementsByType(type);
/**
* 通过类型查找开始节点
*/
System.out.println("=================获取全局扩展配置信息========================");
Collection<Process> processCollection = bpmnModelInstance.getModelElementsByType(Process.class);
for (Process process: processCollection) {
ExtensionElements extensionElements = process.getExtensionElements();
Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
.filterByType(CamundaProperties.class)
.singleResult()
.getCamundaProperties();
for (CamundaProperty property : properties) {
String name = property.getCamundaName();
System.out.println("process:"+name);
String value = property.getCamundaValue();
System.out.println("process:"+value);
}
}
System.out.println("=================获取开始节点配置信息========================");
Collection<StartEvent> startEventCollection = bpmnModelInstance.getModelElementsByType(StartEvent.class);
for (StartEvent startEvent: startEventCollection) {
ExtensionElements extensionElements = startEvent.getExtensionElements();
Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
.filterByType(CamundaProperties.class)
.singleResult()
.getCamundaProperties();
for (CamundaProperty property : properties) {
String name = property.getCamundaName();
System.out.println(name);
String value = property.getCamundaValue();
System.out.println(value);
}
}
System.out.println("================获取所有扩展信息=========================");
Collection<ExtensionElements> extensionElementsCollection = bpmnModelInstance.getModelElementsByType(ExtensionElements.class);
for (ExtensionElements extensionElements: extensionElementsCollection) {
Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
.filterByType(CamundaProperties.class)
.singleResult()
.getCamundaProperties();
for (CamundaProperty property : properties) {
String name = property.getCamundaName();
System.out.println(name);
String value = property.getCamundaValue();
System.out.println(value);
}
}
System.out.println("================任务节点=========================");
Task task = ProcessEngines
.getDefaultProcessEngine()
.getTaskService()
.createTaskQuery()
.taskId("926e98fb-239a-11ec-876c-861b7790c7c0").singleResult();
String taskDefinitionKey = task.getTaskDefinitionKey();
System.out.println(taskDefinitionKey);
UserTask userTask = (UserTask) bpmnModelInstance.getModelElementById(taskDefinitionKey);
ExtensionElements extensionElements = userTask.getExtensionElements();
Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
.filterByType(CamundaProperties.class)
.singleResult()
.getCamundaProperties();
for (CamundaProperty property : properties) {
String name = property.getCamundaName();
System.out.println(name);
String value = property.getCamundaValue();
System.out.println(value);
}
// StartEvent startEvent = bpmnModelInstance.newInstance(StartEvent.class);
// ExtensionElements extensionElements = startEvent.getExtensionElements();
//
// Collection<CamundaProperty> properties = extensionElements.getElementsQuery()
// .filterByType(CamundaProperties.class)
// .singleResult()
// .getCamundaProperties();
//
// for (CamundaProperty property : properties) {
// String name = property.getCamundaName();
// System.out.println(name);
// String value = property.getCamundaValue();
// System.out.println(value);
// }
return new SuccessResponseData();
}
Java获取camunda的bpmn文件中的扩展信息
最新推荐文章于 2024-08-20 16:21:53 发布