动态将服务任务/结束事件/终止事件映射到现有的专有网关传出序列流(Camunda)

时间:2018-11-02 12:30:44

标签: java xml bpmn camunda camunda-modeler

我正在尝试将End或Terminate事件添加到BPMN图中的现有网关,因为另一个输出序列在运行时在Java中实用地流了下来。要实现此目标需要遵循哪些步骤? 我将这些示例作为参考。

https://www.programcreek.com/java-api-examples/?class=org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener&method=setCamundaEvent

BpmnModelInstance bpmn = execution.getBpmnModelInstance();
Collection<ExclusiveGateway> gateways = execution.getBpmnModelInstance().getModelElementsByType(ExclusiveGateway.class);

ExclusiveGateway gateway; // getting the instance of gateway from collection
SequenceFlow sequenceFlow = bpmn.newInstance(SequenceFlow.class);
sequenceFlow.setName("Sequence_flow_2");

ConditionExpression conditionExpression = bpmn.newInstance(ConditionExpression.class);
conditionExpression.setTextContent("${x == 2}");
sequenceFlow.setConditionExpression(conditionExpression);

CamundaExecutionListener executionListener = bpmn.newInstance(CamundaExecutionListener.class);
executionListener.setCamundaEvent("start");
executionListener.setCamundaDelegateExpression("Terminate");

EndEvent endEvent = bpmn.newInstance(EndEvent.class);
endEvent.setName("End error");
if (endEvent.getExtensionElements() == null) {
    ExtensionElements extensionElements =    bpmn.newInstance(ExtensionElements.class);
    endEvent.addChildElement(extensionElements);
}
endEvent.getExtensionElements().addChildElement(executionListener);

if (sequenceFlow.getExtensionElements() == null) {
    ExtensionElements extensionElements =     bpmn.newInstance(ExtensionElements.class);
    sequenceFlow.addChildElement(extensionElements);
}
sequenceFlow.getExtensionElements().addChildElement(endEvent);

if((gateway.getExtensionElements() == null) {
    ExtensionElements extensionElements =    bpmn.newInstance(ExtensionElements.class);
    gateway.addChildElement(extensionElements);
}
gateway.getExtensionElements().addChildElement(sequenceFlow);

//sequenceFlow.setSource(gateway);
//sequenceFlow.setTarget(endEvent);

bpmn.setDocumentElement(sequenceFlow);
gateway.getOutgoing().add(sequenceFlow);

我为下面的bpmn图附加了一张图片。

bpmn diagram

0 个答案:

没有答案