Search in sources :

Example 6 with DiagramElement

use of org.eclipse.dd.di.DiagramElement in project kie-wb-common by kiegroup.

the class EmbeddedSubProcessTest method testMarshallEmbeddedCoords.

@Test
public void testMarshallEmbeddedCoords() throws Exception {
    final String BPMN_EMBEDDED_SUBPROCESS = "org/kie/workbench/common/stunner/bpmn/backend/service/diagram/embeddedSubprocess.bpmn";
    String END_EVENT = "shape__FF050977-4D13-47F1-8B9B-D68FDE208666";
    Diagram<Graph, Metadata> diagram = getSpecificDiagram(BPMN_EMBEDDED_SUBPROCESS);
    // we start converting from the root, then pull out the result
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    List<DiagramElement> planeElement = definitions.getDiagrams().get(0).getPlane().getPlaneElement();
    BPMNShape diagramElement = planeElement.stream().filter(BPMNShape.class::isInstance).map(s -> (BPMNShape) s).filter(el -> el.getId().equals(END_EVENT)).findFirst().get();
    assertThat(diagramElement.getBounds().getX()).isEqualTo(885f);
    assertThat(diagramElement.getBounds().getY()).isEqualTo(143f);
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EmbeddedSubprocessExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.subProcess.execution.EmbeddedSubprocessExecutionSet) DiagramElement(org.eclipse.dd.di.DiagramElement) Test(org.junit.Test) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Definitions(org.eclipse.bpmn2.Definitions) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Test(org.junit.Test)

Example 7 with DiagramElement

use of org.eclipse.dd.di.DiagramElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitEdgeBoundsInContainers.

public void revisitEdgeBoundsInContainers(Definitions def) {
    BPMNPlane plane = def.getDiagrams().get(0).getPlane();
    List<DiagramElement> diagramElements = plane.getPlaneElement();
    for (DiagramElement dia : diagramElements) {
        if (dia instanceof BPMNEdge) {
            BPMNEdge edge = (BPMNEdge) dia;
            if (edge.getBpmnElement() instanceof SequenceFlow) {
                SequenceFlow sq = (SequenceFlow) edge.getBpmnElement();
                List<RootElement> rootElements = def.getRootElements();
                for (RootElement root : rootElements) {
                    if (root instanceof Process) {
                        Process process = (Process) root;
                        updateEdgeBoundsInContainers(process, sq, plane, edge);
                    }
                }
                // update the source and target on BPMNEdge
                if (sq.getSourceRef() != null) {
                    edge.setSourceElement(getBPMNShapeForElement(sq.getSourceRef(), plane));
                }
                if (sq.getTargetRef() != null) {
                    edge.setTargetElement(getBPMNShapeForElement(sq.getTargetRef(), plane));
                }
            }
        }
    }
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) RootElement(org.eclipse.bpmn2.RootElement) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 8 with DiagramElement

use of org.eclipse.dd.di.DiagramElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallNode.

