Search in sources :

Example 21 with PMMLDocumentMetadata

use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata 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 22 with PMMLDocumentMetadata

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

the class PMMLIncludedDocumentFactoryTest method testGetDocumentByPathWithUnknownPathWithIncludedModel.

@Test
public void testGetDocumentByPathWithUnknownPathWithIncludedModel() {
    final Path path = mock(Path.class);
    final PMMLIncludedModel includedModel = makePMMLIncludedModel();
    when(path.toURI()).thenReturn(URI);
    when(ioService.newInputStream(any())).thenThrow(new NoSuchFileException());
    final PMMLDocumentMetadata document = factory.getDocumentByPath(path, includedModel);
    assertThat(document).isNotNull();
    assertThat(document.getPath()).isEqualTo(URI);
    assertThat(document.getImportType()).isEqualTo(NAMESPACE);
    assertThat(document.getName()).isEqualTo(DOCUMENT_NAME);
    assertThat(document.getModels()).isEmpty();
}
Also used : Path(org.uberfire.backend.vfs.Path) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) Test(org.junit.Test)

Example 23 with PMMLDocumentMetadata

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

the class DMNIncludedModelsServiceImplTest method testLoadPMMLDocumentsFromImports.

@Test
public void testLoadPMMLDocumentsFromImports() {
    final WorkspaceProject workspaceProject = mock(WorkspaceProject.class);
    final PMMLIncludedModel includedModel1 = mock(PMMLIncludedModel.class);
    final PMMLIncludedModel includedModel2 = mock(PMMLIncludedModel.class);
    final PMMLIncludedModel includedModel3 = mock(PMMLIncludedModel.class);
    final Path path1 = mock(Path.class);
    final Path path2 = mock(Path.class);
    final Path path3 = mock(Path.class);
    final PMMLDocumentMetadata pmmlDocument1 = mock(PMMLDocumentMetadata.class);
    final PMMLDocumentMetadata pmmlDocument2 = mock(PMMLDocumentMetadata.class);
    final PMMLDocumentMetadata pmmlDocument3 = mock(PMMLDocumentMetadata.class);
    final List<PMMLIncludedModel> includedModels = asList(includedModel1, includedModel2, includedModel3);
    final List<Path> paths = asList(path1, path2, path3);
    when(pathsHelper.getPMMLModelsPaths(workspaceProject)).thenReturn(paths);
    when(includedDocumentsFilter.getDocumentFromImports(dmnModelPath, path1, includedModels)).thenReturn(pmmlDocument1);
    when(includedDocumentsFilter.getDocumentFromImports(dmnModelPath, path2, includedModels)).thenReturn(pmmlDocument2);
    when(includedDocumentsFilter.getDocumentFromImports(dmnModelPath, path3, includedModels)).thenReturn(pmmlDocument3);
    final List<PMMLDocumentMetadata> actualPMMLDocuments = service.loadPMMLDocumentsFromImports(dmnModelPath, workspaceProject, includedModels);
    final List<PMMLDocumentMetadata> expectedPMMLDocuments = asList(pmmlDocument1, pmmlDocument2, pmmlDocument3);
    assertEquals(expectedPMMLDocuments, actualPMMLDocuments);
}
Also used : PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Path(org.uberfire.backend.vfs.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Test(org.junit.Test)

Example 24 with PMMLDocumentMetadata

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

the class PMMLDocumentMetadataProvider method getPMMLDocumentModelParameterNames.

public List<String> getPMMLDocumentModelParameterNames(final String pmmlDocumentName, final String pmmlDocumentModelName) {
    final List<String> pmmlDocumentModelParameterNames = new ArrayList<>();
    if (pmmlDocuments.containsKey(pmmlDocumentName)) {
        final PMMLDocumentMetadata document = pmmlDocuments.get(pmmlDocumentName);
        document.getModels().stream().filter(model -> Objects.equals(pmmlDocumentModelName, model.getName())).findFirst().map(PMMLModelMetadata::getInputParameters).orElse(Collections.emptySet()).forEach(parameter -> pmmlDocumentModelParameterNames.add(parameter.getName()));
        pmmlDocumentModelParameterNames.sort(Comparator.naturalOrder());
    }
    return pmmlDocumentModelParameterNames;
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList) PMMLModelMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata)

Example 25 with PMMLDocumentMetadata

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

the class PMMLDocumentMetadataProvider method getPMMLDocumentModels.

public List<String> getPMMLDocumentModels(final String pmmlDocumentName) {
    final List<String> pmmlDocumentModelNames = new ArrayList<>();
    if (pmmlDocuments.containsKey(pmmlDocumentName)) {
        final PMMLDocumentMetadata document = pmmlDocuments.get(pmmlDocumentName);
        document.getModels().forEach(pmmlDocumentModel -> pmmlDocumentModelNames.add(pmmlDocumentModel.getName()));
        pmmlDocumentModelNames.sort(Comparator.naturalOrder());
    }
    return pmmlDocumentModelNames;
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList)

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