Search in sources :

Example 1 with Parent

use of org.kie.workbench.common.stunner.core.graph.content.relationship.Parent 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;
}
Also used : Parent(org.kie.workbench.common.stunner.core.graph.content.relationship.Parent) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 2 with Parent

use of org.kie.workbench.common.stunner.core.graph.content.relationship.Parent in project kie-wb-common by kiegroup.

the class SetParentNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.INFO, result.getType());
    assertFalse(parent.getOutEdges().isEmpty());
    assertFalse(candidate.getInEdges().isEmpty());
    Edge edge = (Edge) parent.getOutEdges().get(0);
    assertTrue(edge.getContent() instanceof Parent);
    assertEquals(parent, edge.getSourceNode());
    assertEquals(candidate, edge.getTargetNode());
    verify(graphIndex, times(1)).addEdge(eq(edge));
    verify(graphIndex, times(0)).addNode(any(Node.class));
}
Also used : Parent(org.kie.workbench.common.stunner.core.graph.content.relationship.Parent) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 Parent (org.kie.workbench.common.stunner.core.graph.content.relationship.Parent)2 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)2 Test (org.junit.Test)1 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)1 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)1