Search in sources :

Example 1 with DMNIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord 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 2 with DMNIncludedModelActiveRecord

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

the class ImportFactoryTest method testName.

@Test
public void testName() {
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final Import import3 = mock(Import.class);
    final List<Import> imports = asList(import1, import2, import3);
    final DMNIncludedModelActiveRecord record = new DMNIncludedModelActiveRecord(null);
    when(import1.getName()).thenReturn(new Name("foo"));
    when(import2.getName()).thenReturn(new Name("bar"));
    when(import3.getName()).thenReturn(new Name("foo bar"));
    when(modelsIndex.getIndexedImports()).thenReturn(imports);
    record.setName("bla");
    final Name name = factory.name(record);
    final String expected = "bla";
    final String actual = name.getValue();
    assertEquals(expected, actual);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) 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 3 with DMNIncludedModelActiveRecord

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

the class IncludedModelModal method createIncludedModel.

BaseIncludedModelActiveRecord createIncludedModel(final Map<String, String> metaData) {
    final String importType = metaData.get(IMPORT_TYPE_METADATA);
    if (Objects.equals(DMNImportTypes.DMN, determineImportType(importType))) {
        final DMNIncludedModelActiveRecord dmnIncludedModel = new DMNIncludedModelActiveRecord(recordEngine);
        dmnIncludedModel.setDrgElementsCount(Integer.valueOf(metaData.get(DRG_ELEMENT_COUNT_METADATA)));
        dmnIncludedModel.setDataTypesCount(Integer.valueOf(metaData.get(ITEM_DEFINITION_COUNT_METADATA)));
        return dmnIncludedModel;
    } else if (Objects.equals(DMNImportTypes.PMML, determineImportType(importType))) {
        final PMMLIncludedModelActiveRecord pmmlIncludedModel = new PMMLIncludedModelActiveRecord(recordEngine);
        pmmlIncludedModel.setModelCount(Integer.valueOf(metaData.get(PMML_MODEL_COUNT_METADATA)));
        return pmmlIncludedModel;
    }
    return new DefaultIncludedModelActiveRecord(recordEngine);
}
Also used : DefaultIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)

Example 4 with DMNIncludedModelActiveRecord

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

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord 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)

Aggregations

DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)11 Test (org.junit.Test)7 Import (org.kie.workbench.common.dmn.api.definition.model.Import)5 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)5 ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 PMMLIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord)4 DefaultIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord)3 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)2 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)2 KieAssetsDropdownItem (org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem)2 Maps (org.kie.soup.commons.util.Maps)1 RefreshDecisionComponents (org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1