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 org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) {
if (dmn == null) {
return null;
}
final Id id = new Id(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.setDescription(description);
for (Entry<String, String> kv : dmn.getNsContext().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);
}
}
for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) {
final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef);
if (itemDefConverted != null) {
itemDefConverted.setParent(result);
}
result.getItemDefinition().add(itemDefConverted);
}
for (org.kie.dmn.model.api.Import i : dmn.getImport()) {
final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i);
final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i);
final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument);
if (importConverted != null) {
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 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.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class DMNContentServiceImplTest method testLoadPMMLDocumentMetadata.
@Test
public void testLoadPMMLDocumentMetadata() {
final PMMLDocumentMetadata expected = mock(PMMLDocumentMetadata.class);
when(pmmlIncludedDocumentFactory.getDocumentByPath(path)).thenReturn(expected);
final PMMLDocumentMetadata actual = service.loadPMMLDocumentMetadata(path);
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class PMMLDocumentMetadataProviderTest method testGetPMMLDocumentNames.
@Test
public void testGetPMMLDocumentNames() {
final List<PMMLDocumentMetadata> pmmlDocuments = new ArrayList<>();
pmmlDocuments.add(new PMMLDocumentMetadata("path1", "zDocument1", DMNImportTypes.PMML.getDefaultNamespace(), Collections.emptyList()));
pmmlDocuments.add(new PMMLDocumentMetadata("path2", "aDocument2", DMNImportTypes.PMML.getDefaultNamespace(), Collections.emptyList()));
final ServiceCallback<List<PMMLDocumentMetadata>> callback = loadPMMLIncludedDocuments();
callback.onSuccess(pmmlDocuments);
final List<String> documentNames = provider.getPMMLDocumentNames();
assertThat(documentNames).containsSequence("aDocument2", "zDocument1");
}
use of org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata in project kie-wb-common by kiegroup.
the class PMMLDocumentMetadataProviderTest method testGetPMMLDocumentModelNames.
@Test
public void testGetPMMLDocumentModelNames() {
final List<PMMLDocumentMetadata> pmmlDocuments = new ArrayList<>();
pmmlDocuments.add(new PMMLDocumentMetadata("path", "document", DMNImportTypes.PMML.getDefaultNamespace(), asList(new PMMLModelMetadata("zModel1", Collections.emptySet()), new PMMLModelMetadata("aModel2", Collections.emptySet()))));
final ServiceCallback<List<PMMLDocumentMetadata>> callback = loadPMMLIncludedDocuments();
callback.onSuccess(pmmlDocuments);
final List<String> modelNames = provider.getPMMLDocumentModels("document");
assertThat(modelNames).containsSequence("aModel2", "zModel1");
assertThat(provider.getPMMLDocumentModels("unknown")).isEmpty();
}
Aggregations