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;
}
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));
}
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));
}
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);
}
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());
}
Aggregations