use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl in project kie-wb-common by kiegroup.
the class AcyclicDirectedGraphRuleTest method checkCyclicalConnection.
@Test
@SuppressWarnings("unchecked")
public void checkCyclicalConnection() {
final Node node1 = new NodeImpl<>("node1");
final Node node2 = new NodeImpl<>("node2");
final Edge c1 = new EdgeImpl<>("edge1");
node1.getOutEdges().add(c1);
node2.getInEdges().add(c1);
c1.setSourceNode(node1);
c1.setTargetNode(node2);
graph.addNode(node1);
graph.addNode(node2);
when(context.getSource()).thenReturn(Optional.of(node2));
when(context.getTarget()).thenReturn(Optional.of(node1));
when(context.getConnector()).thenReturn(connector);
final RuleViolations result = check.evaluate(rule, context);
assertNotNull(result);
assertTrue(result.violations().iterator().hasNext());
final RuleViolation violation = result.violations().iterator().next();
assertNotNull(violation);
assertTrue(violation.getArguments().isPresent());
assertEquals(1, violation.getArguments().get().length);
assertEquals(AcyclicDirectedGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl in project kie-wb-common by kiegroup.
the class SingleConnectorPerTypeGraphRuleTest method checkHasExistingConnection.
@Test
@SuppressWarnings("unchecked")
public void checkHasExistingConnection() {
final Node node1 = new NodeImpl<>("node1");
final Node node2 = new NodeImpl<>("node2");
final Edge existingConnector = new EdgeImpl<>("edge1");
final ViewConnector existingConnectorView = mock(ViewConnector.class);
existingConnector.setContent(existingConnectorView);
when(existingConnectorView.getDefinition()).thenReturn(new Definition());
node1.getOutEdges().add(existingConnector);
node2.getInEdges().add(existingConnector);
existingConnector.setSourceNode(node1);
existingConnector.setTargetNode(node2);
graph.addNode(node1);
graph.addNode(node2);
when(context.getSource()).thenReturn(Optional.of(node1));
when(context.getTarget()).thenReturn(Optional.of(node2));
when(context.getConnector()).thenReturn(connector);
final RuleViolations result = check.evaluate(rule, context);
assertNotNull(result);
assertTrue(result.violations().iterator().hasNext());
final RuleViolation violation = result.violations().iterator().next();
assertNotNull(violation);
assertTrue(violation.getArguments().isPresent());
assertEquals(1, violation.getArguments().get().length);
assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl in project kie-wb-common by kiegroup.
the class DMNMarshaller method connectRootWithChild.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void connectRootWithChild(final Node dmnDiagramRoot, final Node child) {
final String uuid = org.kie.workbench.common.stunner.core.util.UUID.uuid();
final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Child());
connectEdge(edge, dmnDiagramRoot, child);
}
use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl in project kie-wb-common by kiegroup.
the class SetChildNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final Node<?, Edge> parent = getParent(context);
final Node<?, Edge> candidate = getCandidate(context);
final String uuid = UUID.uuid();
final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Child());
edge.setSourceNode(parent);
edge.setTargetNode(candidate);
parent.getOutEdges().add(edge);
candidate.getInEdges().add(edge);
getMutableIndex(context).addEdge(edge);
}
return results;
}
use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl in project kie-wb-common by kiegroup.
the class SetParentNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final Node<?, Edge> parent = getParent(context);
final Node<?, Edge> candidate = getCandidate(context);
// TODO: Create a ParentEdgeFactory iface extending EdgeFactory using as content generics type Relationship
final String uuid = UUID.uuid();
final Edge<Parent, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Parent());
edge.setSourceNode(parent);
edge.setTargetNode(candidate);
parent.getOutEdges().add(edge);
candidate.getInEdges().add(edge);
getMutableIndex(context).addEdge(edge);
}
return results;
}
Aggregations