Search in sources :

Example 36 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 37 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 38 with Definitions

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

the class DataTypePickerWidget method addItemDefinitions.

void addItemDefinitions() {
    final Definitions definitions = dmnGraphUtils.getModelDefinitions();
    final List<ItemDefinition> itemDefinitions = definitions != null ? definitions.getItemDefinition() : Collections.emptyList();
    final OptGroup group = GWT.create(OptGroup.class);
    group.setLabel(translationService.getTranslation(DMNEditorConstants.DataTypeSelectView_CustomTitle));
    itemDefinitions.stream().sorted(ITEM_DEFINITION_COMPARATOR).map(this::makeTypeSelector).filter(Optional::isPresent).forEach(o -> group.add(o.get()));
    typeSelector.add(group);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) OptGroup(org.gwtbootstrap3.extras.select.client.ui.OptGroup)

Example 39 with Definitions

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

the class DefinitionsConverterTest method wbFromDMN.

@Test
public void wbFromDMN() {
    final Import anImport = new TImport();
    anImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    final org.kie.dmn.model.api.Definitions definitions = mock(org.kie.dmn.model.api.Definitions.class);
    final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = new Maps.Builder<Import, org.kie.dmn.model.api.Definitions>().put(anImport, definitions).build();
    final Map<Import, PMMLDocumentMetadata> pmmlDocuments = new Maps.Builder<Import, PMMLDocumentMetadata>().build();
    when(definitions.getDrgElement()).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class)));
    when(definitions.getItemDefinition()).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class)));
    when(apiDefinitions.getImport()).thenReturn(singletonList(anImport));
    final Definitions wb = DefinitionsConverter.wbFromDMN(apiDefinitions, importDefinitions, pmmlDocuments);
    final String defaultNs = wb.getNsContext().get(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix());
    final String namespace = wb.getNamespace().getValue();
    final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = wb.getImport();
    assertEquals(defaultNs, namespace);
    assertEquals(1, imports.size());
    assertTrue(imports.get(0) instanceof ImportDMN);
    final ImportDMN importDMN = (ImportDMN) imports.get(0);
    assertEquals(2, importDMN.getDrgElementsCount());
    assertEquals(3, importDMN.getItemDefinitionsCount());
}
Also used : TImport(org.kie.dmn.model.v1_2.TImport) Import(org.kie.dmn.model.api.Import) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Maps(org.kie.soup.commons.util.Maps) Test(org.junit.Test)

Example 40 with Definitions

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

the class DMNDomainValidatorImplTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws IOException {
    this.definitions = new Definitions();
    this.validationMessages = new ArrayList<>();
    this.domainValidator = spy(new DMNDomainValidatorImpl(dmnMarshaller, dmnDiagramUtils, importsHelper, dmnIOHelper));
    doReturn(dmnValidator).when(domainValidator).getDMNValidator();
    domainValidator.setupValidator();
    when(dmnMarshaller.marshall(diagram)).thenReturn(DMN_XML);
    when(dmnDiagramUtils.getDefinitions(diagram)).thenReturn(definitions);
    when(dmnValidator.validateUsing(any())).thenReturn(dmnValidatorBuilder);
    when(dmnValidatorBuilder.usingImports(resolver)).thenReturn(dmnValidatorBuilder);
    when(dmnValidatorBuilder.theseModels(Mockito.<Reader>any())).thenReturn(validationMessages);
    when(diagram.getMetadata()).thenReturn(metadata);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Before(org.junit.Before)

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