Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Issue imixs#245
  • Loading branch information
rsoika committed May 11, 2023
1 parent 7c6cafa commit 417953a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,6 +208,7 @@ public GGraph buildGGraph(final BPMNModel model) {
.id(modelState.getRootID());

List<GModelElement> gRootNodeList = new ArrayList<>();
Map<String, PoolGNode> poolGNodeList = new HashMap<String, PoolGNode>();

try {
// In case we have collaboration diagram we iterate over all participants and
Expand All @@ -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));
Expand Down Expand Up @@ -295,10 +300,20 @@ public GGraph buildGGraph(final BPMNModel model) {
// Add all Associations elements...
Set<BPMNProcess> 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();
}
Expand Down Expand Up @@ -745,91 +760,106 @@ private void createSequenceFlowGEdges(final Set<SequenceFlow> 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.
* <p>
* This method expects that all process instances are already resolved.
* <p>
* 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<MessageFlow> messageFlows, final List<GModelElement> gRootNodeList)
private void createAssociationGEdges(final Set<Association> associations, final List<GModelElement> gRootNodeList,
final Participant participant)
throws BPMNMissingElementException {
// List<GModelElement> 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.
* <p>
* This method expects that all process instances are already resolved.
*/
private void createAssociationGEdges(final Set<Association> associations, final List<GModelElement> gRootNodeList)
private void createMessageFlowGEdges(final Set<MessageFlow> messageFlows, final List<GModelElement> gRootNodeList)
throws BPMNMissingElementException {
// List<GModelElement> 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);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 417953a

Please sign in to comment.