// sequence flows are now all on root level
Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
for (Process process : bpmnModel.getProcesses()) {
for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
SubProcess subProcess = (SubProcess) flowElement;
fillSubShapes(subShapesMap, subProcess);
}
if (!subShapesMap.isEmpty()) {
List<String> removeSubFlowsList = new ArrayList<String>();
List<SequenceFlow> sequenceFlowList = process.findFlowElementsOfType(SequenceFlow.class);
for (FlowElement flowElement : sequenceFlowList) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
if (process.getFlowElement(flowElement.getId()) != null && subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
subProcess.addFlowElement(sequenceFlow);
removeSubFlowsList.add(sequenceFlow.getId());
}
}
for (String flowId : removeSubFlowsList) {
process.removeFlowElement(flowId);