use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class WrapperUtils method getDmnElementRef.
static QName getDmnElementRef(final Definitions definitions, final View<? extends DMNElement> v, final String namespaceURI) {
final DMNElement dmnElement = v.getDefinition();
final String dmnElementId = dmnElement.getId().getValue();
return getImportPrefix(definitions, dmnElement).map(prefix -> new QName(namespaceURI, prefix + ":" + dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)).orElse(new QName(namespaceURI, dmnElementId, XMLConstants.DEFAULT_NS_PREFIX));
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class HrefBuilderTest method testGetHrefForImportedDRGElementWhenImportHasAnOddName.
@Test
public void testGetHrefForImportedDRGElementWhenImportHasAnOddName() {
final DRGElement drgElement = mock(DRGElement.class);
final Name drgElementName = mock(Name.class);
final Name importName = mock(Name.class);
final Id id = mock(Id.class);
final Definitions definitions = mock(Definitions.class);
final Import anImport = mock(Import.class);
final List<Import> imports = singletonList(anImport);
final String includedModelName = "d.i.v.i.";
when(importName.getValue()).thenReturn(includedModelName);
when(anImport.getName()).thenReturn(importName);
when(anImport.getNamespace()).thenReturn("https://github.com/kiegroup/dmn/something");
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(imports);
final String actual = HrefBuilder.getHref(drgElement);
final String expected = "https://github.com/kiegroup/dmn/something#0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class HrefBuilderTest method testGetHref.
@Test
public void testGetHref() {
final DRGElement drgElement = mock(DRGElement.class);
final Name name = mock(Name.class);
final Id id = mock(Id.class);
final Definitions definitions = mock(Definitions.class);
final String uuid = "0000-1111-2222";
when(id.getValue()).thenReturn(uuid);
when(name.getValue()).thenReturn("Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(name);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(Collections.emptyList());
final String actual = HrefBuilder.getHref(drgElement);
final String expected = "#" + uuid;
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNDiagramFactoryImplTest method testDefaultNameSpaces.
@Test
@SuppressWarnings("unchecked")
public void testDefaultNameSpaces() {
final Diagram diagram = factory.build(NAME, metadata, graph);
// We can safely get the first object on the iterator as we know the graph only contains one node
final Node<View, Edge> root = (Node<View, Edge>) diagram.getGraph().nodes().iterator().next();
final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(root);
final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
final Map<String, String> dmnDefaultNameSpaces = dmnDefinitions.getNsContext();
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.FEEL.getPrefix()));
assertEquals(DMNModelInstrumentedBase.Namespace.FEEL.getUri(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.FEEL.getPrefix()));
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.DMN.getPrefix()));
assertEquals(DMNModelInstrumentedBase.Namespace.DMN.getUri(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.DMN.getPrefix()));
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.KIE.getPrefix()));
assertEquals(DMNModelInstrumentedBase.Namespace.KIE.getUri(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.KIE.getPrefix()));
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix()));
assertEquals(dmnDefinitions.getNamespace().getValue(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix()));
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.DMNDI.getPrefix()));
assertEquals(DMNModelInstrumentedBase.Namespace.DMNDI.getUri(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.DMNDI.getPrefix()));
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.DI.getPrefix()));
assertEquals(DMNModelInstrumentedBase.Namespace.DI.getUri(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.DI.getPrefix()));
assertTrue(dmnDefaultNameSpaces.containsKey(DMNModelInstrumentedBase.Namespace.DC.getPrefix()));
assertEquals(DMNModelInstrumentedBase.Namespace.DC.getUri(), dmnDefaultNameSpaces.get(DMNModelInstrumentedBase.Namespace.DC.getPrefix()));
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method getImportedItemDefinitionsByNamespaceAsync.
public void getImportedItemDefinitionsByNamespaceAsync(final String modelName, final String namespace, final ServiceCallback<List<ItemDefinition>> callback) {
loadDMNDefinitions().then(definitions -> {
final List<ItemDefinition> result = new ArrayList<>();
for (final Map.Entry<String, JSITDefinitions> entry : definitions.entrySet()) {
final JSITDefinitions definition = Js.uncheckedCast(entry.getValue());
if (Objects.equals(definition.getNamespace(), namespace)) {
final List<JSITItemDefinition> items = definition.getItemDefinition();
for (int j = 0; j < items.size(); j++) {
final JSITItemDefinition jsitItemDefinition = Js.uncheckedCast(items.get(j));
final ItemDefinition converted = ImportedItemDefinitionPropertyConverter.wbFromDMN(jsitItemDefinition, modelName);
result.add(converted);
}
}
}
result.sort(Comparator.comparing(o -> o.getName().getValue()));
callback.onSuccess(result);
return promises.resolve(result);
});
}
Aggregations