Search in sources :

Example 11 with Decision

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

the class DMNMarshallerStandaloneTest method checkEdgewaypoint.

@SuppressWarnings("unchecked")
private void checkEdgewaypoint(Graph<?, Node<?, ?>> graph) {
    Node<?, ?> decision = graph.getNode("_7647e26b-6c7c-46db-aa34-1a1a2b4d8d79");
    assertNodeContentDefinitionIs(decision, Decision.class);
    Decision decisionDefinition = ((View<Decision>) decision.getContent()).getDefinition();
    assertEquals("my decision", decisionDefinition.getName().getValue());
    Node<?, ?> inputdata = graph.getNode("_fd528e66-e2a4-4b7f-aae1-c3ca6723d0cb");
    assertNodeEdgesTo(inputdata, decision, InformationRequirement.class);
    // asserted the two Stunner graph nodes are properly connected, assert location of edge.
    List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) inputdata.getOutEdges();
    Edge<?, ?> edge = outEdges.stream().filter(e -> e.getTargetNode().equals(decision)).findFirst().get();
    ViewConnector<?> connectionContent = (ViewConnector<?>) edge.getContent();
    Point2D sourceLocation = connectionContent.getSourceConnection().get().getLocation();
    assertEquals(266.9968013763428d, ((View) inputdata.getContent()).getBounds().getUpperLeft().getX() + sourceLocation.getX(), 0.1d);
    assertEquals(225.99999618530273d, ((View) inputdata.getContent()).getBounds().getUpperLeft().getY() + sourceLocation.getY(), 0.1d);
    Point2D targetLocation = connectionContent.getTargetConnection().get().getLocation();
    assertEquals(552.2411708831787d, ((View) decision.getContent()).getBounds().getUpperLeft().getX() + targetLocation.getX(), 0.1d);
    assertEquals(226d, ((View) decision.getContent()).getBounds().getUpperLeft().getY() + targetLocation.getY(), 0.1d);
    assertEquals(1, connectionContent.getControlPoints().length);
    Point2D controlPointLocation = connectionContent.getControlPoints()[0].getLocation();
    assertEquals(398.61898612976074d, controlPointLocation.getX(), 0.1d);
    assertEquals(116.99999809265137d, controlPointLocation.getY(), 0.1d);
    final Connection sourceConnection = connectionContent.getSourceConnection().get();
    assertTrue(sourceConnection instanceof MagnetConnection);
    assertFalse(((MagnetConnection) sourceConnection).isAuto());
    final Connection targetConnection = connectionContent.getTargetConnection().get();
    assertTrue(targetConnection instanceof MagnetConnection);
    assertFalse(((MagnetConnection) targetConnection).isAuto());
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) 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 12 with Decision

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

the class DMNMarshallerStandaloneTest method testGetDmnElementRefWithFakeNamespace.

@Test
public void testGetDmnElementRefWithFakeNamespace() {
    final Decision drgElement = mock(Decision.class);
    final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
    final Name drgElementName = mock(Name.class);
    final Id id = mock(Id.class);
    final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn("fakeNamespace.Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(emptyList());
    final String actual = getDmnElementRef(definitions, view).getLocalPart();
    final String expected = "0000-1111-2222";
    assertEquals(expected, actual);
}
Also used : ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(javax.xml.namespace.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 13 with Decision

use of org.kie.workbench.common.dmn.api.definition.model.Decision 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 14 with Decision

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

the class DMNMarshallerStandaloneTest method testGetDmnElementRefWithoutNamespace.

@Test
public void testGetDmnElementRefWithoutNamespace() {
    final Decision drgElement = mock(Decision.class);
    final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
    final Name drgElementName = mock(Name.class);
    final Id id = mock(Id.class);
    final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn("Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(emptyList());
    final String actual = getDmnElementRef(definitions, view).getLocalPart();
    final String expected = "0000-1111-2222";
    assertEquals(expected, actual);
}
Also used : ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(javax.xml.namespace.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 15 with Decision

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

the class KnowledgeSourceConverter method dmnFromNode.

@Override
public org.kie.dmn.model.api.KnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
    final KnowledgeSource source = (KnowledgeSource) DefinitionUtils.getElementDefinition(node);
    final org.kie.dmn.model.api.KnowledgeSource result = new org.kie.dmn.model.v1_2.TKnowledgeSource();
    result.setId(source.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    result.setName(source.getName().getValue());
    result.setType(source.getType().getValue());
    result.setLocationURI(source.getLocationURI().getValue());
    DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
    // DMN spec table 2: Requirements connection rules
    final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        final Node<?, ?> sourceNode = e.getSourceNode();
        if (sourceNode.getContent() instanceof View<?>) {
            final View<?> view = (View<?>) sourceNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) view.getDefinition();
                if (drgElement instanceof Decision) {
                    final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredDecision(ri);
                    result.getAuthorityRequirement().add(iReq);
                } else if (drgElement instanceof KnowledgeSource) {
                    final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredAuthority(ri);
                    result.getAuthorityRequirement().add(iReq);
                } else if (drgElement instanceof InputData) {
                    final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredInput(ri);
                    result.getAuthorityRequirement().add(iReq);
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    return result;
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) List(java.util.List) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Aggregations

Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)121 Test (org.junit.Test)79 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)39 View (org.kie.workbench.common.stunner.core.graph.content.view.View)38 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)37 Node (org.kie.workbench.common.stunner.core.graph.Node)28 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)23 Edge (org.kie.workbench.common.stunner.core.graph.Edge)23 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)22 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)21 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)20 List (java.util.List)16 TDecision (org.kie.dmn.model.v1_2.TDecision)16 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)16 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)16 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)16 ArrayList (java.util.ArrayList)15 Optional (java.util.Optional)15 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)15