Search in sources :

Example 6 with PMMLDocumentMetadata

use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.

the class DefinitionsConverter method wbFromDMN.

public static Definitions wbFromDMN(final JSITDefinitions dmn, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Name name = new Name(dmn.getName());
    final String namespace = dmn.getNamespace();
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Definitions result = new Definitions();
    result.setId(id);
    result.setName(name);
    result.setNamespace(new Text(namespace));
    result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace);
    result.setExpressionLanguage(ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage()));
    result.setTypeLanguage(dmn.getTypeLanguage());
    result.setDmnDiagramElements(getDMNDiagramElements(dmn));
    result.setDescription(description);
    final Map<String, String> namespaces = NameSpaceUtils.extractNamespacesKeyedByPrefix(dmn);
    for (Entry<String, String> kv : namespaces.entrySet()) {
        String mappedURI = kv.getValue();
        switch(mappedURI) {
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN;
                break;
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL;
                break;
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE;
                break;
        }
        if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            result.getNsContext().putIfAbsent(kv.getKey(), mappedURI);
        } else {
            result.getNsContext().put(kv.getKey(), mappedURI);
        }
    }
    final List<JSITItemDefinition> jsiItemDefinitions = dmn.getItemDefinition();
    for (int i = 0; i < jsiItemDefinitions.size(); i++) {
        final JSITItemDefinition jsiItemDefinition = Js.uncheckedCast(jsiItemDefinitions.get(i));
        final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(jsiItemDefinition);
        if (Objects.nonNull(itemDefConverted)) {
            itemDefConverted.setParent(result);
            result.getItemDefinition().add(itemDefConverted);
        }
    }
    final List<JSITImport> jsiImports = dmn.getImport();
    for (int i = 0; i < jsiImports.size(); i++) {
        final JSITImport jsiImport = Js.uncheckedCast(jsiImports.get(i));
        final JSITDefinitions definitions = Js.uncheckedCast(importDefinitions.get(jsiImport));
        final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(jsiImport);
        final Import importConverted = ImportConverter.wbFromDMN(jsiImport, definitions, pmmlDocument);
        if (Objects.nonNull(importConverted)) {
            importConverted.setParent(result);
            result.getImport().add(importConverted);
        }
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Example 7 with PMMLDocumentMetadata

use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.

the class ImportConverter method createWBImport.

private static Import createWBImport(final JSITImport dmn, final JSITDefinitions definitions, final PMMLDocumentMetadata pmmlDocument) {
    final LocationURI locationURI = new LocationURI(dmn.getLocationURI());
    if (Objects.equals(DMNImportTypes.DMN, determineImportType(dmn.getImportType()))) {
        final ImportDMN result = new ImportDMN(dmn.getNamespace(), locationURI, dmn.getImportType());
        result.setDrgElementsCount(countDefinitionElement(definitions, d -> d.getDrgElement().size()));
        result.setItemDefinitionsCount(countDefinitionElement(definitions, d -> d.getItemDefinition().size()));
        return result;
    } else if (Objects.equals(DMNImportTypes.PMML, determineImportType(dmn.getImportType()))) {
        final ImportPMML result = new ImportPMML(dmn.getNamespace(), locationURI, dmn.getImportType());
        result.setModelCount(countDefinitionElement(pmmlDocument, document -> document.getModels().size()));
        return result;
    } else {
        return new Import(dmn.getNamespace(), locationURI, dmn.getImportType());
    }
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) HashMap(java.util.HashMap) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Function(java.util.function.Function) DMNImportTypes.determineImportType(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType) Objects(java.util.Objects) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Import(org.kie.workbench.common.dmn.api.definition.model.Import) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) NameSpaceUtils(org.kie.workbench.common.dmn.client.marshaller.common.NameSpaceUtils) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) Map(java.util.Map) Optional(java.util.Optional) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) XMLConstants(javax.xml.XMLConstants) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 8 with PMMLDocumentMetadata

use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetPMMLDocuments.

@Test
public void testGetPMMLDocuments() {
    final Path dmnModelPath = mock(Path.class);
    final Metadata metadata = mock(Metadata.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    final Import import1 = mock(Import.class);
    final List<Import> imports = singletonList(import1);
    final Path path1 = mock(Path.class);
    final Path path2 = mock(Path.class);
    final List<Path> paths = asList(path1, path2);
    when(metadata.getPath()).thenReturn(dmnModelPath);
    when(import1.getLocationURI()).thenReturn("document1.pmml");
    when(pathsHelper.getRelativeURI(dmnModelPath, path1)).thenReturn("document1.pmml");
    when(pathsHelper.getRelativeURI(dmnModelPath, path2)).thenReturn("document2.pmml");
    when(pmmlDocumentFactory.getDocumentByPath(path1)).thenReturn(pmmlDocument);
    doReturn(paths).when(helper).getPMMLDocumentPaths(metadata);
    final Map<Import, PMMLDocumentMetadata> importDefinitions = helper.getPMMLDocuments(metadata, imports);
    assertEquals(1, importDefinitions.size());
    assertEquals(pmmlDocument, importDefinitions.get(import1));
}
Also used : Path(org.uberfire.backend.vfs.Path) Import(org.kie.dmn.model.api.Import) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Test(org.junit.Test)

Example 9 with PMMLDocumentMetadata

use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.

the class ImportConverterTest method testWbFromDMNWhenGeneric.

@Test
public void testWbFromDMNWhenGeneric() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType("cheese");
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    assertNotNull(anImport);
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.dmn.model.api.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Test(org.junit.Test)

Example 10 with PMMLDocumentMetadata

use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.

the class ImportConverterTest method testWbFromDMNWhenDMNImport.

@Test
public void testWbFromDMNWhenDMNImport() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    final String key = "drools";
    final String value = "http://www.drools.org/kie/dmn/1.1";
    dmn.getNsContext().put(key, value);
    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)));
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    final Map<String, String> nsContext = anImport.getNsContext();
    assertEquals(1, nsContext.size());
    assertEquals(value, nsContext.get(key));
    assertTrue(anImport instanceof ImportDMN);
    final ImportDMN dmnImport = (ImportDMN) anImport;
    assertEquals(2, dmnImport.getDrgElementsCount());
    assertEquals(3, dmnImport.getItemDefinitionsCount());
}
Also used : ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.dmn.model.api.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Test(org.junit.Test)

Aggregations

PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)30 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)10 PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)9 List (java.util.List)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)6 Path (org.uberfire.backend.vfs.Path)6 Objects (java.util.Objects)5 Optional (java.util.Optional)5 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)5 PMMLModelMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata)5 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)5 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)5 Definitions (org.kie.dmn.model.api.Definitions)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 Promise (elemental2.promise.Promise)3 Arrays.asList (java.util.Arrays.asList)3