use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.
the class DefinitionsConverter method dmnFromWB.
public static JSITDefinitions dmnFromWB(final Definitions wb, final boolean ignoreImportedItemDefinition) {
if (Objects.isNull(wb)) {
return null;
}
final JSITDefinitions result = new JSITDefinitions();
// TODO currently DMN wb UI does not offer feature to set these required DMN properties, setting some hardcoded defaults for now.
final String defaultId = Objects.nonNull(wb.getId()) ? wb.getId().getValue() : UUID.uuid();
final String defaultName = Objects.nonNull(wb.getName()) ? wb.getName().getValue() : UUID.uuid(8);
final JSIDMNDI dmnDMNDI = new JSIDMNDI();
final String defaultNamespace = !StringUtils.isEmpty(wb.getNamespace().getValue()) ? wb.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
result.setDMNDI(dmnDMNDI);
result.setId(defaultId);
result.setName(defaultName);
result.setNamespace(defaultNamespace);
final List<DMNDiagramElement> dmnDiagramElements = wb.getDiagramElements();
final List<JSIDMNDiagram> jsidmnDiagrams = getJSIDMNDiagrams(dmnDiagramElements);
dmnDMNDI.setDMNDiagram(jsidmnDiagrams);
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
description.ifPresent(result::setDescription);
final String typeLanguage = wb.getTypeLanguage();
final String expressionLanguage = ExpressionLanguagePropertyConverter.dmnFromWB(wb.getExpressionLanguage());
if (!StringUtils.isEmpty(typeLanguage)) {
result.setTypeLanguage(typeLanguage);
}
if (!StringUtils.isEmpty(expressionLanguage)) {
result.setExpressionLanguage(expressionLanguage);
}
final Map<QName, String> otherAttributes = new HashMap<>();
wb.getNsContext().forEach((k, v) -> {
// See https://github.com/highsource/jsonix/issues/227
if (!Objects.equals(k, DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
otherAttributes.put(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, k, XMLConstants.DEFAULT_NS_PREFIX), v);
}
});
result.setOtherAttributes(otherAttributes);
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getItemDefinition())) {
result.setItemDefinition(new ArrayList<>());
}
for (ItemDefinition itemDef : wb.getItemDefinition()) {
if (ignoreImportedItemDefinition) {
if (itemDef.isAllowOnlyVisualChange()) {
continue;
}
}
final JSITItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.dmnFromWB(itemDef);
result.addItemDefinition(itemDefConverted);
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getImport())) {
result.setImport(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getDrgElement())) {
result.setDrgElement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getArtifact())) {
result.setArtifact(new ArrayList<>());
}
for (Import i : wb.getImport()) {
final JSITImport importConverted = ImportConverter.dmnFromWb(i);
result.addImport(importConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.
the class DefinitionsConverter method getDMNDiagramElements.
private static List<DMNDiagramElement> getDMNDiagramElements(final JSITDefinitions definitions) {
final List<DMNDiagramElement> dmnDiagramElements = new ArrayList<>();
final List<JSIDMNDiagram> dmnDiagrams = definitions.getDMNDI().getDMNDiagram();
forEach(dmnDiagrams, dmnDiagram -> {
final Id id = new Id(dmnDiagram.getId());
dmnDiagramElements.add(new DMNDiagramElement(id, new Name(dmnDiagram.getName())));
});
return dmnDiagramElements;
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.
the class DRDContextMenuTest method testContextMenuHandler.
@Test
public void testContextMenuHandler() {
final DMNDiagramTuple diagramTuple1 = new DMNDiagramTuple(mock(Diagram.class), new DMNDiagramElement());
final DMNDiagramTuple diagramTuple2 = new DMNDiagramTuple(mock(Diagram.class), new DMNDiagramElement());
final List<DMNDiagramTuple> diagrams = asList(diagramTuple1, diagramTuple2);
final DMNDiagramElement diagramElement = mock(DMNDiagramElement.class);
when(translationService.getValue(Mockito.<String>any())).thenReturn(StringUtils.EMPTY);
when(drdContextMenuService.getDiagrams()).thenReturn(diagrams);
when(dmnDiagramsSession.getDRGDiagramElement()).thenReturn(diagramElement);
when(dmnDiagramsSession.getCurrentDMNDiagramElement()).thenReturn(Optional.of(diagramElement));
drdContextMenu.setDRDContextMenuHandler(contextMenu, Collections.singletonList(node));
verify(contextMenu).setHeaderMenu(any(), any());
verify(contextMenu, times(4)).addTextMenuItem(any(), anyBoolean(), any());
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.
the class DMNDiagramsSessionTest method testGetCurrentDiagram.
@Test
public void testGetCurrentDiagram() {
final DMNDiagramElement diagramElement = new DMNDiagramElement();
final Diagram stunnerDiagram = mock(Diagram.class);
final DMNDiagramSelected selectedDiagram = new DMNDiagramSelected(diagramElement);
dmnDiagramsSession.add(diagramElement, stunnerDiagram);
dmnDiagramsSession.onDMNDiagramSelected(selectedDiagram);
final Optional<Diagram> currentDiagram = dmnDiagramsSession.getCurrentDiagram();
assertTrue(currentDiagram.isPresent());
assertEquals(stunnerDiagram, currentDiagram.get());
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.
the class DMNDiagramsSessionTest method testGetCurrentDiagramId.
@Test
public void testGetCurrentDiagramId() {
final DMNDiagramElement diagramElement = mock(DMNDiagramElement.class);
final Diagram stunnerDiagram = mock(Diagram.class);
final DMNDiagramSelected selectedDiagram = new DMNDiagramSelected(diagramElement);
final Id id = mock(Id.class);
final String expectedId = "value";
when(id.getValue()).thenReturn(expectedId);
when(diagramElement.getId()).thenReturn(id);
dmnDiagramsSession.add(diagramElement, stunnerDiagram);
dmnDiagramsSession.onDMNDiagramSelected(selectedDiagram);
final String actualId = dmnDiagramsSession.getCurrentDiagramId();
assertEquals(expectedId, actualId);
}
Aggregations