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());
}
}
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());
}
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());
}
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());
}
}
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());
}
Aggregations