protected void marshallNode(FlowNode node, Map<String, Object> properties, String stencil, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset) throws JsonGenerationException, IOException {
    if (properties == null) {
        properties = new LinkedHashMap<String, Object>();
    }
    putDocumentationProperty(node, properties);
    if (node.getName() != null) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(node.getName()));
    } else {
        if (node instanceof TextAnnotation) {
            if (((TextAnnotation) node).getText() != null) {
                properties.put(NAME, ((TextAnnotation) node).getText());
            } else {
                properties.put(NAME, "");
            }
        } else {
            properties.put(NAME, "");
        }
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(node.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put("name", elementName);
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", stencil);
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    for (SequenceFlow outgoing : node.getOutgoing()) {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", outgoing.getId());
        generator.writeEndObject();
    }
    // we need to also add associations as outgoing elements
    Process process = (Process) plane.getBpmnElement();
    writeAssociations(process, node.getId(), generator);
    // and boundary events for activities
    List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
    findBoundaryEvents(process, boundaryEvents);
    for (BoundaryEvent be : boundaryEvents) {
        if (be.getAttachedToRef().getId().equals(node.getId())) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", be.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    // boundary events have a docker
    if (node instanceof BoundaryEvent) {
        Iterator<FeatureMap.Entry> iter = node.getAnyAttribute().iterator();
        boolean foundDockerInfo = false;
        while (iter.hasNext()) {
            FeatureMap.Entry entry = iter.next();
            if (entry.getEStructuralFeature().getName().equals("dockerinfo")) {
                foundDockerInfo = true;
                String dockerInfoStr = String.valueOf(entry.getValue());
                if (dockerInfoStr != null && dockerInfoStr.length() > 0) {
                    if (dockerInfoStr.endsWith("|")) {
                        dockerInfoStr = dockerInfoStr.substring(0, dockerInfoStr.length() - 1);
                        String[] dockerInfoParts = dockerInfoStr.split("\\|");
                        String infoPartsToUse = dockerInfoParts[0];
                        String[] infoPartsToUseParts = infoPartsToUse.split("\\^");
                        if (infoPartsToUseParts != null && infoPartsToUseParts.length > 0) {
                            generator.writeArrayFieldStart("dockers");
                            generator.writeStartObject();
                            generator.writeObjectField("x", Double.valueOf(infoPartsToUseParts[0]));
                            generator.writeObjectField("y", Double.valueOf(infoPartsToUseParts[1]));
                            generator.writeEndObject();
                            generator.writeEndArray();
                        }
                    }
                }
            }
        }
        // backwards compatibility to older versions -- BZ 1196259
        if (!foundDockerInfo) {
            // find the edge associated with this boundary event
            for (DiagramElement element : plane.getPlaneElement()) {
                if (element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == node) {
                    List<Point> waypoints = ((BPMNEdge) element).getWaypoint();
                    if (waypoints != null && waypoints.size() > 0) {
                        // one per boundary event
                        Point p = waypoints.get(0);
                        if (p != null) {
                            generator.writeArrayFieldStart("dockers");
                            generator.writeStartObject();
                            generator.writeObjectField("x", p.getX());
                            generator.writeObjectField("y", p.getY());
                            generator.writeEndObject();
                            generator.writeEndArray();
                        }
                    }
                }
            }
        }
    }
    BPMNShape shape = (BPMNShape) findDiagramElement(plane, node);
    Bounds bounds = shape.getBounds();
    correctEventNodeSize(shape);
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) Bounds(org.eclipse.dd.dc.Bounds) ArrayList(java.util.ArrayList) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) DiagramElement(org.eclipse.dd.di.DiagramElement) Entry(java.util.Map.Entry) DataObject(org.eclipse.bpmn2.DataObject) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 9 with DiagramElement

use of org.eclipse.dd.di.DiagramElement in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method findDiagramElement.

private DiagramElement findDiagramElement(BPMNPlane plane, BaseElement baseElement) {
    DiagramElement result = _diagramElements.get(baseElement.getId());
    if (result != null) {
        return result;
    }
    for (DiagramElement element : plane.getPlaneElement()) {
        if ((element instanceof BPMNEdge && ((BPMNEdge) element).getBpmnElement() == baseElement) || (element instanceof BPMNShape && ((BPMNShape) element).getBpmnElement() == baseElement)) {
            _diagramElements.put(baseElement.getId(), element);
            return element;
        }
    }
    _logger.debug("Could not find BPMNDI information for " + baseElement);
    return null;
}
Also used : DiagramElement(org.eclipse.dd.di.DiagramElement) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Aggregations

DiagramElement (org.eclipse.dd.di.DiagramElement)9 BPMNShape (org.eclipse.bpmn2.di.BPMNShape)6 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)5 BPMNPlane (org.eclipse.bpmn2.di.BPMNPlane)5 ArrayList (java.util.ArrayList)3 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)3 Process (org.eclipse.bpmn2.Process)3 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 SubProcess (org.eclipse.bpmn2.SubProcess)3 List (java.util.List)2 RootElement (org.eclipse.bpmn2.RootElement)2 Bounds (org.eclipse.dd.dc.Bounds)2 Point (org.eclipse.dd.dc.Point)2 Entry (java.util.Map.Entry)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)1 DataObject (org.eclipse.bpmn2.DataObject)1 Definitions (org.eclipse.bpmn2.Definitions)1 FlowNode (org.eclipse.bpmn2.FlowNode)1 Lane (org.eclipse.bpmn2.Lane)1