Search in sources :

Example 86 with Node

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

the class BPMNDirectDiagramMarshallerTest method testMagnetDockers.

private void testMagnetDockers(Diagram<Graph, Metadata> diagram) {
    Node userTaskNode = (Node) findElementByContentType(diagram, UserTask.class);
    Node businessRuleTaskNode = (Node) findElementByContentType(diagram, BusinessRuleTask.class);
    Node scriptTaskNode = (Node) findElementByContentType(diagram, ScriptTask.class);
    assertNotNull(userTaskNode);
    assertNotNull(businessRuleTaskNode);
    assertNotNull(scriptTaskNode);
    ViewConnector userTaskInEdgeConnector = getInEdgeViewConnector(userTaskNode);
    ViewConnector businessRuleTaskInEdgeConnector = getInEdgeViewConnector(businessRuleTaskNode);
    ViewConnector scriptTaskInEdgeConnector = getInEdgeViewConnector(scriptTaskNode);
    assertNotNull(userTaskInEdgeConnector);
    assertNotNull(businessRuleTaskInEdgeConnector);
    assertNotNull(scriptTaskInEdgeConnector);
    ViewConnector userTaskOutEdgeConnector = getOutEdgeViewConnector(userTaskNode);
    ViewConnector businessRuleTaskOutEdgeConnector = getOutEdgeViewConnector(businessRuleTaskNode);
    ViewConnector scriptTaskOutEdgeConnector = getOutEdgeViewConnector(scriptTaskNode);
    assertNotNull(userTaskOutEdgeConnector);
    assertNotNull(businessRuleTaskOutEdgeConnector);
    assertNotNull(scriptTaskOutEdgeConnector);
    // userTaskInEdgeConnector is from magnet top-middle to left-middle
    assertTrue(userTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(userTaskInEdgeConnector.getTargetConnection().isPresent());
    DiscreteConnection sourceConnection = (DiscreteConnection) userTaskInEdgeConnector.getSourceConnection().get();
    DiscreteConnection targetConnection = (DiscreteConnection) userTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(20d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(24d, targetConnection.getLocation().getY(), 0.1d);
    // Assert both connections for userTaskInEdgeConnector are set to auto.
    assertTrue(sourceConnection.isAuto());
    assertTrue(targetConnection.isAuto());
    // businessRuleTaskInEdgeConnector is from magnet right-middle to top-left
    assertTrue(businessRuleTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(businessRuleTaskInEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (DiscreteConnection) businessRuleTaskInEdgeConnector.getSourceConnection().get();
    targetConnection = (DiscreteConnection) businessRuleTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(40d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(20d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // Assert both connections for businessRuleTaskInEdgeConnector are NOT set to auto.
    assertFalse(sourceConnection.isAuto());
    assertFalse(targetConnection.isAuto());
    // scriptTaskInEdgeConnector is from magnet left-bottom to left-bottom
    assertTrue(scriptTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(scriptTaskInEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (DiscreteConnection) scriptTaskInEdgeConnector.getSourceConnection().get();
    targetConnection = (DiscreteConnection) scriptTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(0d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(40d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(48d, targetConnection.getLocation().getY(), 0.1d);
    // userTaskOutEdgeConnector is from magnet right-middle to left-middle
    assertTrue(userTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(userTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (DiscreteConnection) userTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (DiscreteConnection) userTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(24d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(14d, targetConnection.getLocation().getY(), 0.1d);
    // businessRuleTaskOutEdgeConnector is from magnet middle-bottom to middle-bottom
    assertTrue(businessRuleTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(businessRuleTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (DiscreteConnection) businessRuleTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (DiscreteConnection) businessRuleTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(68d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(14d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(28d, targetConnection.getLocation().getY(), 0.1d);
    // scriptTaskOutEdgeConnector is from magnet left-top to left-top
    assertTrue(scriptTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(scriptTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (DiscreteConnection) scriptTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (DiscreteConnection) scriptTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(0d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
}
Also used : ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) Node(org.kie.workbench.common.stunner.core.graph.Node) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) BusinessRuleTask(org.kie.workbench.common.stunner.bpmn.definition.BusinessRuleTask)

Example 87 with Node

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallNotBoundaryEvents.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallNotBoundaryEvents() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_NOT_BOUNDARY_EVENTS);
    assertEquals("Not Boundary Event", diagram.getMetadata().getTitle());
    assertDiagram(diagram, 6);
    // Assert than the intermediate event is connected using a view connector,
    // so not boundary to the task ( not docked ).
    Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
    List<Edge> inEdges = event.getInEdges();
    boolean foundViewConnector = false;
    for (Edge e : inEdges) {
        if (e.getContent() instanceof ViewConnector) {
            foundViewConnector = true;
        }
    }
    assertTrue(foundViewConnector);
    // Assert absolute position as the node is not docked.
    Bounds bounds = ((View) event.getContent()).getBounds();
    Bounds.Bound ul = bounds.getUpperLeft();
    Bounds.Bound lr = bounds.getLowerRight();
    assertEquals(305, ul.getX(), 0);
    assertEquals(300, ul.getY(), 0);
    assertEquals(335, lr.getX(), 0);
    assertEquals(330, lr.getY(), 0);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 88 with Node

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

the class BPMNDirectDiagramMarshallerTest method testUnmarshallBoundaryEvents.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallBoundaryEvents() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_BOUNDARY_EVENTS);
    // Basic assertions.
    assertEquals("Boundary Event", diagram.getMetadata().getTitle());
    assertDiagram(diagram, 6);
    // Assert than the intermediate event is connected using a dock connector,
    // so boundary to the task.
    Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
    List<Edge> inEdges = event.getInEdges();
    boolean foundDockConector = false;
    for (Edge e : inEdges) {
        if (e.getContent() instanceof Dock) {
            foundDockConector = true;
        }
    }
    assertTrue(foundDockConector);
    // Assert relative position for the docked node.
    Bounds bounds = ((View) event.getContent()).getBounds();
    Bounds.Bound ul = bounds.getUpperLeft();
    Bounds.Bound lr = bounds.getLowerRight();
    assertEquals(57, ul.getX(), 0);
    assertEquals(70, ul.getY(), 0);
    assertEquals(87, lr.getX(), 0);
    assertEquals(100, lr.getY(), 0);
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 89 with Node

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

the class MockApplicationFactoryManager method newElement.

@Override
public Element<?> newElement(String uuid, Class<?> type) {
    String id = BindableAdapterUtils.getGenericClassName(type);
    if (BPMNDefinitionSet.class.equals(type)) {
        Graph graph = bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
        return graph;
    }
    Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
    if (null != model) {
        Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
        if (element.isAssignableFrom(NodeFactory.class)) {
            Node node = viewNodeFactory.build(uuid, model);
            return node;
        } else if (element.isAssignableFrom(EdgeFactory.class)) {
            Edge edge = connectionEdgeFactory.build(uuid, model);
            return edge;
        }
    }
    return null;
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeFactory(org.kie.workbench.common.stunner.core.factory.graph.EdgeFactory) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 90 with Node

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

the class BPMNDiagramMarshallerBase method getNodes.

@SuppressWarnings("unchecked")
protected List<Node> getNodes(Diagram<Graph, Metadata> diagram) {
    Graph graph = diagram.getGraph();
    assertNotNull(graph);
    Iterator<Node> nodesIterable = graph.nodes().iterator();
    List<Node> nodes = new ArrayList<>();
    nodesIterable.forEachRemaining(nodes::add);
    return nodes;
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList)

Aggregations

Node (org.kie.workbench.common.stunner.core.graph.Node)153 Edge (org.kie.workbench.common.stunner.core.graph.Edge)85 View (org.kie.workbench.common.stunner.core.graph.content.view.View)59 Test (org.junit.Test)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)32 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)24 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)21 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)17 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)13 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)13 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)13 List (java.util.List)12 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 Before (org.junit.Before)11 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)11 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)11