Search in sources :

Example 6 with DMNDiagram

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method setup.

@Before
public void setup() {
    super.setup();
    this.diagram = new DMNDiagram();
    this.inputData1 = new InputData();
    this.inputData2 = new InputData();
    this.decision1 = new Decision();
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Before(org.junit.Before)

Example 7 with DMNDiagram

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.

the class DMNMarshallerStandaloneTest method connectTwoNodes.

@SuppressWarnings("unchecked")
private Diagram<Graph, Metadata> connectTwoNodes(final org.kie.workbench.common.stunner.core.graph.content.Bounds bounds, final String decisionNode1UUID, final String decisionNode2UUID, final String edgeUUID, final MagnetConnection edgeSourceConnection, final MagnetConnection edgeTargetConnection, final Consumer<MagnetConnection> sourceMagnetConsumer, final Consumer<MagnetConnection> targetMagnetConsumer) {
    final DiagramImpl diagram = createDiagram();
    final Graph<DefinitionSet, Node> graph = mock(Graph.class);
    final Node<View, Edge> diagramNode = mock(Node.class);
    final View diagramView = mock(View.class);
    final DMNDiagram dmnDiagram = new DMNDiagram();
    when(diagramNode.getContent()).thenReturn(diagramView);
    when(diagramView.getDefinition()).thenReturn(dmnDiagram);
    final Node<View, Edge> decisionNode1 = mock(Node.class);
    final View decisionView1 = mock(View.class);
    final Decision decision1 = new Decision();
    decision1.getId().setValue(decisionNode1UUID);
    when(decisionNode1.getContent()).thenReturn(decisionView1);
    when(decisionView1.getDefinition()).thenReturn(decision1);
    when(decisionView1.getBounds()).thenReturn(bounds);
    final Node<View, Edge> decisionNode2 = mock(Node.class);
    final View decisionView2 = mock(View.class);
    final Decision decision2 = new Decision();
    decision2.getId().setValue(decisionNode2UUID);
    when(decisionNode2.getContent()).thenReturn(decisionView2);
    when(decisionView2.getDefinition()).thenReturn(decision2);
    when(decisionView2.getBounds()).thenReturn(bounds);
    final Edge edge = mock(Edge.class);
    final ViewConnector edgeView = mock(ViewConnector.class);
    Optional edgeSourceConnectionOptional = Optional.empty();
    if (edgeSourceConnection != null) {
        edgeSourceConnectionOptional = Optional.of(edgeSourceConnection);
    }
    Optional edgeTargetConnectionOptional = Optional.empty();
    if (edgeTargetConnection != null) {
        edgeTargetConnectionOptional = Optional.of(edgeTargetConnection);
    }
    when(edge.getUUID()).thenReturn(edgeUUID);
    when(edge.getContent()).thenReturn(edgeView);
    when(edgeView.getSourceConnection()).thenReturn(edgeSourceConnectionOptional);
    when(edgeView.getTargetConnection()).thenReturn(edgeTargetConnectionOptional);
    when(edgeView.getControlPoints()).thenReturn(new ControlPoint[] {});
    when(decisionNode1.getOutEdges()).thenReturn(Collections.singletonList(edge));
    when(decisionNode2.getInEdges()).thenReturn(Collections.singletonList(edge));
    when(edge.getSourceNode()).thenReturn(decisionNode1);
    when(edge.getTargetNode()).thenReturn(decisionNode2);
    sourceMagnetConsumer.accept(edgeSourceConnection);
    targetMagnetConsumer.accept(edgeTargetConnection);
    doReturn(asList(diagramNode, decisionNode1, decisionNode2)).when(graph).nodes();
    diagram.setGraph(graph);
    return diagram;
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Optional(java.util.Optional) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision)

Example 8 with DMNDiagram

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.

the class DMNMarshallerStandaloneTest method newDiagramDecisionWithExpression.

@SuppressWarnings("unchecked")
private Diagram<Graph, Metadata> newDiagramDecisionWithExpression(final Expression expression) {
    final Diagram<Graph, Metadata> diagram = createDiagram();
    final Graph<DefinitionSet, Node> graph = mock(Graph.class);
    final Node<View, ?> diagramNode = mock(Node.class);
    final View diagramView = mock(View.class);
    final DMNDiagram dmnDiagram = new DMNDiagram();
    doReturn(diagramView).when(diagramNode).getContent();
    doReturn(dmnDiagram).when(diagramView).getDefinition();
    final Node<View, ?> decisionNode = mock(Node.class);
    final View decisionView = mock(View.class);
    final Decision decision = new Decision();
    doReturn(decisionView).when(decisionNode).getContent();
    doReturn(decision).when(decisionView).getDefinition();
    decision.setExpression(expression);
    doReturn(asList(diagramNode, decisionNode)).when(graph).nodes();
    ((DiagramImpl) diagram).setGraph(graph);
    return diagram;
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision)

Example 9 with DMNDiagram

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.

the class DMNMarshallerService method registerDiagramInstance.

public void registerDiagramInstance(final Diagram diagram, final String title, final String shapeSetId) {
    registerMetadata(diagram, title, shapeSetId);
    final Node<?, ?> dmnDiagramRoot = DMNGraphUtils.findDMNDiagramRoot(diagram.getGraph());
    final DMNDiagram definition = ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition();
    final DMNDiagramElement drgDiagram = DRGDiagramUtils.newDRGInstance();
    final String diagramId = drgDiagram.getId().getValue();
    final Map<String, Diagram> diagramsByDiagramElementId = new HashMap<>();
    final Map<String, DMNDiagramElement> dmnDiagramsByDiagramElementId = new HashMap<>();
    definition.getDefinitions().getDiagramElements().add(drgDiagram);
    diagramsByDiagramElementId.put(diagramId, diagram);
    dmnDiagramsByDiagramElementId.put(diagramId, drgDiagram);
    dmnDiagramsSession.setState(getMetadata(), diagramsByDiagramElementId, dmnDiagramsByDiagramElementId);
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) HashMap(java.util.HashMap) JSONString(com.google.gwt.json.client.JSONString) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)

Example 10 with DMNDiagram

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram 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)

Aggregations

DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)33 Node (org.kie.workbench.common.stunner.core.graph.Node)25 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)19 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)17 Test (org.junit.Test)16 View (org.kie.workbench.common.stunner.core.graph.content.view.View)16 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Graph (org.kie.workbench.common.stunner.core.graph.Graph)12 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)10 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 ArrayList (java.util.ArrayList)9 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)8 HashMap (java.util.HashMap)7 Optional (java.util.Optional)7 DMNDefinitionSet (org.kie.workbench.common.dmn.api.DMNDefinitionSet)7 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)7 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)7 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)7