Search in sources :

Example 1 with ImportDMN

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

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

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

the class ImportFactoryTest method testMakeDMNImport.

@Test
public void testMakeDMNImport() {
    final DMNIncludedModelActiveRecord record = new DMNIncludedModelActiveRecord(null);
    final String expectedImportType = DMNImportTypes.DMN.getDefaultNamespace();
    final String nameValue = "name";
    final String path = "/src/main/kie/dmn";
    final Name expectedName = new Name(nameValue);
    final LocationURI expectedLocationURI = new LocationURI(path);
    final String expectedNamespace = "://namespace";
    final int expectedDrgElementsCount = 2;
    final int expectedItemDefinitionsCount = 3;
    record.setName(nameValue);
    record.setPath(path);
    record.setNamespace(expectedNamespace);
    record.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    record.setDrgElementsCount(expectedDrgElementsCount);
    record.setDataTypesCount(expectedItemDefinitionsCount);
    final Import actualImport = factory.makeImport(record);
    assertTrue(actualImport instanceof ImportDMN);
    final ImportDMN dmnImport = (ImportDMN) actualImport;
    assertEquals(expectedImportType, actualImport.getImportType());
    assertEquals(expectedName, actualImport.getName());
    assertEquals(expectedLocationURI, actualImport.getLocationURI());
    assertEquals(expectedNamespace, actualImport.getNamespace());
    assertEquals(expectedImportType, actualImport.getImportType());
    assertEquals(expectedDrgElementsCount, dmnImport.getDrgElementsCount());
    assertEquals(expectedItemDefinitionsCount, dmnImport.getItemDefinitionsCount());
}
Also used : 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) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 4 with ImportDMN

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

the class ImportConverter method createWBImport.

private static Import createWBImport(final JSITImport dmn, final JSITDefinitions 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(countDefinitionElement(pmmlDocument, document -> document.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) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Function(java.util.function.Function) DMNImportTypes.determineImportType(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType) Objects(java.util.Objects) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Import(org.kie.workbench.common.dmn.api.definition.model.Import) 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) NameSpaceUtils(org.kie.workbench.common.dmn.client.marshaller.common.NameSpaceUtils) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) Map(java.util.Map) Optional(java.util.Optional) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) XMLConstants(javax.xml.XMLConstants) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) 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) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 5 with ImportDMN

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

the class ImportConverterTest method testWbFromDMNWhenDMNImport.

@Test
public void testWbFromDMNWhenDMNImport() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    final String key = "drools";
    final String value = "http://www.drools.org/kie/dmn/1.1";
    dmn.getNsContext().put(key, value);
    when(definitions.getDrgElement()).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class)));
    when(definitions.getItemDefinition()).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class)));
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    final Map<String, String> nsContext = anImport.getNsContext();
    assertEquals(1, nsContext.size());
    assertEquals(value, nsContext.get(key));
    assertTrue(anImport instanceof ImportDMN);
    final ImportDMN dmnImport = (ImportDMN) anImport;
    assertEquals(2, dmnImport.getDrgElementsCount());
    assertEquals(3, dmnImport.getItemDefinitionsCount());
}
Also used : ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) 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) Test(org.junit.Test)

Aggregations

ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)13 Test (org.junit.Test)8 Import (org.kie.workbench.common.dmn.api.definition.model.Import)8 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)7 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)5 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)4 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)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 Import (org.kie.dmn.model.api.Import)2 TImport (org.kie.dmn.model.v1_2.TImport)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 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2