Search in sources :

Example 1 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 org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(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.setDescription(description);
    for (Entry<String, String> kv : dmn.getNsContext().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);
        }
    }
    for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) {
        final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef);
        if (itemDefConverted != null) {
            itemDefConverted.setParent(result);
        }
        result.getItemDefinition().add(itemDefConverted);
    }
    for (org.kie.dmn.model.api.Import i : dmn.getImport()) {
        final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i);
        final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i);
        final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument);
        if (importConverted != null) {
            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) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 2 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 org.kie.dmn.model.api.Import dmn, final Definitions 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(pmmlDocument.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) UUID(java.util.UUID) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Definitions(org.kie.dmn.model.api.Definitions) DMNImportTypes.determineImportType(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType) Objects(java.util.Objects) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) 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) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) Map(java.util.Map) Optional(java.util.Optional) 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) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 3 with PMMLDocumentMetadata

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

the class DMNContentServiceImplTest method testLoadPMMLDocumentMetadata.

@Test
public void testLoadPMMLDocumentMetadata() {
    final PMMLDocumentMetadata expected = mock(PMMLDocumentMetadata.class);
    when(pmmlIncludedDocumentFactory.getDocumentByPath(path)).thenReturn(expected);
    final PMMLDocumentMetadata actual = service.loadPMMLDocumentMetadata(path);
    assertEquals(expected, actual);
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Test(org.junit.Test)

Example 4 with PMMLDocumentMetadata

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

the class PMMLDocumentMetadataProviderTest method testGetPMMLDocumentNames.

@Test
public void testGetPMMLDocumentNames() {
    final List<PMMLDocumentMetadata> pmmlDocuments = new ArrayList<>();
    pmmlDocuments.add(new PMMLDocumentMetadata("path1", "zDocument1", DMNImportTypes.PMML.getDefaultNamespace(), Collections.emptyList()));
    pmmlDocuments.add(new PMMLDocumentMetadata("path2", "aDocument2", DMNImportTypes.PMML.getDefaultNamespace(), Collections.emptyList()));
    final ServiceCallback<List<PMMLDocumentMetadata>> callback = loadPMMLIncludedDocuments();
    callback.onSuccess(pmmlDocuments);
    final List<String> documentNames = provider.getPMMLDocumentNames();
    assertThat(documentNames).containsSequence("aDocument2", "zDocument1");
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 5 with PMMLDocumentMetadata

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

the class PMMLDocumentMetadataProviderTest method testGetPMMLDocumentModelNames.

@Test
public void testGetPMMLDocumentModelNames() {
    final List<PMMLDocumentMetadata> pmmlDocuments = new ArrayList<>();
    pmmlDocuments.add(new PMMLDocumentMetadata("path", "document", DMNImportTypes.PMML.getDefaultNamespace(), asList(new PMMLModelMetadata("zModel1", Collections.emptySet()), new PMMLModelMetadata("aModel2", Collections.emptySet()))));
    final ServiceCallback<List<PMMLDocumentMetadata>> callback = loadPMMLIncludedDocuments();
    callback.onSuccess(pmmlDocuments);
    final List<String> modelNames = provider.getPMMLDocumentModels("document");
    assertThat(modelNames).containsSequence("aModel2", "zModel1");
    assertThat(provider.getPMMLDocumentModels("unknown")).isEmpty();
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) PMMLModelMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata) 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