Search in sources :

Example 16 with PMMLDocumentMetadata

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());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 17 with PMMLDocumentMetadata

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();
    }));
}
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 18 with PMMLDocumentMetadata

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();
    });
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Mock(org.mockito.Mock) Promises(org.uberfire.client.promise.Promises) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) Promise(elemental2.promise.Promise) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) PMML(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.PMML) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) SyncPromises(org.uberfire.promise.SyncPromises) Mockito.doReturn(org.mockito.Mockito.doReturn) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Before(org.junit.Before) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) Mockito.never(org.mockito.Mockito.never) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Map(java.util.Map) Test(org.junit.Test)

Example 19 with PMMLDocumentMetadata

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<>());
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 20 with PMMLDocumentMetadata

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);
}
Also used : PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)

Aggregations

PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)30 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)10 PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)9 List (java.util.List)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)6 Path (org.uberfire.backend.vfs.Path)6 Objects (java.util.Objects)5 Optional (java.util.Optional)5 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)5 PMMLModelMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata)5 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)5 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)5 Definitions (org.kie.dmn.model.api.Definitions)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 Promise (elemental2.promise.Promise)3 Arrays.asList (java.util.Arrays.asList)3