@Test public void testSortNodes_Stage() { final Diagram<Graph<DefinitionSet, Node>, Metadata> diagram = mock(Diagram.class); final Graph<DefinitionSet, Node> graph = mock(Graph.class); when(diagram.getGraph()).thenReturn(graph); final List<Node> nodes = new LinkedList<>(); when(graph.nodes()).thenReturn(nodes); final Node root = createNode(CaseManagementDiagram.class); final Node start = createNode(StartNoneEvent.class); final Node end = createNode(EndNoneEvent.class); final Node stage1 = createNode(AdHocSubprocess.class); final Node stage2 = createNode(AdHocSubprocess.class); nodes.add(root); nodes.add(start); nodes.add(end); nodes.add(stage1); nodes.add(stage2); createChildEdge(root, end); createChildEdge(root, start); createChildEdge(root, stage2); createChildEdge(root, stage1); createSequenceFlow(start, stage1); createSequenceFlow(stage1, stage2); createSequenceFlow(stage2, end); tested.sortNodes(diagram); final List<Edge> rEdges = root.getOutEdges(); assertEquals(4, rEdges.size()); assertEquals(start, rEdges.get(0).getTargetNode()); assertEquals(stage1, rEdges.get(1).getTargetNode()); assertEquals(stage2, rEdges.get(2).getTargetNode()); assertEquals(end, rEdges.get(3).getTargetNode()); }
@SuppressWarnings("unchecked") void sortNodes(final Diagram<Graph<DefinitionSet, Node>, Metadata> diagram) { List<Node<View<?>, Edge>> nodes = StreamSupport.stream(diagram.getGraph().nodes().spliterator(), false) .map(n -> (Node<View<?>, Edge>) n).collect(Collectors.toList()); nodes.stream() .filter(node -> node.getContent().getDefinition() instanceof CaseManagementDiagram) .findAny().ifPresent(root -> { Map<Node<View<?>, Edge>, Edge> childNodes = root.getOutEdges().stream() .filter(childPredicate()).collect(Collectors.toMap(e -> (Node<View<?>, Edge>) e.getTargetNode(), identity())); Node<View<?>, Edge> startNode = root.getOutEdges().stream().map(Edge::getTargetNode) .filter(n -> ((Node<View<?>, Edge>) n).getContent().getDefinition() instanceof StartNoneEvent).findAny() .orElseGet(() -> childNodes.keySet().stream().filter(n -> n.getInEdges().size() == 1).findAny().orElse(null)); if (startNode != null) { Node<View<?>, Edge> node = startNode; List<Edge> childEdges = new LinkedList<>(); do { childEdges.add(0, childNodes.get(node)); node = node.getOutEdges().stream().filter(sequencePredicate()) .map(Edge::getTargetNode).filter(childNodes::containsKey).findAny().orElse(null); } while (node != null); childEdges.forEach(e -> root.getOutEdges().remove(e)); childEdges.forEach(e -> root.getOutEdges().add(0, e)); } Stream<Node<View<?>, Edge>> stageStream = root.getOutEdges().stream().filter(childPredicate()).map(Edge::getTargetNode); stageStream.filter(CaseManagementCommandUtil::isStageNode) .forEach(n -> { List<Edge> edges = n.getOutEdges().stream().filter(childPredicate()).collect(Collectors.toList()); Collections.sort(edges, (e1, e2) -> { final double y1 = ((Node<View, Edge>) e1.getTargetNode()).getContent().getBounds().getY(); final double y2 = ((Node<View, Edge>) e2.getTargetNode()).getContent().getBounds().getY(); return Double.compare(y2, y1); }); edges.forEach(e -> n.getOutEdges().remove(e)); edges.forEach(e -> n.getOutEdges().add(0, e)); }); }); }
CaseManagementDrawCommand extends AbstractCanvasCommand { @SuppressWarnings("unchecked") void sortNodes(final Diagram<Graph<DefinitionSet, Node>, Metadata> diagram) { List<Node<View<?>, Edge>> nodes = StreamSupport.stream(diagram.getGraph().nodes().spliterator(), false) .map(n -> (Node<View<?>, Edge>) n).collect(Collectors.toList()); nodes.stream() .filter(node -> node.getContent().getDefinition() instanceof CaseManagementDiagram) .findAny().ifPresent(root -> { Map<Node<View<?>, Edge>, Edge> childNodes = root.getOutEdges().stream() .filter(childPredicate()).collect(Collectors.toMap(e -> (Node<View<?>, Edge>) e.getTargetNode(), identity())); Node<View<?>, Edge> startNode = root.getOutEdges().stream().map(Edge::getTargetNode) .filter(n -> ((Node<View<?>, Edge>) n).getContent().getDefinition() instanceof StartNoneEvent).findAny() .orElseGet(() -> childNodes.keySet().stream().filter(n -> n.getInEdges().size() == 1).findAny().orElse(null)); if (startNode != null) { Node<View<?>, Edge> node = startNode; List<Edge> childEdges = new LinkedList<>(); do { childEdges.add(0, childNodes.get(node)); node = node.getOutEdges().stream().filter(sequencePredicate()) .map(Edge::getTargetNode).filter(childNodes::containsKey).findAny().orElse(null); } while (node != null); childEdges.forEach(e -> root.getOutEdges().remove(e)); childEdges.forEach(e -> root.getOutEdges().add(0, e)); } Stream<Node<View<?>, Edge>> stageStream = root.getOutEdges().stream().filter(childPredicate()).map(Edge::getTargetNode); stageStream.filter(CaseManagementCommandUtil::isStageNode) .forEach(n -> { List<Edge> edges = n.getOutEdges().stream().filter(childPredicate()).collect(Collectors.toList()); Collections.sort(edges, (e1, e2) -> { final double y1 = ((Node<View, Edge>) e1.getTargetNode()).getContent().getBounds().getY(); final double y2 = ((Node<View, Edge>) e2.getTargetNode()).getContent().getBounds().getY(); return Double.compare(y2, y1); }); edges.forEach(e -> n.getOutEdges().remove(e)); edges.forEach(e -> n.getOutEdges().add(0, e)); }); }); } }
CaseManagementDrawCommand extends AbstractCanvasCommand { @SuppressWarnings("unchecked") void sortNodes(final Diagram<Graph<DefinitionSet, Node>, Metadata> diagram) { List<Node<View<?>, Edge>> nodes = StreamSupport.stream(diagram.getGraph().nodes().spliterator(), false) .map(n -> (Node<View<?>, Edge>) n).collect(Collectors.toList()); nodes.stream() .filter(node -> node.getContent().getDefinition() instanceof CaseManagementDiagram) .findAny().ifPresent(root -> { Map<Node<View<?>, Edge>, Edge> childNodes = root.getOutEdges().stream() .filter(childPredicate()).collect(Collectors.toMap(e -> (Node<View<?>, Edge>) e.getTargetNode(), identity())); Node<View<?>, Edge> startNode = root.getOutEdges().stream().map(Edge::getTargetNode) .filter(n -> ((Node<View<?>, Edge>) n).getContent().getDefinition() instanceof StartNoneEvent).findAny() .orElseGet(() -> childNodes.keySet().stream().filter(n -> n.getInEdges().size() == 1).findAny().orElse(null)); if (startNode != null) { Node<View<?>, Edge> node = startNode; List<Edge> childEdges = new LinkedList<>(); do { childEdges.add(0, childNodes.get(node)); node = node.getOutEdges().stream().filter(sequencePredicate()) .map(Edge::getTargetNode).filter(childNodes::containsKey).findAny().orElse(null); } while (node != null); childEdges.forEach(e -> root.getOutEdges().remove(e)); childEdges.forEach(e -> root.getOutEdges().add(0, e)); } Stream<Node<View<?>, Edge>> stageStream = root.getOutEdges().stream().filter(childPredicate()).map(Edge::getTargetNode); stageStream.filter(CaseManagementCommandUtil::isStageNode) .forEach(n -> { List<Edge> edges = n.getOutEdges().stream().filter(childPredicate()).collect(Collectors.toList()); Collections.sort(edges, (e1, e2) -> { final double y1 = ((Node<View, Edge>) e1.getTargetNode()).getContent().getBounds().getY(); final double y2 = ((Node<View, Edge>) e2.getTargetNode()).getContent().getBounds().getY(); return Double.compare(y2, y1); }); edges.forEach(e -> n.getOutEdges().remove(e)); edges.forEach(e -> n.getOutEdges().add(0, e)); }); }); } CaseManagementDrawCommand(final ChildrenTraverseProcessor childrenTraverseProcessor); }
CaseManagementDrawCommand extends AbstractCanvasCommand { @SuppressWarnings("unchecked") void sortNodes(final Diagram<Graph<DefinitionSet, Node>, Metadata> diagram) { List<Node<View<?>, Edge>> nodes = StreamSupport.stream(diagram.getGraph().nodes().spliterator(), false) .map(n -> (Node<View<?>, Edge>) n).collect(Collectors.toList()); nodes.stream() .filter(node -> node.getContent().getDefinition() instanceof CaseManagementDiagram) .findAny().ifPresent(root -> { Map<Node<View<?>, Edge>, Edge> childNodes = root.getOutEdges().stream() .filter(childPredicate()).collect(Collectors.toMap(e -> (Node<View<?>, Edge>) e.getTargetNode(), identity())); Node<View<?>, Edge> startNode = root.getOutEdges().stream().map(Edge::getTargetNode) .filter(n -> ((Node<View<?>, Edge>) n).getContent().getDefinition() instanceof StartNoneEvent).findAny() .orElseGet(() -> childNodes.keySet().stream().filter(n -> n.getInEdges().size() == 1).findAny().orElse(null)); if (startNode != null) { Node<View<?>, Edge> node = startNode; List<Edge> childEdges = new LinkedList<>(); do { childEdges.add(0, childNodes.get(node)); node = node.getOutEdges().stream().filter(sequencePredicate()) .map(Edge::getTargetNode).filter(childNodes::containsKey).findAny().orElse(null); } while (node != null); childEdges.forEach(e -> root.getOutEdges().remove(e)); childEdges.forEach(e -> root.getOutEdges().add(0, e)); } Stream<Node<View<?>, Edge>> stageStream = root.getOutEdges().stream().filter(childPredicate()).map(Edge::getTargetNode); stageStream.filter(CaseManagementCommandUtil::isStageNode) .forEach(n -> { List<Edge> edges = n.getOutEdges().stream().filter(childPredicate()).collect(Collectors.toList()); Collections.sort(edges, (e1, e2) -> { final double y1 = ((Node<View, Edge>) e1.getTargetNode()).getContent().getBounds().getY(); final double y2 = ((Node<View, Edge>) e2.getTargetNode()).getContent().getBounds().getY(); return Double.compare(y2, y1); }); edges.forEach(e -> n.getOutEdges().remove(e)); edges.forEach(e -> n.getOutEdges().add(0, e)); }); }); } CaseManagementDrawCommand(final ChildrenTraverseProcessor childrenTraverseProcessor); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context); }
CaseManagementDrawCommand extends AbstractCanvasCommand { @SuppressWarnings("unchecked") void sortNodes(final Diagram<Graph<DefinitionSet, Node>, Metadata> diagram) { List<Node<View<?>, Edge>> nodes = StreamSupport.stream(diagram.getGraph().nodes().spliterator(), false) .map(n -> (Node<View<?>, Edge>) n).collect(Collectors.toList()); nodes.stream() .filter(node -> node.getContent().getDefinition() instanceof CaseManagementDiagram) .findAny().ifPresent(root -> { Map<Node<View<?>, Edge>, Edge> childNodes = root.getOutEdges().stream() .filter(childPredicate()).collect(Collectors.toMap(e -> (Node<View<?>, Edge>) e.getTargetNode(), identity())); Node<View<?>, Edge> startNode = root.getOutEdges().stream().map(Edge::getTargetNode) .filter(n -> ((Node<View<?>, Edge>) n).getContent().getDefinition() instanceof StartNoneEvent).findAny() .orElseGet(() -> childNodes.keySet().stream().filter(n -> n.getInEdges().size() == 1).findAny().orElse(null)); if (startNode != null) { Node<View<?>, Edge> node = startNode; List<Edge> childEdges = new LinkedList<>(); do { childEdges.add(0, childNodes.get(node)); node = node.getOutEdges().stream().filter(sequencePredicate()) .map(Edge::getTargetNode).filter(childNodes::containsKey).findAny().orElse(null); } while (node != null); childEdges.forEach(e -> root.getOutEdges().remove(e)); childEdges.forEach(e -> root.getOutEdges().add(0, e)); } Stream<Node<View<?>, Edge>> stageStream = root.getOutEdges().stream().filter(childPredicate()).map(Edge::getTargetNode); stageStream.filter(CaseManagementCommandUtil::isStageNode) .forEach(n -> { List<Edge> edges = n.getOutEdges().stream().filter(childPredicate()).collect(Collectors.toList()); Collections.sort(edges, (e1, e2) -> { final double y1 = ((Node<View, Edge>) e1.getTargetNode()).getContent().getBounds().getY(); final double y2 = ((Node<View, Edge>) e2.getTargetNode()).getContent().getBounds().getY(); return Double.compare(y2, y1); }); edges.forEach(e -> n.getOutEdges().remove(e)); edges.forEach(e -> n.getOutEdges().add(0, e)); }); }); } CaseManagementDrawCommand(final ChildrenTraverseProcessor childrenTraverseProcessor); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context);  }