use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class DefinitionsConverter method wbFromDMN.
public static Definitions wbFromDMN(final JSITDefinitions dmn, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
if (Objects.isNull(dmn)) {
return null;
}
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Name name = new Name(dmn.getName());
final String namespace = dmn.getNamespace();
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final Definitions result = new Definitions();
result.setId(id);
result.setName(name);
result.setNamespace(new Text(namespace));
result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace);
result.setExpressionLanguage(ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage()));
result.setTypeLanguage(dmn.getTypeLanguage());
result.setDmnDiagramElements(getDMNDiagramElements(dmn));
result.setDescription(description);
final Map<String, String> namespaces = NameSpaceUtils.extractNamespacesKeyedByPrefix(dmn);
for (Entry<String, String> kv : namespaces.entrySet()) {
String mappedURI = kv.getValue();
switch(mappedURI) {
case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN:
mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN;
break;
case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL:
mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL;
break;
case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE:
mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE;
break;
}
if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
result.getNsContext().putIfAbsent(kv.getKey(), mappedURI);
} else {
result.getNsContext().put(kv.getKey(), mappedURI);
}
}
final List<JSITItemDefinition> jsiItemDefinitions = dmn.getItemDefinition();
for (int i = 0; i < jsiItemDefinitions.size(); i++) {
final JSITItemDefinition jsiItemDefinition = Js.uncheckedCast(jsiItemDefinitions.get(i));
final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(jsiItemDefinition);
if (Objects.nonNull(itemDefConverted)) {
itemDefConverted.setParent(result);
result.getItemDefinition().add(itemDefConverted);
}
}
final List<JSITImport> jsiImports = dmn.getImport();
for (int i = 0; i < jsiImports.size(); i++) {
final JSITImport jsiImport = Js.uncheckedCast(jsiImports.get(i));
final JSITDefinitions definitions = Js.uncheckedCast(importDefinitions.get(jsiImport));
final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(jsiImport);
final Import importConverted = ImportConverter.wbFromDMN(jsiImport, definitions, pmmlDocument);
if (Objects.nonNull(importConverted)) {
importConverted.setParent(result);
result.getImport().add(importConverted);
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata 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.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsHelperStandaloneImplTest method testGetPMMLDocuments.
@Test
public void testGetPMMLDocuments() {
final Path dmnModelPath = mock(Path.class);
final Metadata metadata = mock(Metadata.class);
final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
final Import import1 = mock(Import.class);
final List<Import> imports = singletonList(import1);
final Path path1 = mock(Path.class);
final Path path2 = mock(Path.class);
final List<Path> paths = asList(path1, path2);
when(metadata.getPath()).thenReturn(dmnModelPath);
when(import1.getLocationURI()).thenReturn("document1.pmml");
when(pathsHelper.getRelativeURI(dmnModelPath, path1)).thenReturn("document1.pmml");
when(pathsHelper.getRelativeURI(dmnModelPath, path2)).thenReturn("document2.pmml");
when(pmmlDocumentFactory.getDocumentByPath(path1)).thenReturn(pmmlDocument);
doReturn(paths).when(helper).getPMMLDocumentPaths(metadata);
final Map<Import, PMMLDocumentMetadata> importDefinitions = helper.getPMMLDocuments(metadata, imports);
assertEquals(1, importDefinitions.size());
assertEquals(pmmlDocument, importDefinitions.get(import1));
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class ImportConverterTest method testWbFromDMNWhenGeneric.
@Test
public void testWbFromDMNWhenGeneric() {
final org.kie.dmn.model.api.Import dmn = new TImport();
dmn.setImportType("cheese");
final Definitions definitions = mock(Definitions.class);
final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
assertNotNull(anImport);
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata 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