Search in sources :

Example 16 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.

the class DMNDiagramElementsUtils method generateDRGElement.

private JSIDMNDiagram generateDRGElement(final JSITDefinitions dmnDefinitions) {
    final JSIDMNDiagram drg = DRGDiagramUtils.newJSIDRGInstance();
    final double[] globalOriginX = { 0 };
    forEach(getDmnDiagram(dmnDefinitions), dmnDiagram -> {
        final List<JSIDiagramElement> elements = dmnDiagram.getDMNDiagramElement();
        final double[] diagramOriginX = { globalOriginX[0] };
        forEach(elements, element -> {
            final JSIDiagramElement copy = Js.uncheckedCast(jsCopy(element));
            if (JSIDMNShape.instanceOf(copy)) {
                final JSIDMNShape shape = Js.uncheckedCast(copy);
                final JSIBounds bounds = shape.getBounds();
                final double currentMax = bounds.getX() + bounds.getWidth();
                shape.setId(uniqueId());
                bounds.setX(diagramOriginX[0] + bounds.getX());
                if (currentMax > globalOriginX[0]) {
                    globalOriginX[0] = currentMax;
                }
            }
            if (JSIDMNEdge.instanceOf(copy)) {
                final JSIDMNEdge shape = Js.uncheckedCast(copy);
                shape.setId(uniqueId());
                shape.setOtherAttributes(null);
                forEach(shape.getWaypoint(), jsiPoint -> jsiPoint.setX(diagramOriginX[0] + jsiPoint.getX()));
            }
            drg.addDMNDiagramElement(Js.uncheckedCast(JsUtils.getWrappedElement(copy)));
        });
    });
    return drg;
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 17 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.

the class NodeConnectorTest method testIsSourceAutoConnectionEdge.

@Test
public void testIsSourceAutoConnectionEdge() {
    String edgeId = "edge-name";
    JSIDMNEdge edge = mock(JSIDMNEdge.class);
    when(edge.getId()).thenReturn(edgeId);
    assertFalse(nodeConnector.isSourceAutoConnectionEdge(edge));
    when(edge.getId()).thenReturn(edgeId + AUTO_SOURCE_CONNECTION);
    assertTrue(nodeConnector.isSourceAutoConnectionEdge(edge));
}
Also used : JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

Example 18 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.

the class NodeConnectorTest method testConnectEdgeToNodesWhenDMNDIIsPresent.

@Test
public void testConnectEdgeToNodesWhenDMNDIIsPresent() {
    final JSIDMNEdge existingEdge = mock(JSIDMNEdge.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final String id = "789";
    final String contentDefinitionId = "123";
    final List<NodeEntry> list = singletonList(nodeEntry);
    when(jsiDMNElementReference.getHref()).thenReturn("#123");
    when(jsiDMNElement.getId()).thenReturn(id);
    when(existingEdge.getDmnElementRef()).thenReturn(new QName("", id));
    when(definition.getDefinition()).thenReturn(drgElement);
    when(currentNode.getContent()).thenReturn(definition);
    when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
    doReturn(true).when(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
    doReturn(Optional.of(requiredNode)).when(nodeConnector).getSourceNode(eq(existingEdge), any());
    doNothing().when(nodeConnector).connectWbEdge(any(), any(), any(), any(), any(), any());
    entriesById.put(contentDefinitionId, list);
    edges.add(existingEdge);
    isDMNDIPresent = true;
    nodeConnector.connectEdgeToNodes(connectorTypeId, jsiDMNElement, jsiDMNElementReference, entriesById, diagramId, edges, isDMNDIPresent, currentNode);
    verify(nodeConnector).connectWbEdge(eq(connectorTypeId), eq(diagramId), eq(currentNode), eq(requiredNode), eq(existingEdge), eq("789"));
    verify(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
}
Also used : QName(javax.xml.namespace.QName) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 19 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.

the class NodeConnectorTest method testGetTargetNode_WhenThereIsOnlyASingleNode.

@Test
public void testGetTargetNode_WhenThereIsOnlyASingleNode() {
    final JSIDMNEdge jsiDMNEdge = mock(JSIDMNEdge.class);
    final NodeEntry nodeEntry = mock(NodeEntry.class);
    final Node node = mock(Node.class);
    final List nodeEntries = singletonList(nodeEntry);
    when(nodeEntry.getNode()).thenReturn(node);
    Optional<Node> targetNode = nodeConnector.getTargetNode(jsiDMNEdge, nodeEntries);
    assertTrue(targetNode.isPresent());
    assertEquals(targetNode.get(), node);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

Example 20 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.

the class NodeConnectorTest method testSetConnectionMagnets.

@Test
public void testSetConnectionMagnets() {
    Edge edge = mock(Edge.class);
    ViewConnector viewConnector = mock(ViewConnector.class);
    JSIDMNEdge jsidmnEdge = mock(JSIDMNEdge.class);
    Node sourceNode = mock(Node.class);
    Node targetNode = mock(Node.class);
    View<?> view = mock(View.class);
    Bounds bounds = mock(Bounds.class);
    JSIPoint start = mock(JSIPoint.class);
    JSIPoint waypoint = mock(JSIPoint.class);
    JSIPoint end = mock(JSIPoint.class);
    List<JSIPoint> waypoints = new ArrayList<>();
    waypoints.add(start);
    waypoints.add(waypoint);
    waypoints.add(end);
    NodeConnector nodeConnector = mock(NodeConnector.class);
    doCallRealMethod().when(nodeConnector).setConnectionMagnets(eq(edge), eq(viewConnector), eq(jsidmnEdge));
    when(jsidmnEdge.getWaypoint()).thenReturn(waypoints);
    when(jsidmnEdge.getId()).thenReturn(AUTO_SOURCE_CONNECTION + AUTO_TARGET_CONNECTION);
    when(edge.getSourceNode()).thenReturn(sourceNode);
    when(edge.getTargetNode()).thenReturn(targetNode);
    when(sourceNode.getContent()).thenReturn(view);
    when(targetNode.getContent()).thenReturn(view);
    when(view.getBounds()).thenReturn(bounds);
    when(bounds.getWidth()).thenReturn(0.0);
    when(bounds.getHeight()).thenReturn(0.0);
    when(start.getX()).thenReturn(0.0);
    when(start.getY()).thenReturn(0.0);
    when(waypoint.getX()).thenReturn(1.0);
    when(waypoint.getY()).thenReturn(1.0);
    when(start.getX()).thenReturn(1.0);
    when(start.getY()).thenReturn(1.0);
    nodeConnector.setConnectionMagnets(edge, viewConnector, jsidmnEdge);
    verify(nodeConnector).isSourceAutoConnectionEdge(jsidmnEdge);
    verify(nodeConnector).isTargetAutoConnectionEdge(jsidmnEdge);
    verify(viewConnector).setControlPoints(any());
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) ArrayList(java.util.ArrayList) JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

Aggregations

JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)26 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Collections.singletonList (java.util.Collections.singletonList)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)7 JSIPoint (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 QName (javax.xml.namespace.QName)4 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)4 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)4 JSIBounds (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)3 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)3 JSITDMNElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement)3 JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)3 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 Point2D (com.ait.lienzo.client.core.types.Point2D)2