private static BPMNDiagram separateSplitFromJoin(BPMNDiagram diagram) { Iterator<Gateway> iterator = getXORGateways(diagram).iterator(); while (iterator.hasNext()) { Gateway gateway = iterator.next(); if (isSplit(diagram, gateway) && isJoin(diagram, gateway)) { List<BPMNNode> incoming = getIncomingNodes(diagram, gateway); List<BPMNNode> outgoing = getOutgoingNodes(diagram, gateway); Gateway split = diagram.addGateway("", Gateway.GatewayType.DATABASED); Gateway join = diagram.addGateway("", Gateway.GatewayType.DATABASED); for (BPMNNode node : incoming) { diagram.addFlow(node, join, ""); } for (BPMNNode node : outgoing) { diagram.addFlow(split, node, ""); } diagram.addFlow(join, split, ""); diagram.removeGateway(gateway); iterator = getXORGateways(diagram).iterator(); } } return diagram; }
private static BPMNDiagram mergeActivitiesAfterXOR( BPMNDiagram diagram, Gateway gateway, Activity activity1, Activity activity2) { List<Flow> outgoingFlows1 = getOutgoingFlows(diagram, activity1); List<Flow> outgoingFlows2 = getOutgoingFlows(diagram, activity2); List<Flow> outgoingFlows3 = getOutgoingFlows(diagram, gateway); List<Flow> incomingFlows = getIncomingFlows(diagram, gateway); String label = activity1.getLabel(); Activity activity = diagram.addActivity(label, false, false, false, false, false); Set<BPMNNode> outgoingNodes1 = new UnifiedSet<BPMNNode>(); for (Flow flow : outgoingFlows1) { outgoingNodes1.add(flow.getTarget()); } for (Flow flow : outgoingFlows2) { outgoingNodes1.add(flow.getTarget()); } if (outgoingNodes1.size() > 1) { Gateway gateway1 = diagram.addGateway("", Gateway.GatewayType.DATABASED); Set<BPMNNode> outgoingNodes = new UnifiedSet<BPMNNode>(); for (Flow flow : outgoingFlows1) { if (!outgoingNodes.contains(flow.getTarget())) { outgoingNodes.add(flow.getTarget()); diagram.addFlow(gateway1, flow.getTarget(), ""); } } for (Flow flow : outgoingFlows2) { if (!outgoingNodes.contains(flow.getTarget())) { outgoingNodes.add(flow.getTarget()); diagram.addFlow(gateway1, flow.getTarget(), ""); } } diagram.addFlow(activity, gateway1, ""); } else if (outgoingNodes1.size() > 0) { diagram.addFlow(activity, outgoingNodes1.toArray(new BPMNNode[1])[0], ""); } diagram.removeActivity(activity1); diagram.removeActivity(activity2); if (outgoingFlows3.size() == 2) { for (Flow flow : incomingFlows) { diagram.addFlow(flow.getSource(), activity, ""); } diagram.removeGateway(gateway); } else { diagram.addFlow(gateway, activity, ""); } // if(outgoingNodes.size() == 1) { // BPMNNode node = outgoingNodes.toArray(new BPMNNode[1])[0]; // if(node instanceof Gateway) { // Gateway gateway2 = (Gateway) node; // if(gateway2.getGatewayType().equals(Gateway.GatewayType.DATABASED)) { // List<BPMNNode> list = new ArrayList<BPMNNode>(); // for(Flow flow: diagram.getFlows()) { // if(flow.getSource().equals(gateway2)) { // list.add(flow.getTarget()); // } // } // for(BPMNNode node1 : list) { // diagram.addFlow(activity, node1, ""); // } // diagram.removeGateway(gateway1); // diagram.removeGateway(gateway2); // } // } // } // } return diagram; }