diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/model/BPMNGModelFactory.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/model/BPMNGModelFactory.java index 983d565f..406d8db6 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/model/BPMNGModelFactory.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/model/BPMNGModelFactory.java @@ -22,7 +22,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -206,6 +208,7 @@ public GGraph buildGGraph(final BPMNModel model) { .id(modelState.getRootID()); List gRootNodeList = new ArrayList<>(); + Map poolGNodeList = new HashMap(); try { // In case we have collaboration diagram we iterate over all participants and @@ -229,6 +232,8 @@ public GGraph buildGGraph(final BPMNModel model) { applyBPMNExtensions(pool, participant); gRootNodeList.add(pool); + poolGNodeList.put(participant.getId(), pool); + } else { // add default process without a pool gRootNodeList.addAll(computeGModelElements(bpmnProcess, null, gRootNodeList)); @@ -295,10 +300,20 @@ public GGraph buildGGraph(final BPMNModel model) { // Add all Associations elements... Set processList = model.getProcesses(); for (BPMNProcess _process : processList) { - // apply the associations for each process separately... - createAssociationGEdges(_process.getAssociations(), gRootNodeList); + // apply the associations for each process separately. + // NOTE: It is necessary to verify if the Association is inside a Pool. In this + // case + // the Association becomes a child of the PoolGNode + if (!_process.isPublicProcess()) { + // the Associations inside a Pool, we need to add the edge to the + // PoolGNode childList + Participant _participant = _process.findParticipant(); + PoolGNode pool = poolGNodeList.get(_participant.getId()); + createAssociationGEdges(_process.getAssociations(), pool.getChildren(), _participant); + } else { + createAssociationGEdges(_process.getAssociations(), gRootNodeList, null); + } } - } catch (BPMNModelException e) { e.printStackTrace(); } @@ -745,91 +760,106 @@ private void createSequenceFlowGEdges(final Set sequenceFlows, fin } /** - * This helper method adds a list of MessageFlows to a given rootNodeElement + * This helper method adds a list of Associations to gModel * list. *

* This method expects that all process instances are already resolved. + *

+ * NOTE: The Association has a mixed behaviour. In case the Association is part + * of a Participant, than the edge waypoints are relative in the GModel. If the + * Association is part of the default process thant the waypoints are absolute. */ - private void createMessageFlowGEdges(final Set messageFlows, final List gRootNodeList) + private void createAssociationGEdges(final Set associations, final List gRootNodeList, + final Participant participant) throws BPMNMissingElementException { - // List gNodeList = new ArrayList<>(); // Add all SequenceFlows - for (MessageFlow messageFlow : messageFlows) { + for (Association association : associations) { // first we need to verify if the target and source objects exist in our model // if not we need to skip this messageFlow element! - GModelElement source = findGElementById(gRootNodeList, messageFlow.getSourceRef()); - GModelElement target = findGElementById(gRootNodeList, messageFlow.getTargetRef()); + GModelElement source = findGElementById(gRootNodeList, association.getSourceRef()); + GModelElement target = findGElementById(gRootNodeList, association.getTargetRef()); if (source == null) { - logger.warn("Source element '" + messageFlow.getSourceRef() + "' not found - skip MessageFlow id=" - + messageFlow.getId()); + logger.warn("Source element '" + association.getSourceRef() + "' not found - skip MessageFlow id=" + + association.getId()); continue; } if (target == null) { - logger.warn("Target element '" + messageFlow.getTargetRef() + "' not found - skip MessageFlow id=" - + messageFlow.getId()); + logger.warn("Target element '" + association.getTargetRef() + "' not found - skip MessageFlow id=" + + association.getId()); continue; } // now construct the GNode and add it to the model.... - BPMNGEdgeBuilder builder = new BPMNGEdgeBuilder(messageFlow); + BPMNGEdgeBuilder builder = new BPMNGEdgeBuilder(association); builder.target(computeGPort(target)); builder.source(computeGPort(source)); BPMNGEdge bpmnGEdge = builder.build(); bpmnGEdge.setKind(""); - for (BPMNPoint wayPoint : messageFlow.getWayPoints()) { - // add the waypoint to the GLSP model.... - GPoint point = GraphUtil.point(wayPoint.getX(), wayPoint.getY()); + // add the waypoints to the GLSP model.... + for (BPMNPoint wayPoint : association.getWayPoints()) { + + // compute relative waypoints in case we are inside a Particpant + GPoint point = null; + if (participant != null) { + point = computeRelativeGPoint(wayPoint, participant); + } else { + // compute absoulte waypoints, because the association is part of the default + // process. + point = GraphUtil.point(wayPoint.getX(), wayPoint.getY()); + } bpmnGEdge.getRoutingPoints().add(point); } + gRootNodeList.add(bpmnGEdge); // apply BPMN Extensions - applyBPMNExtensions(bpmnGEdge, messageFlow); + applyBPMNExtensions(bpmnGEdge, association); } } /** - * This helper method adds a list of Associations to gModel + * This helper method adds a list of MessageFlows to a given rootNodeElement * list. *

* This method expects that all process instances are already resolved. */ - private void createAssociationGEdges(final Set associations, final List gRootNodeList) + private void createMessageFlowGEdges(final Set messageFlows, final List gRootNodeList) throws BPMNMissingElementException { + // List gNodeList = new ArrayList<>(); // Add all SequenceFlows - for (Association association : associations) { + for (MessageFlow messageFlow : messageFlows) { // first we need to verify if the target and source objects exist in our model // if not we need to skip this messageFlow element! - GModelElement source = findGElementById(gRootNodeList, association.getSourceRef()); - GModelElement target = findGElementById(gRootNodeList, association.getTargetRef()); + GModelElement source = findGElementById(gRootNodeList, messageFlow.getSourceRef()); + GModelElement target = findGElementById(gRootNodeList, messageFlow.getTargetRef()); if (source == null) { - logger.warn("Source element '" + association.getSourceRef() + "' not found - skip MessageFlow id=" - + association.getId()); + logger.warn("Source element '" + messageFlow.getSourceRef() + "' not found - skip MessageFlow id=" + + messageFlow.getId()); continue; } if (target == null) { - logger.warn("Target element '" + association.getTargetRef() + "' not found - skip MessageFlow id=" - + association.getId()); + logger.warn("Target element '" + messageFlow.getTargetRef() + "' not found - skip MessageFlow id=" + + messageFlow.getId()); continue; } // now construct the GNode and add it to the model.... - BPMNGEdgeBuilder builder = new BPMNGEdgeBuilder(association); + BPMNGEdgeBuilder builder = new BPMNGEdgeBuilder(messageFlow); builder.target(computeGPort(target)); builder.source(computeGPort(source)); BPMNGEdge bpmnGEdge = builder.build(); bpmnGEdge.setKind(""); - for (BPMNPoint wayPoint : association.getWayPoints()) { + for (BPMNPoint wayPoint : messageFlow.getWayPoints()) { // add the waypoint to the GLSP model.... GPoint point = GraphUtil.point(wayPoint.getX(), wayPoint.getY()); bpmnGEdge.getRoutingPoints().add(point); } gRootNodeList.add(bpmnGEdge); // apply BPMN Extensions - applyBPMNExtensions(bpmnGEdge, association); + applyBPMNExtensions(bpmnGEdge, messageFlow); } diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java index eeaab41d..727364a2 100644 --- a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java +++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java @@ -1134,10 +1134,13 @@ public BPMNElementEdge findElementEdgeById(String id) { } /** - * This method returns the BPMNParticipant in case the Process represents a BPMN - * Pool + * This method returns the BPMNParticipant of this process in case it represents + * a BPMN Participant. * - * @return + * The method returns null if the process is the default process (no + * Participant) + * + * @return participant or null if default process */ public Participant findParticipant() { Participant result = this.getModel().findParticipantByProcessId(this.getId());