Search in sources :

Example 61 with Definition

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

the class DMNCanvasHandlerTest method getElementForTestUpdateDiagramId.

private Element getElementForTestUpdateDiagramId(final String diagramId, final String currentDiagramId, final HasContentDefinitionId hasContentDefinitionId) {
    final Element element = mock(Element.class);
    final Definition definition = mock(Definition.class);
    final GraphsProvider graphsProvider = mock(GraphsProvider.class);
    when(graphsProvider.getCurrentDiagramId()).thenReturn(diagramId);
    when(definition.getDefinition()).thenReturn(hasContentDefinitionId);
    when(element.getContent()).thenReturn(definition);
    when(hasContentDefinitionId.getDiagramId()).thenReturn(currentDiagramId);
    when(canvasHandler.getGraphsProvider()).thenReturn(graphsProvider);
    return element;
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) GraphsProvider(org.kie.workbench.common.stunner.core.diagram.GraphsProvider)

Example 62 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 evaluateSingleContainment.

@SuppressWarnings("unchecked")
private void evaluateSingleContainment(final DefaultRuleViolations result, final RuleExtension rule, final NodeContainmentContext context, final Node<? extends Definition<?>, ? extends Edge> candidate) {
    final GraphEvaluationState state = context.getState();
    final Graph<?, ? extends Node> graph = context.getState().getGraph();
    final String connectorId = rule.getId();
    // Walk throw the graph and evaluate connector source and target nodes parent match.
    treeWalkTraverseProcessor.traverse(graph, candidate, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {

        @Override
        public boolean startNodeTraversal(final Node node) {
            // Process incoming edges into the node as well.
            final List<? extends Edge> inEdges = node.getInEdges();
            if (null != inEdges) {
                inEdges.stream().forEach(this::process);
            }
            return true;
        }

        @Override
        public boolean startEdgeTraversal(final Edge edge) {
            return process(edge);
        }

        private boolean process(final Edge edge) {
            final Optional<String> eId = getId(definitionManager, edge);
            if (eId.isPresent() && connectorId.equals(eId.get())) {
                final Node sourceNode = state.getConnectionState().getSource(edge);
                final Node targetNode = state.getConnectionState().getTarget(edge);
                final boolean valid = new ParentTypesMatcher(() -> definitionManager, e -> getParent(context, e), rule.getTypeArguments()).matcher().test(sourceNode, targetNode);
                if (!valid) {
                    addViolation(edge.getUUID(), rule, result);
                }
            }
            return true;
        }
    });
}
Also used : StatefulContainmentState.getParent(org.kie.workbench.common.stunner.core.rule.context.impl.StatefulGraphEvaluationState.StatefulContainmentState.getParent) Collection(java.util.Collection) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) GraphEvaluationState(org.kie.workbench.common.stunner.core.rule.context.GraphEvaluationState) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) NodeContainmentContext(org.kie.workbench.common.stunner.core.rule.context.NodeContainmentContext) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Stream(java.util.stream.Stream) ParentTypesMatcher(org.kie.workbench.common.stunner.core.graph.util.ParentTypesMatcher) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) GraphEvaluationHandlerUtils(org.kie.workbench.common.stunner.core.rule.handler.impl.GraphEvaluationHandlerUtils) AbstractTreeTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.AbstractTreeTraverseCallback) Optional(java.util.Optional) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) ApplicationScoped(javax.enterprise.context.ApplicationScoped) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Node(org.kie.workbench.common.stunner.core.graph.Node) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Optional(java.util.Optional) ParentTypesMatcher(org.kie.workbench.common.stunner.core.graph.util.ParentTypesMatcher) Node(org.kie.workbench.common.stunner.core.graph.Node) List(java.util.List) Edge(org.kie.workbench.common.stunner.core.graph.Edge) GraphEvaluationState(org.kie.workbench.common.stunner.core.rule.context.GraphEvaluationState)

Example 63 with Definition

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

the class CaseManagementUtilsTest method checkGetFirstDiagramNodeWithNonEmptyGraph.

@Test
@SuppressWarnings("unchecked")
public void checkGetFirstDiagramNodeWithNonEmptyGraph() {
    final Graph graph = new GraphImpl<>("uuid", new GraphNodeStoreImpl());
    final Node node = new NodeImpl<Definition>("node-uuid");
    final CaseManagementDiagram content = new CaseManagementDiagram.CaseManagementDiagramBuilder().build();
    node.setContent(new DefinitionImpl<>(content));
    graph.addNode(node);
    final Node<Definition<CaseManagementDiagram>, ?> fNode = CaseManagementUtils.getFirstDiagramNode(graph);
    assertNotNull(fNode);
    assertEquals("node-uuid", fNode.getUUID());
    assertEquals(content, fNode.getContent().getDefinition());
}
Also used : GraphNodeStoreImpl(org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl) Graph(org.kie.workbench.common.stunner.core.graph.Graph) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) CaseManagementDiagram(org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Test(org.junit.Test)

Example 64 with Definition

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

the class StartEventFilterProvider method provideFilters.

@Override
public Collection<FormElementFilter> provideFilters(String elementUUID, Element<? extends Definition<?>> element, Object definition) {
    Predicate predicate = o -> isParentAnEventSubProcess(elementUUID);
    FormElementFilter isInterruptingFilter = new FormElementFilter("executionSet.isInterrupting", predicate);
    return Arrays.asList(isInterruptingFilter);
}
Also used : Arrays(java.util.Arrays) StunnerFormElementFilterProvider(org.kie.workbench.common.stunner.forms.client.formFilters.StunnerFormElementFilterProvider) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Edge(org.kie.workbench.common.stunner.core.graph.Edge) FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Supplier(java.util.function.Supplier) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) View(org.kie.workbench.common.stunner.core.graph.content.view.View) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) EventSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EventSubprocess) Element(org.kie.workbench.common.stunner.core.graph.Element) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Node(org.kie.workbench.common.stunner.core.graph.Node) FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) Predicate(java.util.function.Predicate)

Example 65 with Definition

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

the class BaseDiagramMarshaller method getTitle.

private String getTitle(final Graph graph) {
    final Node<Definition<BPMNDiagram>, ?> diagramNode = getFirstDiagramNode(graph);
    final BPMNDiagram diagramBean = null != diagramNode ? (BPMNDiagram) ((Definition) diagramNode.getContent()).getDefinition() : null;
    return getTitle(diagramBean);
}
Also used : BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

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