use of org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel in project kie-wb-common by kiegroup.
the class DMNIncludeModelsClientTest method testLoadNodesFromImports.
@Test
@SuppressWarnings("unchecked")
public void testLoadNodesFromImports() {
final DMNIncludedModel includedModel1 = mock(DMNIncludedModel.class);
final DMNIncludedModel includedModel2 = mock(DMNIncludedModel.class);
final List<DMNIncludedModel> imports = asList(includedModel1, includedModel2);
client.loadNodesFromImports(imports, listConsumerDMNNodes);
verify(service).loadNodesFromImports(eq(imports), any(ServiceCallback.class));
}
use of org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel in project kie-wb-common by kiegroup.
the class DMNClientServicesProxyImplTest method testLoadNodesFromImports.
@Test
@SuppressWarnings("unchecked")
public void testLoadNodesFromImports() {
final Optional<WorkspaceProject> optionalWorkspaceProject = Optional.of(workspaceProject);
final DMNIncludedModel includedModel1 = mock(DMNIncludedModel.class);
final DMNIncludedModel includedModel2 = mock(DMNIncludedModel.class);
final List<DMNIncludedModel> imports = asList(includedModel1, includedModel2);
when(projectContext.getActiveWorkspaceProject()).thenReturn(optionalWorkspaceProject);
clientServicesProxy.loadNodesFromImports(imports, serviceCallback);
verify(includedModelsService).loadNodesFromImports(workspaceProject, imports);
}
use of org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel 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.DMNIncludedModel in project kie-wb-common by kiegroup.
the class DecisionComponentsTest method testAsDMNIncludedModel.
@Test
public void testAsDMNIncludedModel() {
final String modelName = "Model Name";
final String namespace = "The Namespace";
final String type = "The type";
final String file = "my file.dmn";
final String filePath = "//users//some//" + file;
final Import anImport = new Import();
anImport.setName(new Name(modelName));
anImport.setNamespace(namespace);
anImport.setImportType(type);
anImport.setLocationURI(new LocationURI(filePath));
final DMNIncludedModel includedModel = decisionComponents.asDMNIncludedModel(anImport);
assertEquals(modelName, includedModel.getModelName());
assertEquals(namespace, includedModel.getNamespace());
assertEquals(type, includedModel.getImportType());
assertEquals(file, includedModel.getPath());
}
use of org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel in project kie-wb-common by kiegroup.
the class DecisionComponentsTest method testGetDMNIncludedModelsOnlyIncludesDMN.
@Test
public void testGetDMNIncludedModelsOnlyIncludesDMN() {
final ImportDMN dmnImport = new ImportDMN();
final ImportPMML pmmlImport = new ImportPMML();
dmnImport.getName().setValue("dmn");
dmnImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
pmmlImport.setImportType(DMNImportTypes.PMML.getDefaultNamespace());
when(dmnDiagramsSession.getModelImports()).thenReturn(asList(dmnImport, pmmlImport));
final List<DMNIncludedModel> includedModels = decisionComponents.getDMNIncludedModels();
assertThat(includedModels).hasSize(1);
assertThat(includedModels.get(0).getModelName()).isEqualTo("dmn");
assertThat(includedModels.get(0).getImportType()).isEqualTo(DMNImportTypes.DMN.getDefaultNamespace());
}
Aggregations