Search in sources :

Example 1 with ImportPMML

use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML in project kie-wb-common by kiegroup.

the class ImportConverter method createWBImport.

private static Import createWBImport(final org.kie.dmn.model.api.Import dmn, final Definitions definitions, final PMMLDocumentMetadata pmmlDocument) {
    final LocationURI locationURI = new LocationURI(dmn.getLocationURI());
    if (Objects.equals(DMNImportTypes.DMN, determineImportType(dmn.getImportType()))) {
        final ImportDMN result = new ImportDMN(dmn.getNamespace(), locationURI, dmn.getImportType());
        result.setDrgElementsCount(countDefinitionElement(definitions, () -> d -> d.getDrgElement().size()));
        result.setItemDefinitionsCount(countDefinitionElement(definitions, () -> d -> d.getItemDefinition().size()));
        return result;
    } else if (Objects.equals(DMNImportTypes.PMML, determineImportType(dmn.getImportType()))) {
        final ImportPMML result = new ImportPMML(dmn.getNamespace(), locationURI, dmn.getImportType());
        result.setModelCount(pmmlDocument.getModels().size());
        return result;
    } else {
        return new Import(dmn.getNamespace(), locationURI, dmn.getImportType());
    }
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) HashMap(java.util.HashMap) UUID(java.util.UUID) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Definitions(org.kie.dmn.model.api.Definitions) DMNImportTypes.determineImportType(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType) Objects(java.util.Objects) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) Map(java.util.Map) Optional(java.util.Optional) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Import(org.kie.workbench.common.dmn.api.definition.model.Import) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 2 with ImportPMML

use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML in project kie-wb-common by kiegroup.

the class ImportConverterTest method testWbFromDMNWhenPMMLImport.

@Test
public void testWbFromDMNWhenPMMLImport() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType(DMNImportTypes.PMML.getDefaultNamespace());
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    when(pmmlDocument.getModels()).thenReturn(asList(mock(PMMLModelMetadata.class), mock(PMMLModelMetadata.class)));
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    assertTrue(anImport instanceof ImportPMML);
    final ImportPMML pmmlImport = (ImportPMML) anImport;
    assertEquals(2, pmmlImport.getModelCount());
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.dmn.model.api.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Example 3 with ImportPMML

use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML 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 4 with ImportPMML

use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML in project kie-wb-common by kiegroup.

the class ImportConverterTest method wbFromDMN_PMMLImportNoModels.

@Test
public void wbFromDMN_PMMLImportNoModels() {
    when(jsitImportMock.getImportType()).thenReturn(PMML_IMPORT_TYPE);
    Import resultImport = ImportConverter.wbFromDMN(jsitImportMock, null, pmmlDocumentMetadata);
    assertTrue(resultImport instanceof ImportPMML);
    assertEquals(LOCATION_URI, resultImport.getLocationURI().getValue());
    assertEquals(NAME, resultImport.getNamespace());
    assertEquals(DESCRIPTION, resultImport.getDescription().getValue());
    assertEquals(NAME, resultImport.getName().getValue());
    assertEquals(PMML_IMPORT_TYPE, resultImport.getImportType());
    assertNotNull(resultImport.getId().getValue());
    assertEquals(0, ((ImportPMML) resultImport).getModelCount());
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Example 5 with ImportPMML

use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML in project kie-wb-common by kiegroup.

the class IncludedModelsFactoryTest method testMakeIncludedPMMLModels.

@Test
public void testMakeIncludedPMMLModels() {
    final ImportPMML import1 = mock(ImportPMML.class);
    final ImportPMML import2 = mock(ImportPMML.class);
    final Name nameMock1 = mock(Name.class);
    final Name nameMock2 = mock(Name.class);
    final List<Import> imports = asList(import1, import2);
    final String name1 = "name1";
    final String name2 = "name2";
    final String path1 = "path1";
    final String path2 = "path2";
    final String uuid1 = "123";
    final String uuid2 = "456";
    final String[] uuids = { uuid1, uuid2 };
    final String uri1 = "/src/main/kie/dmn/1";
    final String uri2 = "/src/main/kie/dmn/2";
    final Integer modelCount1 = 2;
    final Integer modelCount2 = 8;
    when(nameMock1.getValue()).thenReturn(name1);
    when(nameMock2.getValue()).thenReturn(name2);
    when(import1.getName()).thenReturn(nameMock1);
    when(import2.getName()).thenReturn(nameMock2);
    when(import1.getNamespace()).thenReturn(path1);
    when(import2.getNamespace()).thenReturn(path2);
    when(import1.getImportType()).thenReturn(DMNImportTypes.PMML.getDefaultNamespace());
    when(import2.getImportType()).thenReturn(DMNImportTypes.PMML.getDefaultNamespace());
    when(import1.getLocationURI()).thenReturn(new LocationURI(uri1));
    when(import2.getLocationURI()).thenReturn(new LocationURI(uri2));
    when(import1.getModelCount()).thenReturn(modelCount1);
    when(import2.getModelCount()).thenReturn(modelCount2);
    doAnswer(new Answer() {

        private int count = 0;

        public Object answer(InvocationOnMock invocation) {
            return uuids[count++];
        }
    }).when(factory).uuidWrapper();
    final List<BaseIncludedModelActiveRecord> includedModels = factory.makeIncludedModels(imports);
    final BaseIncludedModelActiveRecord includedModel1 = includedModels.get(0);
    final BaseIncludedModelActiveRecord includedModel2 = includedModels.get(1);
    verify(includedModelsIndex).clear();
    verify(includedModelsIndex).index(includedModel1, import1);
    verify(includedModelsIndex).index(includedModel2, import2);
    assertEquals(2, includedModels.size());
    assertEquals(uuid1, includedModel1.getUUID());
    assertEquals(uuid2, includedModel2.getUUID());
    assertEquals(name1, includedModel1.getName());
    assertEquals(name2, includedModel2.getName());
    assertEquals(path1, includedModel1.getNamespace());
    assertEquals(path2, includedModel2.getNamespace());
    assertEquals(uri1, includedModel1.getPath());
    assertEquals(uri2, includedModel2.getPath());
    assertTrue(includedModel1 instanceof PMMLIncludedModelActiveRecord);
    assertTrue(includedModel2 instanceof PMMLIncludedModelActiveRecord);
    assertEquals(modelCount1, ((PMMLIncludedModelActiveRecord) includedModel1).getModelCount());
    assertEquals(modelCount2, ((PMMLIncludedModelActiveRecord) includedModel2).getModelCount());
    assertEquals(recordEngine, includedModel1.getRecordEngine());
    assertEquals(recordEngine, includedModel2.getRecordEngine());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Import(org.kie.workbench.common.dmn.api.definition.model.Import) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Aggregations

ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)13 Import (org.kie.workbench.common.dmn.api.definition.model.Import)9 Test (org.junit.Test)8 ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)7 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 PMMLIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord)4 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)4 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Definitions (org.kie.dmn.model.api.Definitions)2 DMNImportTypes (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes)2 DMNImportTypes.determineImportType (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType)2 PMMLModelMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLModelMetadata)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)2