use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector in project kie-wb-common by kiegroup.
the class BPMN2JsonParser method initialize.
/*
****************************************************************
* Custom Stunner logic
****************************************************************
*/
@SuppressWarnings("unchecked")
private void initialize(final ContextualParser.Context parsingContext) {
Graph graph = diagram.getGraph();
final Map<String, EdgeParser> edgeParsers = new HashMap<>();
new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()).traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {
final Stack<NodeParser> parsers = new Stack<NodeParser>();
NodeParser currentParser = null;
@Override
public void startGraphTraversal(Graph<DefinitionSet, Node<View, Edge>> graph) {
super.startGraphTraversal(graph);
}
@Override
public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) {
super.startNodeTraversal(parents, node);
onNodeTraversal(node);
return true;
}
@Override
public void startNodeTraversal(final Node<View, Edge> node) {
super.startNodeTraversal(node);
onNodeTraversal(node);
}
private void onNodeTraversal(final Node node) {
NodeParser p = new NodeParser("", node);
if (null != currentParser) {
parsers.peek().addChild(p);
} else {
BPMN2JsonParser.this.rootParser = p;
}
currentParser = p;
List<Edge> outEdges = node.getOutEdges();
if (null != outEdges && !outEdges.isEmpty()) {
for (Edge edge : outEdges) {
// Only add the edges with view connector types into the resulting structure to generate the bpmn definition.
if (edge.getContent() instanceof ViewConnector && !edgeParsers.containsKey(edge.getUUID())) {
edgeParsers.put(edge.getUUID(), new EdgeParser("", (Edge) edge));
}
}
}
}
@Override
public void startEdgeTraversal(Edge<Child, Node> edge) {
super.startEdgeTraversal(edge);
parsers.push(currentParser);
}
@Override
public void endEdgeTraversal(Edge<Child, Node> edge) {
super.endEdgeTraversal(edge);
currentParser = parsers.pop();
}
@Override
public void endGraphTraversal() {
super.endGraphTraversal();
}
});
// In oryx format, all edges are added into the main BPMNDiagram node.
if (null != rootParser && !edgeParsers.isEmpty()) {
for (EdgeParser edgeParser : edgeParsers.values()) {
rootParser.addChild(edgeParser);
}
}
// Initialize all the element parsers added in the tree.
BPMN2JsonParser.this.rootParser.initialize(parsingContext);
System.out.println("End of children and view traverse");
}
use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testMagnetsInLane.
private void testMagnetsInLane(Diagram<Graph, Metadata> diagram) throws Exception {
Node userTaskNode = (Node) findElementByContentType(diagram, UserTask.class);
Node scriptTaskNode = (Node) findElementByContentType(diagram, ScriptTask.class);
assertNotNull(userTaskNode);
assertNotNull(scriptTaskNode);
ViewConnector userTaskInEdgeConnector = getInEdgeViewConnector(userTaskNode);
ViewConnector scriptTaskInEdgeConnector = getInEdgeViewConnector(scriptTaskNode);
assertNotNull(userTaskInEdgeConnector);
assertNotNull(scriptTaskInEdgeConnector);
ViewConnector userTaskOutEdgeConnector = getOutEdgeViewConnector(userTaskNode);
ViewConnector scriptTaskOutEdgeConnector = getOutEdgeViewConnector(scriptTaskNode);
assertNotNull(userTaskOutEdgeConnector);
assertNotNull(scriptTaskOutEdgeConnector);
// userTaskInEdgeConnector is from magnet right-middle to middle-top
assertTrue(userTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(userTaskInEdgeConnector.getTargetConnection().isPresent());
Connection sourceConnection = (Connection) userTaskInEdgeConnector.getSourceConnection().get();
Connection targetConnection = (Connection) userTaskInEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(24d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(68d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// scriptTaskInEdgeConnector is from magnet right-bottom to left-top
assertTrue(scriptTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(scriptTaskInEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (Connection) scriptTaskInEdgeConnector.getSourceConnection().get();
targetConnection = (Connection) scriptTaskInEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// userTaskOutEdgeConnector is from magnet right-bottom to left-top
assertTrue(userTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(userTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (Connection) userTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (Connection) userTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// scriptTaskOutEdgeConnector is from magnet right-top to left-middle
assertTrue(scriptTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(scriptTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (Connection) scriptTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (Connection) scriptTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(14d, targetConnection.getLocation().getY(), 0.1d);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testUnmarshallXorGateway.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallXorGateway() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_XORGATEWAY);
assertDiagram(diagram, 7);
assertEquals(diagram.getMetadata().getTitle(), "XORGateway");
Graph graph = diagram.getGraph();
Node<? extends Definition, ?> gatewayNode = graph.getNode("_877EA035-1A14-42E9-8CAA-43E9BF908C70");
ExclusiveGateway xorGateway = (ExclusiveGateway) gatewayNode.getContent().getDefinition();
assertEquals("AgeSplit", xorGateway.getGeneral().getName().getValue());
assertEquals("_5110D608-BDAD-47BF-A3F9-E1DBE43ED7CD", xorGateway.getExecutionSet().getDefaultRoute().getValue());
SequenceFlow sequenceFlow1 = null;
SequenceFlow sequenceFlow2 = null;
List<Edge> outEdges = (List<Edge>) gatewayNode.getOutEdges();
if (outEdges != null) {
for (Edge edge : outEdges) {
if ("_C72E00C3-70DC-4BC9-A08E-761B4263A239".equals(edge.getUUID())) {
sequenceFlow1 = (SequenceFlow) ((ViewConnector) edge.getContent()).getDefinition();
} else if ("_5110D608-BDAD-47BF-A3F9-E1DBE43ED7CD".equals(edge.getUUID())) {
sequenceFlow2 = (SequenceFlow) ((ViewConnector) edge.getContent()).getDefinition();
}
}
}
assertNotNull(sequenceFlow1);
assertEquals("10 and over", sequenceFlow1.getGeneral().getName().getValue());
assertNotNull(sequenceFlow2);
assertEquals("under 10", sequenceFlow2.getGeneral().getName().getValue());
}
use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testMagnetDockers.
private void testMagnetDockers(Diagram<Graph, Metadata> diagram) throws Exception {
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);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest 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);
}
Aggregations