Search in sources :

Example 41 with Definitions

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

the class DMNDiagramHelperTest method testGetItemDefinitionsByDiagram.

@Test
public void testGetItemDefinitionsByDiagram() {
    final Definitions definitions = mock(Definitions.class);
    final List<ItemDefinition> expectedItemDefinitions = asList(mock(ItemDefinition.class), mock(ItemDefinition.class));
    when(definitions.getItemDefinition()).thenReturn(expectedItemDefinitions);
    when(dmnDiagramUtils.getDefinitions(diagram)).thenReturn(definitions);
    final List<ItemDefinition> actualItemDefinitions = helper.getItemDefinitions(diagram);
    assertEquals(expectedItemDefinitions, actualItemDefinitions);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Test(org.junit.Test)

Example 42 with Definitions

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

the class AbstractDMNDiagramFactory method updateName.

private void updateName(final Node<Definition<DMNDiagram>, ?> diagramNode, final String name) {
    final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
    final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
    final Name dmnName = dmnDefinitions.getName();
    if (StringUtils.isEmpty(dmnName.getValue())) {
        dmnName.setValue(name);
    }
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 43 with Definitions

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

the class AbstractDMNDiagramFactory method updateDefaultNameSpaces.

private void updateDefaultNameSpaces(final Node<Definition<DMNDiagram>, ?> diagramNode) {
    final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
    final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
    Stream.of(DMNModelInstrumentedBase.Namespace.values()).filter(namespace -> !dmnDefinitions.getNsContext().containsValue(namespace.getUri())).forEach(namespace -> {
        if (!namespace.getPrefix().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            dmnDefinitions.getNsContext().put(namespace.getPrefix(), namespace.getUri());
        }
    });
    String defaultNamespace = !StringUtils.isEmpty(dmnDefinitions.getNamespace().getValue()) ? dmnDefinitions.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
    dmnDefinitions.setNamespace(new Text(defaultNamespace));
    dmnDefinitions.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), defaultNamespace);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) UUID(org.kie.workbench.common.stunner.core.util.UUID) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Function(java.util.function.Function) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Stream(java.util.stream.Stream) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) BindableDiagramFactory(org.kie.workbench.common.stunner.core.factory.impl.BindableDiagramFactory) StringUtils(org.kie.workbench.common.stunner.core.util.StringUtils) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Text(org.kie.workbench.common.dmn.api.property.dmn.Text)

Example 44 with Definitions

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

the class DMNDiagramFactoryImplTest method testModelName.

@Test
@SuppressWarnings("unchecked")
public void testModelName() {
    final Diagram diagram = factory.build(NAME, metadata, graph);
    // We can safely get the first object on the iterator as we know the graph only contains one node
    final Node<View, Edge> root = (Node<View, Edge>) diagram.getGraph().nodes().iterator().next();
    final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(root);
    final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
    assertEquals(NAME, dmnDefinitions.getName().getValue());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 45 with Definitions

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

the class DMNDiagramFactoryImplTest method testModelNameWithNonEmptyExistingName.

@Test
@SuppressWarnings("unchecked")
public void testModelNameWithNonEmptyExistingName() {
    final Node<View, Edge> existingRoot = (Node<View, Edge>) graph.nodes().iterator().next();
    final DMNDiagram existingDMNDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(existingRoot);
    final Definitions existingDMNDefinitions = existingDMNDiagram.getDefinitions();
    existingDMNDefinitions.getName().setValue(EXISTING_NAME);
    final Diagram newDiagram = factory.build(NAME, metadata, graph);
    final Node<View, Edge> newRoot = (Node<View, Edge>) newDiagram.getGraph().nodes().iterator().next();
    final DMNDiagram newDMNDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(newRoot);
    final Definitions newDMNDefinitions = newDMNDiagram.getDefinitions();
    assertEquals(EXISTING_NAME, newDMNDefinitions.getName().getValue());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Aggregations

Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)70 Test (org.junit.Test)41 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)24 Node (org.kie.workbench.common.stunner.core.graph.Node)23 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)22 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)19 ArrayList (java.util.ArrayList)18 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)18 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)15 Import (org.kie.workbench.common.dmn.api.definition.model.Import)15 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)14 List (java.util.List)13 Objects (java.util.Objects)12 Optional (java.util.Optional)12 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)12 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)12 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)12 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Map (java.util.Map)11