Search in sources :

Example 66 with Definitions

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

the class HrefBuilderTest method testGetHrefForImportedDRGElement.

@Test
public void testGetHrefForImportedDRGElement() {
    final DRGElement drgElement = mock(DRGElement.class);
    final Name drgElementName = mock(Name.class);
    final Name importName = mock(Name.class);
    final Id id = mock(Id.class);
    final Definitions definitions = mock(Definitions.class);
    final Import anImport = mock(Import.class);
    final List<Import> imports = singletonList(anImport);
    final String includedModelName = "includedModel";
    when(importName.getValue()).thenReturn(includedModelName);
    when(anImport.getName()).thenReturn(importName);
    when(anImport.getNamespace()).thenReturn("https://github.com/kiegroup/dmn/something");
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(imports);
    final String actual = HrefBuilder.getHref(drgElement);
    final String expected = "https://github.com/kiegroup/dmn/something#0000-1111-2222";
    assertEquals(expected, actual);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 67 with Definitions

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

the class DMNDomainValidatorImpl method validate.

@Override
public Collection<DomainViolation> validate(final Diagram diagram, final String diagramXml) {
    final List<Reader> dmnXMLReaders = new ArrayList<>();
    try {
        dmnXMLReaders.add(getStringReader(diagramXml));
        // Load Readers for all other imported DMN models.
        final Definitions uiDefinitions = dmnDiagramUtils.getDefinitions(diagram);
        final List<Import> uiImports = uiDefinitions.getImport();
        final List<org.kie.dmn.model.api.Import> dmnImports = uiImports.stream().map(ImportConverter::dmnFromWb).collect(Collectors.toList());
        final Metadata metadata = diagram.getMetadata();
        final Map<org.kie.dmn.model.api.Import, String> importedDiagramsXML = importsHelper.getImportXML(metadata, dmnImports);
        importedDiagramsXML.values().forEach(importedDiagramXML -> dmnXMLReaders.add(getStringReader(importedDiagramXML)));
        final Reader[] aDMNXMLReaders = new Reader[] {};
        final List<DMNMessage> messages = dmnValidator.validateUsing(DMNValidator.Validation.VALIDATE_MODEL, DMNValidator.Validation.VALIDATE_COMPILATION, DMNValidator.Validation.ANALYZE_DECISION_TABLE).usingImports(getValidatorImportReaderResolver(metadata)).theseModels(dmnXMLReaders.toArray(aDMNXMLReaders));
        return convert(messages);
    } finally {
        dmnXMLReaders.forEach(reader -> {
            try {
                reader.close();
            } catch (IOException ioe) {
            // Swallow. The Reader is already closed.
            }
        });
    }
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ArrayList(java.util.ArrayList) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Reader(java.io.Reader) StringReader(java.io.StringReader) IOException(java.io.IOException) DMNMessage(org.kie.dmn.api.core.DMNMessage)

Example 68 with Definitions

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithMultipleHierarchyCustomTypes.

@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithMultipleHierarchyCustomTypes() {
    setupGraphWithDiagram();
    setupGraphWithInputData();
    final Definitions definitions = diagram.getDefinitions();
    final String tSmurf = "tSmurf";
    final String tSmurfAddress = "tSmurfAddress";
    final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
    final QName stringBuiltInType = new QName(QName.NULL_NS_URI, STRING.getName());
    final ItemDefinition tSmurfAddressCustomDataType = new ItemDefinition();
    tSmurfAddressCustomDataType.setName(new Name(tSmurfAddress));
    tSmurfAddressCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name("line1"));
            setTypeRef(stringBuiltInType);
        }
    });
    tSmurfAddressCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name("line2"));
            setTypeRef(stringBuiltInType);
        }
    });
    final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
    tSmurfCustomDataType.setName(new Name(tSmurf));
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name("dob"));
            setTypeRef(dateBuiltInType);
        }
    });
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name("address"));
            getItemComponent().add(tSmurfAddressCustomDataType);
        }
    });
    definitions.getItemDefinition().add(tSmurfCustomDataType);
    final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurf);
    inputData1.getVariable().setTypeRef(inputData1TypeRef);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    definition.enrich(Optional.of(NODE_UUID), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    final List<InputClause> input = model.getInput();
    assertThat(input.size()).isEqualTo(4);
    assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
    assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
    assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".address." + tSmurfAddress + ".line1");
    assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(stringBuiltInType);
    assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".address." + tSmurfAddress + ".line2");
    assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(stringBuiltInType);
    assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".dob");
    assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
    assertStandardOutputClauseEnrichment(model);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 69 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 70 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)

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