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());
}
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();
}
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);
}
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;
}
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;
}
Aggregations