Search in sources :

Example 1 with PMMLIncludedModel

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

the class PMMLDocumentMetadataProviderTest method testLoadPMMLIncludedDocumentsPMMLIncludedModels.

@Test
@SuppressWarnings("unchecked")
public void testLoadPMMLIncludedDocumentsPMMLIncludedModels() {
    final Import dmn = new ImportDMN("dmn", new LocationURI("dmn-location"), DMNImportTypes.DMN.getDefaultNamespace());
    final Import pmml = new ImportPMML("pmml", new LocationURI("pmml-location"), DMNImportTypes.PMML.getDefaultNamespace());
    dmn.getName().setValue("dmn");
    pmml.getName().setValue("pmml");
    definitions.getImport().add(dmn);
    definitions.getImport().add(pmml);
    provider.loadPMMLIncludedDocuments();
    verify(clientServicesProxy).loadPMMLDocumentsFromImports(any(Path.class), pmmlIncludedModelsArgumentCaptor.capture(), any(ServiceCallback.class));
    final List<PMMLIncludedModel> actualIncludedModels = pmmlIncludedModelsArgumentCaptor.getValue();
    assertThat(actualIncludedModels).hasSize(1);
    final PMMLIncludedModel pmmlIncludedModel = actualIncludedModels.get(0);
    assertThat(pmmlIncludedModel.getModelName()).isEqualTo("pmml");
    assertThat(pmmlIncludedModel.getPath()).isEqualTo("pmml-location");
    assertThat(pmmlIncludedModel.getImportType()).isEqualTo(DMNImportTypes.PMML.getDefaultNamespace());
}
Also used : Path(org.uberfire.backend.vfs.Path) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Import(org.kie.workbench.common.dmn.api.definition.model.Import) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Example 2 with PMMLIncludedModel

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

the class PMMLIncludedDocumentFactoryTest method testGetDocumentByPathWithKnownPathWithIncludedModel.

@Test
public void testGetDocumentByPathWithKnownPathWithIncludedModel() {
    final Path path = mock(Path.class);
    final PMMLInfo<PMMLModelInfo> pmmlInfo = makePMMLInfo();
    final PMMLIncludedModel includedModel = makePMMLIncludedModel();
    when(path.toURI()).thenReturn(URI);
    doReturn(pmmlInfo).when(factory).loadPMMLInfo(path);
    final PMMLDocumentMetadata document = factory.getDocumentByPath(path, includedModel);
    assertThat(document).isNotNull();
    assertThat(document.getPath()).isEqualTo(URI);
    assertThat(document.getImportType()).isEqualTo(NAMESPACE);
    assertThat(document.getName()).isEqualTo(DOCUMENT_NAME);
    assertThat(document.getModels()).hasSize(1);
    final PMMLModelMetadata model = document.getModels().get(0);
    assertThat(model.getName()).isEqualTo(MODEL_NAME);
    assertThat(model.getInputParameters()).hasSize(INPUT_FIELDS_COUNT);
    assertThat(model.getInputParameters()).usingElementComparator(comparing(PMMLParameterMetadata::getName, naturalOrder())).containsExactlyInAnyOrder(expectedPMMLParameterMetadata());
}
Also used : Path(org.uberfire.backend.vfs.Path) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) PMMLParameterMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLParameterMetadata) PMMLModelInfo(org.kie.dmn.core.pmml.PMMLModelInfo) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) PMMLModelMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata) Test(org.junit.Test)

Example 3 with PMMLIncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel 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 4 with PMMLIncludedModel

use of org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel 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 5 with PMMLIncludedModel

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

PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)13 Test (org.junit.Test)11 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)8 Path (org.uberfire.backend.vfs.Path)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 DMNIncludedModel (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)2 IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)2 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)2 Promise (elemental2.promise.Promise)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Level (java.util.logging.Level)1