use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method getPMMLDocumentsAsync.
public Promise<Map<JSITImport, PMMLDocumentMetadata>> getPMMLDocumentsAsync(final Metadata metadata, final List<JSITImport> imports) {
if (!imports.isEmpty()) {
return loadPMMLDefinitions().then(otherDefinitions -> {
final Map<JSITImport, PMMLDocumentMetadata> importDefinitions = new HashMap<>();
for (final Map.Entry<String, PMMLDocumentMetadata> entry : otherDefinitions.entrySet()) {
final PMMLDocumentMetadata def = entry.getValue();
findImportByPMMLDocument(FileUtils.getFileName(def.getPath()), imports).ifPresent(anImport -> {
final JSITImport foundImported = Js.uncheckedCast(anImport);
importDefinitions.put(foundImported, def);
});
}
return promises.resolve(importDefinitions);
});
}
return promises.resolve(Collections.emptyMap());
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata 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.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelperTest method getPMMLDocumentsAsync.
@Test
public void getPMMLDocumentsAsync() {
final PMMLDocumentMetadata pmmlDocumentMetadata = new PMMLDocumentMetadata(PMML_PATH, PMML_FILE, PMML.getDefaultNamespace(), Collections.emptyList());
when(dmnImportsContentService.getModelsPMMLFilesURIs()).thenReturn(promises.resolve(new String[] { PMML_PATH }));
when(dmnImportsContentService.loadFile(PMML_PATH)).thenReturn(promises.resolve(PMML_CONTENT));
doReturn(promises.resolve(pmmlDocumentMetadata)).when(dmnImportsContentService).getPMMLDocumentMetadata(PMML_PATH);
final List<JSITImport> imports = new ArrayList<>();
final JSITImport jsImportMock = mock(JSITImport.class);
when(jsImportMock.getLocationURI()).thenReturn(PMML_FILE);
imports.add(jsImportMock);
final Promise<Map<JSITImport, PMMLDocumentMetadata>> returnPromise = importsHelper.getPMMLDocumentsAsync(metadataMock, imports);
returnPromise.then(def -> {
assertEquals(1, def.size());
assertEquals(PMML_PATH, def.get(jsImportMock).getPath());
assertEquals(PMML_FILE, def.get(jsImportMock).getName());
assertEquals(PMML.getDefaultNamespace(), def.get(jsImportMock).getImportType());
assertEquals(0, def.get(jsImportMock).getModels().size());
return promises.resolve();
}).catch_(i -> {
fail("Promise should've been resolved!");
return promises.resolve();
});
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class ImportConverterTest method setup.
@Before
public void setup() {
when(jsitImportMock.getLocationURI()).thenReturn(LOCATION_URI);
when(jsitImportMock.getNamespace()).thenReturn(NAMESPACE);
when(jsitImportMock.getName()).thenReturn(NAME);
when(jsitImportMock.getDescription()).thenReturn(DESCRIPTION);
pmmlDocumentMetadata = new PMMLDocumentMetadata("test.pmml", DMNImportTypes.PMML.toString(), new ArrayList<>());
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata 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