Search in sources :

Example 6 with DMNDiagramElement

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;
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) JSIDMNDI(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDI) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Example 7 with DMNDiagramElement

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;
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) ArrayList(java.util.ArrayList) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName)

Example 8 with DMNDiagramElement

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());
}
Also used : DMNDiagramTuple(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 9 with DMNDiagramElement

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());
}
Also used : DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 10 with DMNDiagramElement

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);
}
Also used : Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Aggregations

DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)35 Test (org.junit.Test)23 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)21 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)13 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)10 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 Node (org.kie.workbench.common.stunner.core.graph.Node)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 DMNDiagramTuple (org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)5 DecisionNavigatorItem (org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem)4 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)3 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)3 JSONString (com.google.gwt.json.client.JSONString)2 QName (javax.xml.namespace.QName)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)2 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)2