use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel in project kie-wb-common by kiegroup.
the class PMMLDocumentMetadataProviderTest method testLoadPMMLIncludedDocumentsPMMLIncludedModels.
@Test
@SuppressWarnings("unchecked")
public void testLoadPMMLIncludedDocumentsPMMLIncludedModels() {
final Import dmn = new ImportDMN("dmn", new LocationURI("dmn-location"), DMNImportTypes.DMN.getDefaultNamespace());
final Import pmml = new ImportPMML("pmml", new LocationURI("pmml-location"), DMNImportTypes.PMML.getDefaultNamespace());
dmn.getName().setValue("dmn");
pmml.getName().setValue("pmml");
definitions.getImport().add(dmn);
definitions.getImport().add(pmml);
provider.loadPMMLIncludedDocuments();
verify(clientServicesProxy).loadPMMLDocumentsFromImports(any(Path.class), pmmlIncludedModelsArgumentCaptor.capture(), any(ServiceCallback.class));
final List<PMMLIncludedModel> actualIncludedModels = pmmlIncludedModelsArgumentCaptor.getValue();
assertThat(actualIncludedModels).hasSize(1);
final PMMLIncludedModel pmmlIncludedModel = actualIncludedModels.get(0);
assertThat(pmmlIncludedModel.getModelName()).isEqualTo("pmml");
assertThat(pmmlIncludedModel.getPath()).isEqualTo("pmml-location");
assertThat(pmmlIncludedModel.getImportType()).isEqualTo(DMNImportTypes.PMML.getDefaultNamespace());
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel in project kie-wb-common by kiegroup.
the class PMMLIncludedDocumentFactoryTest method testGetDocumentByPathWithKnownPathWithIncludedModel.
@Test
public void testGetDocumentByPathWithKnownPathWithIncludedModel() {
final Path path = mock(Path.class);
final PMMLInfo<PMMLModelInfo> pmmlInfo = makePMMLInfo();
final PMMLIncludedModel includedModel = makePMMLIncludedModel();
when(path.toURI()).thenReturn(URI);
doReturn(pmmlInfo).when(factory).loadPMMLInfo(path);
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()).hasSize(1);
final PMMLModelMetadata model = document.getModels().get(0);
assertThat(model.getName()).isEqualTo(MODEL_NAME);
assertThat(model.getInputParameters()).hasSize(INPUT_FIELDS_COUNT);
assertThat(model.getInputParameters()).usingElementComparator(comparing(PMMLParameterMetadata::getName, naturalOrder())).containsExactlyInAnyOrder(expectedPMMLParameterMetadata());
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel in project kie-wb-common by kiegroup.
the class IncludedModelFactoryTest method testCreatePMML.
@Test
public void testCreatePMML() throws Exception {
final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
final Package aPackage = mock(Package.class);
final String packageName = "com.kie.pmml";
final String fileName = "file.pmml";
final String uri = "/src/main/java/com/kie/pmml/file.pmml";
final Integer expectedModelsCount = 2;
when(aPackage.getPackageName()).thenReturn(packageName);
when(includedModelPath.getFileName()).thenReturn(fileName);
when(moduleService.resolvePackage(includedModelPath)).thenReturn(aPackage);
when(importTypesHelper.isDMN(includedModelPath)).thenReturn(false);
when(importTypesHelper.isPMML(includedModelPath)).thenReturn(true);
when(pathsHelper.getRelativeURI(dmnModelPath, includedModelPath)).thenReturn(uri);
when(pmmlDocumentFactory.getDocumentByPath(includedModelPath)).thenReturn(pmmlDocument);
when(pmmlDocument.getModels()).thenReturn(asList(mock(PMMLModelMetadata.class), mock(PMMLModelMetadata.class)));
final IncludedModel includedModel = factory.create(dmnModelPath, includedModelPath);
assertTrue(includedModel instanceof PMMLIncludedModel);
final PMMLIncludedModel pmmlIncludedModel = (PMMLIncludedModel) includedModel;
assertEquals(packageName, includedModel.getModelPackage());
assertEquals(fileName, includedModel.getModelName());
assertEquals(uri, includedModel.getPath());
assertEquals(expectedModelsCount, pmmlIncludedModel.getModelCount());
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method loadModels.
public void loadModels(final ServiceCallback<List<IncludedModel>> callback) {
final List<IncludedModel> models = new ArrayList<>();
dmnImportsContentService.getModelsURIs().then(items -> promises.all(Arrays.asList(items), file -> {
final String fileName = FileUtils.getFileName(file);
if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) {
return dmnImportsContentService.loadFile(file).then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() {
@Override
public void onSuccess(final Definitions definitions) {
final String modelPackage = "";
final String namespace = definitions.getNamespace().getValue();
final String importType = DMNImportTypes.DMN.getDefaultNamespace();
final int drgElementCount = definitions.getDrgElement().size();
final int itemDefinitionCount = definitions.getItemDefinition().size();
models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount));
success.onInvoke(promises.resolve());
}
@Override
public void onError(final ClientRuntimeError error) {
// Swallow. Since it must try to load other paths.
success.onInvoke(promises.resolve());
}
})));
}
if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) {
return dmnImportsContentService.getPMMLDocumentMetadata(file).then(pmmlDocumentMetadata -> {
int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0;
models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount));
return promises.resolve();
});
}
return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported");
}).then(v -> {
callback.onSuccess(models);
return promises.resolve();
}));
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel in project kie-wb-common by kiegroup.
the class IncludedModelFactory method makePMMLIncludedModel.
private IncludedModel makePMMLIncludedModel(final Path dmnModelPath, final Path includedModelPath) {
final String fileName = includedModelPath.getFileName();
final String modelPackage = getPackage(includedModelPath);
final String relativeURI = pathsHelper.getRelativeURI(dmnModelPath, includedModelPath);
final PMMLDocumentMetadata document = pmmlDocumentFactory.getDocumentByPath(includedModelPath);
final String importType = document.getImportType();
final int modelCount = document.getModels().size();
return new PMMLIncludedModel(fileName, modelPackage, relativeURI, importType, modelCount);
}
Aggregations