Search in sources :

Example 1 with DefinitionSet

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

the class GraphValidatorImplTest method testValidateEmptyViewConnectorNodes.

@Test
@SuppressWarnings("unchecked")
public void testValidateEmptyViewConnectorNodes() {
    final RuleSet ruleSet = graphTestHandler.ruleSet;
    final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
    final TestingGraphInstanceBuilder.TestGraph1 testGraph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    // Update the edge2 and remove the connection's target node.
    // From this point, a validation error is expected.
    graphTestHandler.removeTargetConnection(testGraph1.edge2);
    tested.validate(graph, ruleSet, ruleViolations -> {
        assertEquals(1, ruleViolations.size());
        final RuleViolation violation = ruleViolations.iterator().next();
        assertNotNull(violation);
        assertTrue(violation instanceof EmptyConnectionViolation);
        EmptyConnectionViolation v = (EmptyConnectionViolation) violation;
        final Optional<Object[]> arguments = v.getArguments();
        assertTrue(arguments.isPresent());
        assertEquals(testGraph1.edge2.getUUID(), arguments.get()[0]);
        assertEquals(testGraph1.intermNode.getUUID(), arguments.get()[1]);
        assertNull(arguments.get()[2]);
    });
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) EmptyConnectionViolation(org.kie.workbench.common.stunner.core.rule.violations.EmptyConnectionViolation) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 2 with DefinitionSet

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

the class GraphValidatorImplTest method testValidateGraph2.

@Test
@SuppressWarnings("unchecked")
public void testValidateGraph2() {
    final RuleManager ruleManager = graphTestHandler.ruleManager;
    final RuleSet ruleSet = graphTestHandler.ruleSet;
    final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
    final TestingGraphInstanceBuilder.TestGraph2 testGraph2 = TestingGraphInstanceBuilder.newGraph2(graphTestHandler);
    tested.validate(getGraph(), graphTestHandler.ruleSet, this::assertNoError);
    final int evalCount = testGraph2.evaluationsCount + 11;
    final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
    verify(ruleManager, times(evalCount)).evaluate(eq(ruleSet), contextCaptor.capture());
    final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
    assertEquals(evalCount, contexts.size());
    int cindex = testGraph2.evaluationsCount;
    verifyCardinality((ElementCardinalityContext) contexts.get(cindex++), graph);
    verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph2.parentNode);
    verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.startNode);
    verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge1, testGraph2.startNode, testGraph2.intermNode);
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge1, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.startNode, testGraph2.edge1, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
    verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.intermNode);
    verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge2, testGraph2.intermNode, testGraph2.endNode);
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.endNode, testGraph2.edge2, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge2, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
    verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.endNode);
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Test(org.junit.Test)

Example 3 with DefinitionSet

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

the class GraphImpl method hashCode.

@Override
public int hashCode() {
    // dirty trick to allow inner class to modify variable
    int[] hashArr = { 0 };
    final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl();
    treeWalkTraverseProcessor.traverse(this, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {

        int[] myHashArr = hashArr;

        @Override
        public boolean startEdgeTraversal(final Edge edge) {
            super.startEdgeTraversal(edge);
            final Object content = edge.getContent();
            myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], content.hashCode());
            return true;
        }

        @Override
        public boolean startNodeTraversal(final Node node) {
            super.startNodeTraversal(node);
            myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], node.hashCode());
            if (!(node.getContent() instanceof DefinitionSet) && node.getContent() instanceof Definition) {
                Object def = ((Definition) (node.getContent())).getDefinition();
                myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], def.hashCode());
            }
            return true;
        }
    });
    // Get the hash from the graph traversal
    return hashArr[0];
}
Also used : TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)

Example 4 with DefinitionSet

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

the class AbstractGraphFactory method build.

@Override
@SuppressWarnings("unchecked   ")
public Graph<DefinitionSet, Node> build(final String uuid, final String definitionSetId) {
    final GraphImpl graph = new GraphImpl<>(uuid, new GraphNodeStoreImpl());
    final DefinitionSet content = new DefinitionSetImpl(definitionSetId);
    graph.setContent(content);
    graph.getLabels().add(definitionSetId);
    content.setBounds(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(getWidth(), getHeight())));
    return graph;
}
Also used : GraphNodeStoreImpl(org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl) DefinitionSetImpl(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSetImpl) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)

Example 5 with DefinitionSet

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

the class LocationControlImpl method getLocationBounds.

@SuppressWarnings("unchecked")
private double[] getLocationBounds() {
    final Graph<DefinitionSet, ? extends Node> graph = canvasHandler.getDiagram().getGraph();
    final Bounds bounds = graph.getContent().getBounds();
    return new double[] { bounds.getUpperLeft().getX(), bounds.getUpperLeft().getY(), bounds.getLowerRight().getX(), bounds.getLowerRight().getY() };
}
Also used : HasDragBounds(org.kie.workbench.common.stunner.core.client.shape.view.HasDragBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)

Aggregations

DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)15 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Graph (org.kie.workbench.common.stunner.core.graph.Graph)6 Test (org.junit.Test)5 Edge (org.kie.workbench.common.stunner.core.graph.Edge)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)4 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)4 TestingGraphInstanceBuilder (org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder)3 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)3 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)3 TreeWalkTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)3 Command (org.kie.workbench.common.stunner.core.command.Command)2 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)2 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)2 TreeNode (com.fasterxml.jackson.core.TreeNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1