@Test public void initialize() throws Exception { cloneConnectorCommand.initialize(graphCommandExecutionContext); AddConnectorCommand addConnectorCommand = getExecutedCommand(command -> command instanceof AddConnectorCommand); assertEquals(addConnectorCommand.getEdge(), cloneEdge); assertEquals(addConnectorCommand.getSourceNode().getUUID(), sourceNodeUUID); assertEquals(addConnectorCommand.getConnection(), sourceConnection); SetConnectionTargetNodeCommand setConnectionTargetNodeCommand = getExecutedCommand(command -> command instanceof SetConnectionTargetNodeCommand); assertEquals(setConnectionTargetNodeCommand.getTargetNode().getUUID(), targetNodeUUID); assertEquals(setConnectionTargetNodeCommand.getEdge(), cloneEdge); assertEquals(setConnectionTargetNodeCommand.getConnection(), targetConnection); verify(graphIndex, times(1)).addEdge(cloneEdge); }
@Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean); clone = context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asEdge(); Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); getMutableIndex(context).addEdge(clone); return this; }
CloneConnectorCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean); clone = context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asEdge(); Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); getMutableIndex(context).addEdge(clone); return this; } }
CloneConnectorCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean); clone = context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asEdge(); Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); getMutableIndex(context).addEdge(clone); return this; } CloneConnectorCommand();  CloneConnectorCommand(final @MapsTo("candidate") Edge candidate, final @MapsTo("sourceNodeUUID") String sourceNodeUUID, final @MapsTo("targetNodeUUID") String targetNodeUUID);  CloneConnectorCommand(Edge candidate, String sourceNodeUUID, String targetNodeUUID, Consumer<Edge> callback); }
CloneConnectorCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean); clone = context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asEdge(); Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); getMutableIndex(context).addEdge(clone); return this; } CloneConnectorCommand();  CloneConnectorCommand(final @MapsTo("candidate") Edge candidate, final @MapsTo("sourceNodeUUID") String sourceNodeUUID, final @MapsTo("targetNodeUUID") String targetNodeUUID);  CloneConnectorCommand(Edge candidate, String sourceNodeUUID, String targetNodeUUID, Consumer<Edge> callback); @Override CommandResult<RuleViolation> execute(GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); }
CloneConnectorCommand extends AbstractGraphCompositeCommand { @Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); final DefinitionId definitionId = context.getDefinitionManager().adapters().forDefinition().getId(bean); clone = context.getFactoryManager().newElement(UUID.uuid(), definitionId.value()).asEdge(); Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); getMutableIndex(context).addEdge(clone); return this; } CloneConnectorCommand();  CloneConnectorCommand(final @MapsTo("candidate") Edge candidate, final @MapsTo("sourceNodeUUID") String sourceNodeUUID, final @MapsTo("targetNodeUUID") String targetNodeUUID);  CloneConnectorCommand(Edge candidate, String sourceNodeUUID, String targetNodeUUID, Consumer<Edge> callback); @Override CommandResult<RuleViolation> execute(GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context);  }