Search in sources :

Example 11 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class IdUtilsTest method testGetEdgeId.

@Test
public void testGetEdgeId() {
    String dmnElementId = "_1111-2222";
    String uniqueId = "dmnedge-drg-" + dmnElementId;
    final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
    when(diagram.getName()).thenReturn("DRG");
    final String result1 = getEdgeId(diagram, list(), dmnElementId, false, false);
    String expected1 = uniqueId;
    assertEquals(expected1, result1);
    final String result2 = getEdgeId(diagram, list(), dmnElementId, true, false);
    String expected2 = uniqueId + AUTO_SOURCE_CONNECTION;
    assertEquals(expected2, result2);
    final String result3 = getEdgeId(diagram, list(), dmnElementId, false, true);
    String expected3 = uniqueId + AUTO_TARGET_CONNECTION;
    assertEquals(expected3, result3);
    final String result4 = getEdgeId(diagram, list(), dmnElementId, true, true);
    String expected4 = uniqueId + AUTO_SOURCE_CONNECTION + AUTO_TARGET_CONNECTION;
    assertEquals(expected4, result4);
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Test(org.junit.Test)

Example 12 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class IdUtilsTest method testGetShapeId.

@Test
public void testGetShapeId() {
    final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
    when(diagram.getName()).thenReturn("DRG");
    assertEquals("dmnshape-drg-_1111-2222", getShapeId(diagram, list(), "_1111-2222"));
    assertEquals("dmnshape-drg-2-_1111-2222", getShapeId(diagram, list("dmnshape-drg-_1111-2222"), "_1111-2222"));
    assertEquals("dmnshape-drg-3-_1111-2222", getShapeId(diagram, list("dmnshape-drg-_1111-2222", "dmnshape-drg-2-_1111-2222"), "_1111-2222"));
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Test(org.junit.Test)

Example 13 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class IdUtilsTest method testGetEdgeIdWhenDiagramNameIsNull.

@Test
public void testGetEdgeIdWhenDiagramNameIsNull() {
    final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
    assertEquals("dmnedge-_1111-2222", getEdgeId(diagram, list(), "_1111-2222", false, false));
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Test(org.junit.Test)

Example 14 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class WrapperUtils method stunnerToDDExt.

private static JSIDMNShape stunnerToDDExt(final JSIDMNDiagram diagram, final List<String> dmnDiagramElementIds, final Definitions definitionsStunnerPojo, final View<? extends DMNElement> v, final String namespaceURI) {
    final JSIDMNShape result = new JSIDMNShape();
    final DMNElement definition = v.getDefinition();
    final String dmnElementId = definition.getId().getValue();
    final String shapeId = getShapeId(diagram, dmnDiagramElementIds, dmnElementId);
    result.setId(shapeId);
    result.setDmnElementRef(getDmnElementRef(definitionsStunnerPojo, v, namespaceURI));
    final JSIBounds bounds = new JSIBounds();
    result.setBounds(bounds);
    bounds.setX(xOfBound(upperLeftBound(v)));
    bounds.setY(yOfBound(upperLeftBound(v)));
    result.setDMNLabel(new JSIDMNLabel());
    // TODO {gcardosi}: HARDCODED
    result.setIsCollapsed(false);
    final JSIDMNStyle style = new JSIDMNStyle();
    if (v.getDefinition() instanceof Decision) {
        final Decision d = (Decision) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof InputData) {
        InputData d = (InputData) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
        final BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof KnowledgeSource) {
        final KnowledgeSource d = (KnowledgeSource) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof TextAnnotation) {
        final TextAnnotation d = (TextAnnotation) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
    } else if (v.getDefinition() instanceof DecisionService) {
        final DecisionService d = (DecisionService) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyStylingStyles(d.getStylingSet(), style);
        final JSIDMNDecisionServiceDividerLine dl = new JSIDMNDecisionServiceDividerLine();
        final JSIPoint leftPoint = new JSIPoint();
        leftPoint.setX(v.getBounds().getUpperLeft().getX());
        final double dlY = v.getBounds().getUpperLeft().getY() + d.getDividerLineY().getValue();
        leftPoint.setY(dlY);
        dl.addWaypoint(leftPoint);
        final JSIPoint rightPoint = new JSIPoint();
        rightPoint.setX(v.getBounds().getLowerRight().getX());
        rightPoint.setY(dlY);
        dl.addWaypoint(rightPoint);
        result.setDMNDecisionServiceDividerLine(dl);
    }
    result.setStyle(getWrappedJSIDMNStyle(style));
    return result;
}
Also used : JSIDMNDecisionServiceDividerLine(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDecisionServiceDividerLine) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) JSIDMNLabel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNLabel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation)

Example 15 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class DMNDiagramElementsUtils method generateDRGElement.

private JSIDMNDiagram generateDRGElement(final JSITDefinitions dmnDefinitions) {
    final JSIDMNDiagram drg = DRGDiagramUtils.newJSIDRGInstance();
    final double[] globalOriginX = { 0 };
    forEach(getDmnDiagram(dmnDefinitions), dmnDiagram -> {
        final List<JSIDiagramElement> elements = dmnDiagram.getDMNDiagramElement();
        final double[] diagramOriginX = { globalOriginX[0] };
        forEach(elements, element -> {
            final JSIDiagramElement copy = Js.uncheckedCast(jsCopy(element));
            if (JSIDMNShape.instanceOf(copy)) {
                final JSIDMNShape shape = Js.uncheckedCast(copy);
                final JSIBounds bounds = shape.getBounds();
                final double currentMax = bounds.getX() + bounds.getWidth();
                shape.setId(uniqueId());
                bounds.setX(diagramOriginX[0] + bounds.getX());
                if (currentMax > globalOriginX[0]) {
                    globalOriginX[0] = currentMax;
                }
            }
            if (JSIDMNEdge.instanceOf(copy)) {
                final JSIDMNEdge shape = Js.uncheckedCast(copy);
                shape.setId(uniqueId());
                shape.setOtherAttributes(null);
                forEach(shape.getWaypoint(), jsiPoint -> jsiPoint.setX(diagramOriginX[0] + jsiPoint.getX()));
            }
            drg.addDMNDiagramElement(Js.uncheckedCast(JsUtils.getWrappedElement(copy)));
        });
    });
    return drg;
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) JSIBounds(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Aggregations

JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)14 ArrayList (java.util.ArrayList)7 JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)6 Test (org.junit.Test)5 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 Edge (org.kie.workbench.common.stunner.core.graph.Edge)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)4 HashMap (java.util.HashMap)3 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)3 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)3 JSIDMNShape (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)3 Node (org.kie.workbench.common.stunner.core.graph.Node)3 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 DMNViewDefinition (org.kie.workbench.common.dmn.api.definition.DMNViewDefinition)2 Association (org.kie.workbench.common.dmn.api.definition.model.Association)2 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)2