Search in sources :

Example 1 with DMNIncludedModel

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));
}
Also used : ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) Test(org.junit.Test)

Example 2 with DMNIncludedModel

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);
}
Also used : WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) Test(org.junit.Test)

Example 3 with DMNIncludedModel

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();
    }));
}
Also used : JSITInvocable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocable) Arrays(java.util.Arrays) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) Promises(org.uberfire.client.promise.Promises) JSITInputData(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputData) BuiltInTypeUtils.isBuiltInType(org.kie.workbench.common.dmn.api.editors.types.BuiltInTypeUtils.isBuiltInType) HashMap(java.util.HashMap) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Promise(elemental2.promise.Promise) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) Js(jsinterop.base.Js) Map(java.util.Map) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) DMNMarshallerImportsHelper(org.kie.workbench.common.dmn.api.marshalling.DMNMarshallerImportsHelper) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) StringUtils.isEmpty(org.kie.workbench.common.stunner.core.util.StringUtils.isEmpty) DMNIncludedNode(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) FileUtils(org.kie.workbench.common.stunner.core.util.FileUtils) List(java.util.List) ImportedItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.client.marshaller.converters.ImportedItemDefinitionPropertyConverter) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) ImportedItemDefinitionPropertyConverter.withNamespace(org.kie.workbench.common.dmn.client.marshaller.converters.ImportedItemDefinitionPropertyConverter.withNamespace) Optional(java.util.Optional) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) QName(javax.xml.namespace.QName) Comparator(java.util.Comparator) Collections(java.util.Collections) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ArrayList(java.util.ArrayList) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)

Example 4 with DMNIncludedModel

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());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) Test(org.junit.Test)

Example 5 with DMNIncludedModel

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());
}
Also used : ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) Test(org.junit.Test)

Aggregations

DMNIncludedModel (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)11 Test (org.junit.Test)9 DMNIncludedNode (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)3 IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)3 PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)3 Path (org.uberfire.backend.vfs.Path)3 Promise (elemental2.promise.Promise)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2