use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.
the class NodeConnector method setConnectionMagnets.
void setConnectionMagnets(final Edge edge, final ViewConnector connectionContent, final JSIDMNEdge jsidmnEdge) {
final JSIDMNEdge e = Js.uncheckedCast(jsidmnEdge);
final JSIPoint source = Js.uncheckedCast(e.getWaypoint().get(0));
final Node<View<?>, Edge> sourceNode = edge.getSourceNode();
if (null != sourceNode) {
setConnectionMagnet(sourceNode, source, connectionContent::setSourceConnection, isSourceAutoConnectionEdge(jsidmnEdge));
}
final JSIPoint target = Js.uncheckedCast(e.getWaypoint().get(e.getWaypoint().size() - 1));
final Node<View<?>, Edge> targetNode = edge.getTargetNode();
if (null != targetNode) {
setConnectionMagnet(targetNode, target, connectionContent::setTargetConnection, isTargetAutoConnectionEdge(jsidmnEdge));
}
if (e.getWaypoint().size() > 2) {
connectionContent.setControlPoints(e.getWaypoint().subList(1, e.getWaypoint().size() - 1).stream().map(p -> ControlPoint.build(PointUtils.dmndiPointToPoint2D(p))).toArray(ControlPoint[]::new));
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.
the class NodeEntriesFactory method getEdges.
private List<JSIDMNEdge> getEdges(final JSIDMNDiagram dmnDiagram) {
final List<JSIDMNEdge> edges = new ArrayList<>();
final List<JSIDiagramElement> dmnDiagramElements = dmnDiagram.getDMNDiagramElement();
forEach(dmnDiagramElements, dmnDiagramElement -> {
if (JSIDMNEdge.instanceOf(dmnDiagramElement)) {
final JSIDMNEdge jsiEdge = Js.uncheckedCast(dmnDiagramElement);
edges.add(jsiEdge);
}
});
return edges;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testConnect.
@Test
public void testConnect() {
final DMNMarshaller dmnMarshaller = new DMNMarshaller();
final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
final List<String> dmnDiagramElementIds = mock(List.class);
final Definitions definitionsStunnerPojo = mock(Definitions.class);
final List<JSIDMNEdge> dmnEdges = new ArrayList<>();
final Node<?, ?> node = mock(Node.class);
final List inEdges = new ArrayList<>();
final Edge edge = mock(Edge.class);
final Node sourceNode = mock(Node.class);
final View sourceView = mock(View.class);
final ViewConnector viewConnector = mock(ViewConnector.class);
final DiscreteConnection sourceConnection = mock(DiscreteConnection.class);
final DiscreteConnection targetConnection = mock(DiscreteConnection.class);
final View<?> view = mock(View.class);
inEdges.add(edge);
when(edge.getSourceNode()).thenReturn(sourceNode);
when(sourceNode.getContent()).thenReturn(sourceView);
when(node.getInEdges()).thenReturn(inEdges);
when(edge.getContent()).thenReturn(viewConnector);
when(viewConnector.getControlPoints()).thenReturn(new ControlPoint[] {});
when(sourceConnection.isAuto()).thenReturn(true);
when(targetConnection.isAuto()).thenReturn(true);
when(diagram.getName()).thenReturn("dmnEdge");
when(definitionsStunnerPojo.getDefaultNamespace()).thenReturn("org.edge");
when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
when(viewConnector.getTargetConnection()).thenReturn(Optional.of(targetConnection));
dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
when(viewConnector.getSourceConnection()).thenReturn(Optional.empty());
when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
verify(sourceConnection).isAuto();
verify(targetConnection).isAuto();
}
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 testConnectWbEdge.
@Test
public void testConnectWbEdge() {
final JSIDMNEdge edge = mock(JSIDMNEdge.class);
final Element element = mock(Element.class);
final String id = "123";
final Edge wbEdge = mock(Edge.class);
final ViewConnector viewConnector = mock(ViewConnector.class);
when(factoryManager.newElement("diagramId#123", connectorTypeId)).thenReturn(element);
when(element.asEdge()).thenReturn(wbEdge);
when(wbEdge.getContent()).thenReturn(viewConnector);
doNothing().when(nodeConnector).connectEdge(any(), any(), any());
doNothing().when(nodeConnector).setConnectionMagnets(any(), any(), any());
nodeConnector.connectWbEdge(connectorTypeId, diagramId, currentNode, requiredNode, edge, id);
verify(nodeConnector).connectEdge(wbEdge, requiredNode, currentNode);
verify(nodeConnector).setConnectionMagnets(wbEdge, viewConnector, 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 testGetTargetNode.
@Test
public void testGetTargetNode() {
final JSIDMNEdge jsiDMNEdge = mock(JSIDMNEdge.class);
final double targetX = 7.0;
final double targetY = 8.0;
final JSIPoint sourcePoint = createPoint(1, 2);
final JSIPoint targetPoint = createPoint(targetX, targetY);
final List<JSIPoint> waypoints = Arrays.asList(sourcePoint, targetPoint);
final List nodeEntries = mock(List.class);
final Point2D targetPoint2D = new Point2D(targetX, targetY);
when(jsiDMNEdge.getWaypoint()).thenReturn(waypoints);
doReturn(Optional.of(mock(Node.class))).when(nodeConnector).getNodeFromPoint(targetPoint2D, nodeEntries);
nodeConnector.getTargetNode(jsiDMNEdge, nodeEntries);
verify(nodeConnector).getNodeFromPoint(targetPoint2D, nodeEntries);
}
Aggregations