Search in sources :

Example 81 with Definition

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

the class NodeConnectorTest method testConnectEdgeToNodesWhenDMNDIIsPresentAndNodeIsNotConnectedWithEdge.

@Test
public void testConnectEdgeToNodesWhenDMNDIIsPresentAndNodeIsNotConnectedWithEdge() {
    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(false).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, never()).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 82 with Definition

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

the class DeleteNodeConfirmationImpl method isReferredInAnotherGraph.

boolean isReferredInAnotherGraph(final Element element) {
    if (element.getContent() instanceof Definition) {
        final Definition def = (Definition) element.getContent();
        if (def.getDefinition() instanceof HasContentDefinitionId) {
            final HasContentDefinitionId hasContentDefinitionId = (HasContentDefinitionId) def.getDefinition();
            final String contentId = hasContentDefinitionId.getContentDefinitionId();
            final List<Graph> graphs = getGraphsProvider().getNonGlobalGraphs();
            return graphs.stream().anyMatch(graph -> containsNodeWithContentId(graph, contentId));
        }
    }
    return false;
}
Also used : HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

Example 83 with Definition

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

the class ConnectorParentsMatchContainmentHandler method evaluateContainment.

@SuppressWarnings("unchecked")
private RuleViolations evaluateContainment(final RuleExtension rule, final NodeContainmentContext context) {
    final DefaultRuleViolations result = new DefaultRuleViolations();
    final Collection<Node<? extends Definition<?>, ? extends Edge>> candidates = context.getCandidates();
    candidates.forEach(candidate -> evaluateSingleContainment(result, rule, context, candidate));
    return result;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 84 with Definition

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

the class NodeContainmentEvaluationHandler method evaluate.

@Override
@SuppressWarnings("unchecked")
public RuleViolations evaluate(final CanContain rule, final NodeContainmentContext context) {
    final Element<? extends Definition<?>> parent = context.getParent();
    final Set<String> parentLabels = evalUtils.getLabels(parent);
    final DefaultRuleViolations result = new DefaultRuleViolations();
    final Collection<Node<? extends Definition<?>, ? extends Edge>> candidates = context.getCandidates();
    candidates.forEach(candidate -> result.addViolations(evaluate(rule, candidate.getUUID(), evalUtils.getLabels(candidate), parentLabels)));
    return result;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 85 with Definition

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

the class GraphUtils method computeGraphHashCode.

@SuppressWarnings("all")
public static int computeGraphHashCode(GraphImpl graph) {
    final int[] result = { 0 };
    new TreeWalkTraverseProcessorImpl().traverse(graph, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {

        @Override
        public boolean startEdgeTraversal(final Edge edge) {
            super.startEdgeTraversal(edge);
            final Object content = edge.getContent();
            result[0] = combineHashCodes(result[0], content.hashCode());
            if (edge.getContent() instanceof ViewConnector) {
                Optional<Connection> sourceConnection = ((ViewConnector) edge.getContent()).getSourceConnection();
                sourceConnection.ifPresent(c -> result[0] = combineHashCodes(result[0], c.hashCode()));
                Optional<Connection> targetConnection = ((ViewConnector) edge.getContent()).getTargetConnection();
                targetConnection.ifPresent(c -> result[0] = combineHashCodes(result[0], c.hashCode()));
            }
            return true;
        }

        @Override
        public boolean startNodeTraversal(final Node node) {
            super.startNodeTraversal(node);
            result[0] = combineHashCodes(result[0], node.hashCode());
            if (!(node.getContent() instanceof DefinitionSet) && node.getContent() instanceof Definition) {
                Object def = ((Definition) (node.getContent())).getDefinition();
                result[0] = combineHashCodes(result[0], def.hashCode());
            }
            if (node.getContent() instanceof HasBounds) {
                Bounds bounds = ((HasBounds) node.getContent()).getBounds();
                result[0] = combineHashCodes(result[0], bounds.hashCode());
            }
            return true;
        }
    });
    return result[0];
}
Also used : IntStream(java.util.stream.IntStream) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Edge(org.kie.workbench.common.stunner.core.graph.Edge) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) HashMap(java.util.HashMap) HashUtil.combineHashCodes(org.kie.workbench.common.stunner.core.util.HashUtil.combineHashCodes) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Map(java.util.Map) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Element(org.kie.workbench.common.stunner.core.graph.Element) AbstractTreeTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.AbstractTreeTraverseCallback) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) StreamSupport(java.util.stream.StreamSupport) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) Collection(java.util.Collection) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Set(java.util.Set) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Collectors(java.util.stream.Collectors) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Objects(java.util.Objects) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) Stream(java.util.stream.Stream) Optional(java.util.Optional) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Collections(java.util.Collections) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Optional(java.util.Optional) Node(org.kie.workbench.common.stunner.core.graph.Node) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge) HasBounds(org.kie.workbench.common.stunner.core.graph.content.HasBounds)

Aggregations

Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)111 Node (org.kie.workbench.common.stunner.core.graph.Node)61 Test (org.junit.Test)46 Element (org.kie.workbench.common.stunner.core.graph.Element)31 Edge (org.kie.workbench.common.stunner.core.graph.Edge)25 Graph (org.kie.workbench.common.stunner.core.graph.Graph)20 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)14 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)14 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)11 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 List (java.util.List)9 Before (org.junit.Before)9 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)9 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)9 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)9 Stream (java.util.stream.Stream)8