@Test public void testExecute() { CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext); assertEquals(CommandResult.Type.INFO, result.getType()); verify(graph, times(1)).clear(); verify(graphIndex, times(1)).clear(); }
@Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph<?, Node> graph = getGraph(context); if (hasRootUUID()) { Iterator<Node> nodes = graph.nodes().iterator(); if (null != nodes) { nodes.forEachRemaining(node -> { if (!node.getUUID().equals(rootUUID)) { getMutableIndex(context).removeNode(node); nodes.remove(); } else { node.getOutEdges().stream().forEach(edge -> getMutableIndex(context).removeEdge((Edge) edge)); node.getOutEdges().clear(); } }); } } else { graph.clear(); getMutableIndex(context).clear(); } } return results; }
ClearGraphCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph<?, Node> graph = getGraph(context); if (hasRootUUID()) { Iterator<Node> nodes = graph.nodes().iterator(); if (null != nodes) { nodes.forEachRemaining(node -> { if (!node.getUUID().equals(rootUUID)) { getMutableIndex(context).removeNode(node); nodes.remove(); } else { node.getOutEdges().stream().forEach(edge -> getMutableIndex(context).removeEdge((Edge) edge)); node.getOutEdges().clear(); } }); } } else { graph.clear(); getMutableIndex(context).clear(); } } return results; } }
ClearGraphCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph<?, Node> graph = getGraph(context); if (hasRootUUID()) { Iterator<Node> nodes = graph.nodes().iterator(); if (null != nodes) { nodes.forEachRemaining(node -> { if (!node.getUUID().equals(rootUUID)) { getMutableIndex(context).removeNode(node); nodes.remove(); } else { node.getOutEdges().stream().forEach(edge -> getMutableIndex(context).removeEdge((Edge) edge)); node.getOutEdges().clear(); } }); } } else { graph.clear(); getMutableIndex(context).clear(); } } return results; } ClearGraphCommand(final @MapsTo("rootUUID") String rootUUID); }
ClearGraphCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph<?, Node> graph = getGraph(context); if (hasRootUUID()) { Iterator<Node> nodes = graph.nodes().iterator(); if (null != nodes) { nodes.forEachRemaining(node -> { if (!node.getUUID().equals(rootUUID)) { getMutableIndex(context).removeNode(node); nodes.remove(); } else { node.getOutEdges().stream().forEach(edge -> getMutableIndex(context).removeEdge((Edge) edge)); node.getOutEdges().clear(); } }); } } else { graph.clear(); getMutableIndex(context).clear(); } } return results; } ClearGraphCommand(final @MapsTo("rootUUID") String rootUUID); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); String getRootUUID(); @Override String toString(); }
ClearGraphCommand extends AbstractGraphCommand { @Override @SuppressWarnings("unchecked") public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) { final CommandResult<RuleViolation> results = allow(context); if (!results.getType().equals(CommandResult.Type.ERROR)) { final Graph<?, Node> graph = getGraph(context); if (hasRootUUID()) { Iterator<Node> nodes = graph.nodes().iterator(); if (null != nodes) { nodes.forEachRemaining(node -> { if (!node.getUUID().equals(rootUUID)) { getMutableIndex(context).removeNode(node); nodes.remove(); } else { node.getOutEdges().stream().forEach(edge -> getMutableIndex(context).removeEdge((Edge) edge)); node.getOutEdges().clear(); } }); } } else { graph.clear(); getMutableIndex(context).clear(); } } return results; } ClearGraphCommand(final @MapsTo("rootUUID") String rootUUID); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); String getRootUUID(); @Override String toString();  }