Search in sources :

Example 6 with ImportDMN

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

the class ImportConverterTest method wbFromDMN_DMNImport.

@Test
public void wbFromDMN_DMNImport() {
    when(jsitImportMock.getImportType()).thenReturn(DMN_IMPORT_TYPE);
    when(jsitDefinitionsMock.getDrgElement()).thenReturn(new ArrayList<>(Arrays.asList(mock(JSITDRGElement.class), mock(JSITDRGElement.class))));
    when(jsitDefinitionsMock.getItemDefinition()).thenReturn(new ArrayList<>(Arrays.asList(mock(JSITItemDefinition.class))));
    Import resultImport = ImportConverter.wbFromDMN(jsitImportMock, jsitDefinitionsMock, null);
    assertTrue(resultImport instanceof ImportDMN);
    assertEquals(NAMESPACE, resultImport.getNamespace());
    assertEquals(LOCATION_URI, resultImport.getLocationURI().getValue());
    assertEquals(DESCRIPTION, resultImport.getDescription().getValue());
    assertEquals(NAME, resultImport.getName().getValue());
    assertEquals(DMN_IMPORT_TYPE, resultImport.getImportType());
    assertEquals(2, ((ImportDMN) resultImport).getDrgElementsCount());
    assertEquals(1, ((ImportDMN) resultImport).getItemDefinitionsCount());
}
Also used : JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) Test(org.junit.Test)

Example 7 with ImportDMN

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

the class DMNMarshallerStandaloneTest method checkImports.

@SuppressWarnings("unchecked")
private void checkImports(final Graph<?, Node<?, ?>> graph) {
    assertNotNull(graph);
    final DMNDiagramUtils utils = new DMNDiagramUtils();
    final Diagram mockDiagram = mock(Diagram.class);
    when(mockDiagram.getGraph()).thenReturn(graph);
    final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = utils.getDefinitions(mockDiagram);
    final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = definitions.getImport();
    assertTrue(imports.get(0) instanceof ImportDMN);
    assertTrue(imports.get(1) instanceof ImportPMML);
    final ImportDMN dmnImport = (ImportDMN) imports.get(0);
    assertEquals("dmn-import", dmnImport.getName().getValue());
    assertEquals("https://kiegroup.org/dmn/_46EB0D0D-7241-4629-A38E-0377AA5B32D1", dmnImport.getNamespace());
    assertEquals(DMNImportTypes.DMN.getDefaultNamespace(), dmnImport.getImportType());
    final ImportPMML pmmlImport = (ImportPMML) imports.get(1);
    assertEquals("pmml-import", pmmlImport.getName().getValue());
    assertEquals("pmml-import", pmmlImport.getNamespace());
    assertEquals(DMNImportTypes.PMML.getDefaultNamespace(), pmmlImport.getImportType());
}
Also used : Import(org.kie.dmn.model.api.Import) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) DMNDiagramUtils(org.kie.workbench.common.dmn.api.graph.DMNDiagramUtils) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 8 with ImportDMN

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

the class IncludedModelsFactory method makeIncludedModel.

private BaseIncludedModelActiveRecord makeIncludedModel(final Import anImport) {
    BaseIncludedModelActiveRecord includedModel;
    if (anImport instanceof ImportDMN) {
        final DMNIncludedModelActiveRecord dmnIncludedModel = new DMNIncludedModelActiveRecord(getRecordEngine());
        dmnIncludedModel.setDataTypesCount(getDataTypesCount((ImportDMN) anImport));
        dmnIncludedModel.setDrgElementsCount(getDrgElementsCount((ImportDMN) anImport));
        includedModel = dmnIncludedModel;
    } else if (anImport instanceof ImportPMML) {
        final PMMLIncludedModelActiveRecord pmmlIncludedModel = new PMMLIncludedModelActiveRecord(getRecordEngine());
        pmmlIncludedModel.setModelCount(getPMMLModelCount((ImportPMML) anImport));
        includedModel = pmmlIncludedModel;
    } else {
        includedModel = new DefaultIncludedModelActiveRecord(getRecordEngine());
    }
    includedModel.setUuid(uuidWrapper());
    includedModel.setName(getName(anImport));
    includedModel.setNamespace(getNamespace(anImport));
    includedModel.setImportType(getImportType(anImport));
    includedModel.setPath(getPath(anImport));
    getIncludedModelsIndex().index(includedModel, anImport);
    return includedModel;
}
Also used : DefaultIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 9 with ImportDMN

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

the class ImportFactory method makeImport.

public Import makeImport(final BaseIncludedModelActiveRecord record) {
    Import anImport;
    if (record instanceof DMNIncludedModelActiveRecord) {
        final ImportDMN dmn = new ImportDMN();
        final DMNIncludedModelActiveRecord dmnRecord = (DMNIncludedModelActiveRecord) record;
        dmn.setName(name(record));
        dmn.setNamespace(record.getNamespace());
        dmn.setLocationURI(location(record));
        dmn.setImportType(record.getImportType());
        dmn.setDrgElementsCount(dmnRecord.getDrgElementsCount());
        dmn.setItemDefinitionsCount(dmnRecord.getDataTypesCount());
        anImport = dmn;
    } else if (record instanceof PMMLIncludedModelActiveRecord) {
        final ImportPMML pmml = new ImportPMML();
        final PMMLIncludedModelActiveRecord pmmlRecord = (PMMLIncludedModelActiveRecord) record;
        pmml.setName(name(record));
        pmml.setNamespace(name(record).getValue());
        pmml.setLocationURI(location(record));
        pmml.setImportType(record.getImportType());
        pmml.setModelCount(pmmlRecord.getModelCount());
        anImport = pmml;
    } else {
        anImport = new Import();
    }
    anImport.setLocationURI(location(record));
    anImport.setImportType(record.getImportType());
    return anImport;
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 10 with ImportDMN

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

the class DefinitionsConverterTest method wbFromDMN.

@Test
public void wbFromDMN() {
    final Import anImport = new TImport();
    anImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    final org.kie.dmn.model.api.Definitions definitions = mock(org.kie.dmn.model.api.Definitions.class);
    final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = new Maps.Builder<Import, org.kie.dmn.model.api.Definitions>().put(anImport, definitions).build();
    final Map<Import, PMMLDocumentMetadata> pmmlDocuments = new Maps.Builder<Import, PMMLDocumentMetadata>().build();
    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)));
    when(apiDefinitions.getImport()).thenReturn(singletonList(anImport));
    final Definitions wb = DefinitionsConverter.wbFromDMN(apiDefinitions, importDefinitions, pmmlDocuments);
    final String defaultNs = wb.getNsContext().get(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix());
    final String namespace = wb.getNamespace().getValue();
    final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = wb.getImport();
    assertEquals(defaultNs, namespace);
    assertEquals(1, imports.size());
    assertTrue(imports.get(0) instanceof ImportDMN);
    final ImportDMN importDMN = (ImportDMN) imports.get(0);
    assertEquals(2, importDMN.getDrgElementsCount());
    assertEquals(3, importDMN.getItemDefinitionsCount());
}
Also used : TImport(org.kie.dmn.model.v1_2.TImport) Import(org.kie.dmn.model.api.Import) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Maps(org.kie.soup.commons.util.Maps) 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