@Test public void testAddNewRelationship_noIndex() { final Node diagram = createNode(CaseManagementDiagram.class); final Node start = createNode(StartNoneEvent.class); final Node end = createNode(EndNoneEvent.class); final Node stage = createNode(AdHocSubprocess.class); final Node candidate = createNode(AdHocSubprocess.class); createChildEdge(diagram, start); createChildEdge(diagram, stage); createChildEdge(diagram, end); createSequenceFlow(start, stage); final Edge edge = createSequenceFlow(stage, end); final CaseManagementSetChildNodeGraphCommand command = new CaseManagementSetChildNodeGraphCommand(diagram, candidate, OptionalInt.empty(), Optional.of(diagram), originalIndex); command.addNewRelationship(context); assertTrue(command.in.isPresent()); assertEquals(stage, command.in.get()); assertTrue(command.out.isPresent()); assertEquals(end, command.out.get()); assertTrue(command.edge.isPresent()); assertEquals(edge, command.edge.get()); assertEquals(candidate, ((Edge) diagram.getOutEdges().get(2)).getTargetNode()); assertEquals(candidate, ((Edge) stage.getOutEdges().get(0)).getTargetNode()); assertEquals(1, end.getInEdges().stream().filter(sequencePredicate()).count()); assertEquals(candidate, ((List) end.getInEdges().stream().filter(sequencePredicate()) .map(e -> ((Edge) e).getSourceNode()).collect(Collectors.toList())).get(0)); }
@SuppressWarnings("unchecked") void addNewRelationship(final GraphCommandExecutionContext context) { OptionalInt insertIndex = index; if (isStage(parent, child)) { List<Node> childNodes = parent.getOutEdges().stream() .map(Edge::getTargetNode).collect(Collectors.toList()); if (index.isPresent()) { for (int i = index.getAsInt() - 1; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); break; } } for (int i = index.getAsInt(), n = childNodes.size(); i < n; i++) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } else { int n = childNodes.size(); int i = n - 1; for (; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); insertIndex = OptionalInt.of(i + 1); break; } } if (i == 0) { insertIndex = OptionalInt.of(0); } if (i >= 0) { for (; i < n; i++) { Node node = childNodes.get(i); if (((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } } } if (in.isPresent() && out.isPresent()) { edge = getEdgeForTarget(in, out.get(), sequencePredicate()); } edge.ifPresent(e -> removeRelationship(e, in.get(), out.get(), context)); addRelationship(parent, child, insertIndex, context, Child::new); in.ifPresent(n -> addRelationship(n, child, OptionalInt.empty(), context, sequenceFlowSupplier())); out.ifPresent(n -> addRelationship(child, n, OptionalInt.empty(), context, sequenceFlowSupplier())); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void addNewRelationship(final GraphCommandExecutionContext context) { OptionalInt insertIndex = index; if (isStage(parent, child)) { List<Node> childNodes = parent.getOutEdges().stream() .map(Edge::getTargetNode).collect(Collectors.toList()); if (index.isPresent()) { for (int i = index.getAsInt() - 1; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); break; } } for (int i = index.getAsInt(), n = childNodes.size(); i < n; i++) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } else { int n = childNodes.size(); int i = n - 1; for (; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); insertIndex = OptionalInt.of(i + 1); break; } } if (i == 0) { insertIndex = OptionalInt.of(0); } if (i >= 0) { for (; i < n; i++) { Node node = childNodes.get(i); if (((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } } } if (in.isPresent() && out.isPresent()) { edge = getEdgeForTarget(in, out.get(), sequencePredicate()); } edge.ifPresent(e -> removeRelationship(e, in.get(), out.get(), context)); addRelationship(parent, child, insertIndex, context, Child::new); in.ifPresent(n -> addRelationship(n, child, OptionalInt.empty(), context, sequenceFlowSupplier())); out.ifPresent(n -> addRelationship(child, n, OptionalInt.empty(), context, sequenceFlowSupplier())); } }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void addNewRelationship(final GraphCommandExecutionContext context) { OptionalInt insertIndex = index; if (isStage(parent, child)) { List<Node> childNodes = parent.getOutEdges().stream() .map(Edge::getTargetNode).collect(Collectors.toList()); if (index.isPresent()) { for (int i = index.getAsInt() - 1; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); break; } } for (int i = index.getAsInt(), n = childNodes.size(); i < n; i++) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } else { int n = childNodes.size(); int i = n - 1; for (; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); insertIndex = OptionalInt.of(i + 1); break; } } if (i == 0) { insertIndex = OptionalInt.of(0); } if (i >= 0) { for (; i < n; i++) { Node node = childNodes.get(i); if (((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } } } if (in.isPresent() && out.isPresent()) { edge = getEdgeForTarget(in, out.get(), sequencePredicate()); } edge.ifPresent(e -> removeRelationship(e, in.get(), out.get(), context)); addRelationship(parent, child, insertIndex, context, Child::new); in.ifPresent(n -> addRelationship(n, child, OptionalInt.empty(), context, sequenceFlowSupplier())); out.ifPresent(n -> addRelationship(child, n, OptionalInt.empty(), context, sequenceFlowSupplier())); } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void addNewRelationship(final GraphCommandExecutionContext context) { OptionalInt insertIndex = index; if (isStage(parent, child)) { List<Node> childNodes = parent.getOutEdges().stream() .map(Edge::getTargetNode).collect(Collectors.toList()); if (index.isPresent()) { for (int i = index.getAsInt() - 1; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); break; } } for (int i = index.getAsInt(), n = childNodes.size(); i < n; i++) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } else { int n = childNodes.size(); int i = n - 1; for (; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); insertIndex = OptionalInt.of(i + 1); break; } } if (i == 0) { insertIndex = OptionalInt.of(0); } if (i >= 0) { for (; i < n; i++) { Node node = childNodes.get(i); if (((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } } } if (in.isPresent() && out.isPresent()) { edge = getEdgeForTarget(in, out.get(), sequencePredicate()); } edge.ifPresent(e -> removeRelationship(e, in.get(), out.get(), context)); addRelationship(parent, child, insertIndex, context, Child::new); in.ifPresent(n -> addRelationship(n, child, OptionalInt.empty(), context, sequenceFlowSupplier())); out.ifPresent(n -> addRelationship(child, n, OptionalInt.empty(), context, sequenceFlowSupplier())); } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); OptionalInt getIndex(); OptionalInt getOriginalIndex(); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void addNewRelationship(final GraphCommandExecutionContext context) { OptionalInt insertIndex = index; if (isStage(parent, child)) { List<Node> childNodes = parent.getOutEdges().stream() .map(Edge::getTargetNode).collect(Collectors.toList()); if (index.isPresent()) { for (int i = index.getAsInt() - 1; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); break; } } for (int i = index.getAsInt(), n = childNodes.size(); i < n; i++) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } else { int n = childNodes.size(); int i = n - 1; for (; i >= 0; i--) { Node node = childNodes.get(i); if (isStageNode(node) || ((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof StartNoneEvent) { in = Optional.of(node); insertIndex = OptionalInt.of(i + 1); break; } } if (i == 0) { insertIndex = OptionalInt.of(0); } if (i >= 0) { for (; i < n; i++) { Node node = childNodes.get(i); if (((Node<View<?>, Edge>) node).getContent().getDefinition() instanceof EndNoneEvent) { out = Optional.of(node); break; } } } } } if (in.isPresent() && out.isPresent()) { edge = getEdgeForTarget(in, out.get(), sequencePredicate()); } edge.ifPresent(e -> removeRelationship(e, in.get(), out.get(), context)); addRelationship(parent, child, insertIndex, context, Child::new); in.ifPresent(n -> addRelationship(n, child, OptionalInt.empty(), context, sequenceFlowSupplier())); out.ifPresent(n -> addRelationship(child, n, OptionalInt.empty(), context, sequenceFlowSupplier())); } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); OptionalInt getIndex(); OptionalInt getOriginalIndex();  }