@Test @SuppressWarnings("unchecked") public void testCompositeTheRightCommands() { tested.initialize(graphCommandExecutionContext); final List<Command<GraphCommandExecutionContext, RuleViolation>> commands = tested.getCommands(); assertEquals(3, commands.size()); DeleteConnectorCommand deleteConnectorCommand = (DeleteConnectorCommand) commands.get(0); assertEquals(edge, deleteConnectorCommand.getEdge()); SafeDeleteNodeCommand deleteSourceNodeCommand = (SafeDeleteNodeCommand) commands.get(1); assertEquals(source, deleteSourceNodeCommand.getNode()); SafeDeleteNodeCommand deleteTargetNodeCommand = (SafeDeleteNodeCommand) commands.get(2); assertEquals(target, deleteTargetNodeCommand.getNode()); assertTrue(deleteSourceNodeCommand.getOptions().getExclusions().contains(EDGE_UUID)); assertTrue(deleteTargetNodeCommand.getOptions().getExclusions().contains(EDGE_UUID)); }
@Override @SuppressWarnings("unchecked") protected DeleteElementsCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); if (null == elements) { elements = uuids.stream() .map(uuid -> context.getGraphIndex().get(uuid)) .collect(Collectors.toList()); } if (elements.isEmpty()) { throw new IllegalArgumentException("No elements to delete."); } if (1 == elements.size()) { final Element<?> element = elements.iterator().next(); if (null != element.asNode()) { final Node<?, Edge> node = element.asNode(); final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.defaults(); commands.add(createSafeDeleteNodeCommand(node, options, callback)); } else { final Edge<? extends View, Node> edge = (Edge<? extends View, Node>) element.asEdge(); commands.add(new DeleteConnectorCommand(edge)); callback.onDeleteEdge(edge); } } else { final List<Element> edges = elements.stream() .filter(e -> null != e.asEdge()) .collect(Collectors.toList()); final Set<String> edgeIds = edges.stream() .map(Element::getUUID) .collect(Collectors.toSet()); edges.forEach(edge -> { commands.add(new DeleteConnectorCommand((Edge<? extends View, Node>) edge)); callback.onDeleteEdge((Edge<? extends View, Node>) edge); }); elements.stream() .filter(e -> null != e.asNode()) .collect(Collectors.toList()) .forEach(e -> { final Node<?, Edge> node = (Node<?, Edge>) e; final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.exclude(edgeIds); commands.add(createSafeDeleteNodeCommand(node, options, callback)); }); } return this; }
DeleteElementsCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected DeleteElementsCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); if (null == elements) { elements = uuids.stream() .map(uuid -> context.getGraphIndex().get(uuid)) .collect(Collectors.toList()); } if (elements.isEmpty()) { throw new IllegalArgumentException("No elements to delete."); } if (1 == elements.size()) { final Element<?> element = elements.iterator().next(); if (null != element.asNode()) { final Node<?, Edge> node = element.asNode(); final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.defaults(); commands.add(createSafeDeleteNodeCommand(node, options, callback)); } else { final Edge<? extends View, Node> edge = (Edge<? extends View, Node>) element.asEdge(); commands.add(new DeleteConnectorCommand(edge)); callback.onDeleteEdge(edge); } } else { final List<Element> edges = elements.stream() .filter(e -> null != e.asEdge()) .collect(Collectors.toList()); final Set<String> edgeIds = edges.stream() .map(Element::getUUID) .collect(Collectors.toSet()); edges.forEach(edge -> { commands.add(new DeleteConnectorCommand((Edge<? extends View, Node>) edge)); callback.onDeleteEdge((Edge<? extends View, Node>) edge); }); elements.stream() .filter(e -> null != e.asNode()) .collect(Collectors.toList()) .forEach(e -> { final Node<?, Edge> node = (Node<?, Edge>) e; final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.exclude(edgeIds); commands.add(createSafeDeleteNodeCommand(node, options, callback)); }); } return this; } }
DeleteElementsCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected DeleteElementsCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); if (null == elements) { elements = uuids.stream() .map(uuid -> context.getGraphIndex().get(uuid)) .collect(Collectors.toList()); } if (elements.isEmpty()) { throw new IllegalArgumentException("No elements to delete."); } if (1 == elements.size()) { final Element<?> element = elements.iterator().next(); if (null != element.asNode()) { final Node<?, Edge> node = element.asNode(); final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.defaults(); commands.add(createSafeDeleteNodeCommand(node, options, callback)); } else { final Edge<? extends View, Node> edge = (Edge<? extends View, Node>) element.asEdge(); commands.add(new DeleteConnectorCommand(edge)); callback.onDeleteEdge(edge); } } else { final List<Element> edges = elements.stream() .filter(e -> null != e.asEdge()) .collect(Collectors.toList()); final Set<String> edgeIds = edges.stream() .map(Element::getUUID) .collect(Collectors.toSet()); edges.forEach(edge -> { commands.add(new DeleteConnectorCommand((Edge<? extends View, Node>) edge)); callback.onDeleteEdge((Edge<? extends View, Node>) edge); }); elements.stream() .filter(e -> null != e.asNode()) .collect(Collectors.toList()) .forEach(e -> { final Node<?, Edge> node = (Node<?, Edge>) e; final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.exclude(edgeIds); commands.add(createSafeDeleteNodeCommand(node, options, callback)); }); } return this; } DeleteElementsCommand(final @MapsTo("uuids") Collection<String> uuids);  DeleteElementsCommand(final Supplier<Collection<Element>> elements);  DeleteElementsCommand(final Supplier<Collection<Element>> elements,
                                 final DeleteCallback callback); }
DeleteElementsCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected DeleteElementsCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); if (null == elements) { elements = uuids.stream() .map(uuid -> context.getGraphIndex().get(uuid)) .collect(Collectors.toList()); } if (elements.isEmpty()) { throw new IllegalArgumentException("No elements to delete."); } if (1 == elements.size()) { final Element<?> element = elements.iterator().next(); if (null != element.asNode()) { final Node<?, Edge> node = element.asNode(); final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.defaults(); commands.add(createSafeDeleteNodeCommand(node, options, callback)); } else { final Edge<? extends View, Node> edge = (Edge<? extends View, Node>) element.asEdge(); commands.add(new DeleteConnectorCommand(edge)); callback.onDeleteEdge(edge); } } else { final List<Element> edges = elements.stream() .filter(e -> null != e.asEdge()) .collect(Collectors.toList()); final Set<String> edgeIds = edges.stream() .map(Element::getUUID) .collect(Collectors.toSet()); edges.forEach(edge -> { commands.add(new DeleteConnectorCommand((Edge<? extends View, Node>) edge)); callback.onDeleteEdge((Edge<? extends View, Node>) edge); }); elements.stream() .filter(e -> null != e.asNode()) .collect(Collectors.toList()) .forEach(e -> { final Node<?, Edge> node = (Node<?, Edge>) e; final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.exclude(edgeIds); commands.add(createSafeDeleteNodeCommand(node, options, callback)); }); } return this; } DeleteElementsCommand(final @MapsTo("uuids") Collection<String> uuids);  DeleteElementsCommand(final Supplier<Collection<Element>> elements);  DeleteElementsCommand(final Supplier<Collection<Element>> elements,
                                 final DeleteCallback callback); Collection<String> getUUIDs(); @Override String toString(); }
DeleteElementsCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected DeleteElementsCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); if (null == elements) { elements = uuids.stream() .map(uuid -> context.getGraphIndex().get(uuid)) .collect(Collectors.toList()); } if (elements.isEmpty()) { throw new IllegalArgumentException("No elements to delete."); } if (1 == elements.size()) { final Element<?> element = elements.iterator().next(); if (null != element.asNode()) { final Node<?, Edge> node = element.asNode(); final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.defaults(); commands.add(createSafeDeleteNodeCommand(node, options, callback)); } else { final Edge<? extends View, Node> edge = (Edge<? extends View, Node>) element.asEdge(); commands.add(new DeleteConnectorCommand(edge)); callback.onDeleteEdge(edge); } } else { final List<Element> edges = elements.stream() .filter(e -> null != e.asEdge()) .collect(Collectors.toList()); final Set<String> edgeIds = edges.stream() .map(Element::getUUID) .collect(Collectors.toSet()); edges.forEach(edge -> { commands.add(new DeleteConnectorCommand((Edge<? extends View, Node>) edge)); callback.onDeleteEdge((Edge<? extends View, Node>) edge); }); elements.stream() .filter(e -> null != e.asNode()) .collect(Collectors.toList()) .forEach(e -> { final Node<?, Edge> node = (Node<?, Edge>) e; final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.exclude(edgeIds); commands.add(createSafeDeleteNodeCommand(node, options, callback)); }); } return this; } DeleteElementsCommand(final @MapsTo("uuids") Collection<String> uuids);  DeleteElementsCommand(final Supplier<Collection<Element>> elements);  DeleteElementsCommand(final Supplier<Collection<Element>> elements,
                                 final DeleteCallback callback); Collection<String> getUUIDs(); @Override String toString();  }