Search in sources :

Example 1 with IncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.

the class DMNIncludedModelsServiceImplTest method testLoadModelsWhenWorkspaceProjectIsNotNull.

@Test
public void testLoadModelsWhenWorkspaceProjectIsNotNull() throws Exception {
    final WorkspaceProject workspaceProject = mock(WorkspaceProject.class);
    final Path rootPath = mock(Path.class);
    final String uri = "/src/path/file.dmn";
    final Path path1 = mock(Path.class);
    final Path path2 = mock(Path.class);
    final Path path3 = mock(Path.class);
    final IncludedModel includedModel1 = mock(IncludedModel.class);
    final IncludedModel includedModel2 = mock(IncludedModel.class);
    when(workspaceProject.getRootPath()).thenReturn(rootPath);
    when(rootPath.toURI()).thenReturn(uri);
    when(pathsHelper.getModelsPaths(workspaceProject)).thenReturn(asList(path1, path2, path3));
    when(includedModelFactory.create(dmnModelPath, path1)).thenReturn(includedModel1);
    when(includedModelFactory.create(dmnModelPath, path2)).thenReturn(includedModel2);
    when(includedModelFactory.create(dmnModelPath, path3)).thenThrow(new DMNIncludeModelCouldNotBeCreatedException());
    final List<IncludedModel> includedModels = service.loadModels(dmnModelPath, workspaceProject);
    assertEquals(2, includedModels.size());
    assertEquals(includedModel1, includedModels.get(0));
    assertEquals(includedModel2, includedModels.get(1));
}
Also used : Path(org.uberfire.backend.vfs.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) 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) DMNIncludeModelCouldNotBeCreatedException(org.kie.workbench.common.dmn.backend.editors.types.exceptions.DMNIncludeModelCouldNotBeCreatedException) Test(org.junit.Test)

Example 2 with IncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.

the class DMNIncludedModelsServiceImplTest method testLoadModelsWhenWorkspaceProjectIsNull.

@Test
public void testLoadModelsWhenWorkspaceProjectIsNull() throws Exception {
    final WorkspaceProject workspaceProject = null;
    final Path path1 = mock(Path.class);
    final Path path2 = mock(Path.class);
    final Path path3 = mock(Path.class);
    final IncludedModel includedModel1 = mock(IncludedModel.class);
    final IncludedModel includedModel2 = mock(IncludedModel.class);
    when(pathsHelper.getModelsPaths(workspaceProject)).thenReturn(asList(path1, path2, path3));
    when(includedModelFactory.create(dmnModelPath, path1)).thenReturn(includedModel1);
    when(includedModelFactory.create(dmnModelPath, path2)).thenReturn(includedModel2);
    when(includedModelFactory.create(dmnModelPath, path3)).thenThrow(new DMNIncludeModelCouldNotBeCreatedException());
    final List<IncludedModel> includedModels = service.loadModels(dmnModelPath, workspaceProject);
    assertEquals(2, includedModels.size());
    assertEquals(includedModel1, includedModels.get(0));
    assertEquals(includedModel2, includedModels.get(1));
}
Also used : Path(org.uberfire.backend.vfs.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) 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) DMNIncludeModelCouldNotBeCreatedException(org.kie.workbench.common.dmn.backend.editors.types.exceptions.DMNIncludeModelCouldNotBeCreatedException) Test(org.junit.Test)

Example 3 with IncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.

the class DMNIncludedNodeFactoryTest method testMakeDMNIncludeModel.

@Test
public void testMakeDMNIncludeModel() {
    final Path path = mock(Path.class);
    final IncludedModel includedModel = mock(IncludedModel.class);
    final String drgElementId = "0000-1111-3333-4444";
    final String drgElementName = "Can Drive?";
    final String expectedFileName = "file.dmn";
    final String expectedModelName = "model";
    final String expectedImportedElementId = "0000-1111-3333-4444";
    final String expectedImportedElementName = "model.Can Drive?";
    final String expectedImportedItemDefinitionName = "model.tCustomBoolean";
    final DRGElement importedElementId = makeDecision(drgElementId, drgElementName, "tCustomBoolean");
    when(path.getFileName()).thenReturn(expectedFileName);
    when(includedModel.getModelName()).thenReturn(expectedModelName);
    final DMNIncludedNode node = factory.makeDMNIncludeModel(path, includedModel, importedElementId);
    final Decision drgElement = (Decision) node.getDrgElement();
    assertEquals(expectedImportedElementId, drgElement.getId().getValue());
    assertEquals(expectedImportedElementName, drgElement.getName().getValue());
    assertEquals(expectedImportedItemDefinitionName, drgElement.getVariable().getTypeRef().getLocalPart());
    assertEquals(expectedFileName, node.getFileName());
    assertTrue(drgElement.isAllowOnlyVisualChange());
}
Also used : Path(org.uberfire.backend.vfs.Path) DMNIncludedNode(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 4 with IncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel 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());
}
Also used : PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Package(org.guvnor.common.services.project.model.Package) 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) Test(org.junit.Test)

Example 5 with IncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel 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)

Aggregations

IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)10 Test (org.junit.Test)9 DMNIncludedModel (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)7 PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)7 Path (org.uberfire.backend.vfs.Path)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)4 List (java.util.List)3 DMNIncludedNode (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode)3 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)2 Arrays.asList (java.util.Arrays.asList)2 Consumer (java.util.function.Consumer)2 Package (org.guvnor.common.services.project.model.Package)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 Import (org.kie.workbench.common.dmn.api.definition.model.Import)2 DMN (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.DMN)2 PMML (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.PMML)2 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)2