Dear Community,
currently, I am trying to remove an activity from a model using the model api.
I am trying to remove the activity and connect the incoming sequence flows with the subsequent flow node and remove the outgoing sequence flows as they are no longer necessary.
Collection<Definitions> definitions = modelInstance.getModelElementsByType(Definitions.class);
definitions.forEach(definition -> {
FlowNode activityA = (FlowNode) modelInstance.getModelElementById("Activity_A");
Collection<SequenceFlow> outgoing = activityA.getOutgoing();
Collection<SequenceFlow> incoming = activityA.getIncoming();
for (SequenceFlow incomingFlow : incoming) {
for (SequenceFlow outgoingFlow : outgoing) {
FlowNode target = outgoingFlow.getTarget();
incomingFlow.setTarget(target);
target.getIncoming().add(incomingFlow);
target.getIncoming().remove(outgoingFlow);
activityA.getOutgoing().remove(outgoingFlow);
System.out.println("remove sequence flow " + outgoingFlow.getId());
System.out.println(definition.removeChildElement(outgoingFlow));
}
}
definition.removeChildElement(activityA);
});
However, the outgoing sequence flow cannot be removed. And as a result I get an error:
Caused by: org.xml.sax.SAXParseException; cvc-complex-type.4: Attribute ‘sourceRef’ must appear on element ‘bpmn:sequenceFlow’.
I think I get the error because the sequence flow is still there and wants to reference the activity that shall be removed.
So, the question is, why can’t I remove the sequence flow and is my assumption right that I geht the error because of that?
Any hints are appreciated.