Search in sources :

Example 36 with Definition

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

the class DMNDiagramsSessionTest method testGetDRGElementFromContentDefinition.

@Test
public void testGetDRGElementFromContentDefinition() {
    final Node nodeWithContentDefinition = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    when(nodeWithContentDefinition.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(drgElement);
    final DRGElement actual = dmnDiagramsSession.getDRGElementFromContentDefinition(nodeWithContentDefinition);
    assertEquals(drgElement, actual);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 37 with Definition

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

the class DMNDiagramsSessionTest method testDefinitionContainsDRGElement.

@Test
public void testDefinitionContainsDRGElement() {
    final Node nodeWithContentDefinition = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    when(nodeWithContentDefinition.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(drgElement);
    assertTrue(dmnDiagramsSession.definitionContainsDRGElement(nodeWithContentDefinition));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 38 with Definition

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

the class DecisionNavigatorBaseItemFactoryTest method testMakeItem.

@Test
@SuppressWarnings("unchecked")
public void testMakeItem() {
    final String itemUUID = "itemUUID";
    final String childUUID = "childUUID";
    final String graphUUID = "graphUUID";
    final String label = "label";
    final Command onClick = mock(Command.class);
    final Node<Definition, Edge> diagramNode = mock(Node.class);
    final Definition diagramDefinition = mock(Definition.class);
    final DMNDiagram diagram = mock(DMNDiagram.class);
    final DecisionNavigatorItem child = new DecisionNavigatorItemBuilder().withUUID(childUUID).build();
    final List<DecisionNavigatorItem> nestedItems = singletonList(child);
    when(node.getUUID()).thenReturn(itemUUID);
    doReturn(label).when(factory).getLabel(node);
    doReturn(onClick).when(factory).makeOnClickCommand(node);
    doReturn(nestedItems).when(factory).makeNestedItems(node);
    when(graph.nodes()).thenReturn(Collections.singletonList(diagramNode));
    when(diagramNode.getContent()).thenReturn(diagramDefinition);
    when(diagramDefinition.getDefinition()).thenReturn(diagram);
    when(diagramNode.getUUID()).thenReturn(graphUUID);
    final DecisionNavigatorItem item = factory.makeItem(node, ITEM);
    assertEquals(itemUUID, item.getUUID());
    assertEquals(label, item.getLabel());
    assertTrue(item.getOnClick().isPresent());
    assertEquals(onClick, item.getOnClick().get());
    assertEquals(asTreeSet(child), item.getChildren());
    assertEquals(itemUUID, child.getParentUUID());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) DecisionNavigatorItem(org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem) DecisionNavigatorItemBuilder(org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItemBuilder) Command(org.uberfire.mvp.Command) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 39 with Definition

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

the class DMNElementsSynchronizerTest method testDefinitionContainsDRGElement_WhenDoesNotContains.

@Test
public void testDefinitionContainsDRGElement_WhenDoesNotContains() {
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final Object obj = mock(Object.class);
    when(definition.getDefinition()).thenReturn(obj);
    when(node.getContent()).thenReturn(definition);
    final boolean containsDRGElement = synchronizer.definitionContainsDRGElement(node);
    assertFalse(containsDRGElement);
}
Also used : 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 40 with Definition

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

the class DMNFlowActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
    final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
    final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
    final Diagram diagram = canvasHandler.getDiagram();
    final String defSetId = diagram.getMetadata().getDefinitionSetId();
    final CommonDomainLookups lookup = toolboxDomainLookups.get(defSetId);
    // Look for the allowed connectors present in the Definition Set.
    final Set<String> allowedConnectorIds = lookup.lookupTargetConnectors(node);
    for (final String allowedConnectorId : allowedConnectorIds) {
        // Append a new action for each connector.
        actions.add(createConnectorActions.get().setEdgeId(allowedConnectorId));
        // Append a new action for each candidate target node (as from the current connector).
        final Set<String> defIds = lookup.lookupTargetNodes(diagram.getGraph(), node, allowedConnectorId);
        defIds.forEach(definitionId -> actions.add(createNodeActions.get().setEdgeId(allowedConnectorId).setNodeId(definitionId)));
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) CreateNodeToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.CreateNodeToolboxAction) CreateConnectorToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.CreateConnectorToolboxAction) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CommonDomainLookups(org.kie.workbench.common.stunner.core.lookup.domain.CommonDomainLookups) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

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