Skip to content

Commit

Permalink
fixed, refactoring
Browse files Browse the repository at this point in the history
Issue #294
  • Loading branch information
rsoika committed Sep 24, 2023
1 parent 4fa492f commit 86989ba
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.glsp.server.gmodel.GModelCreateOperationHandler;
import org.eclipse.glsp.server.operations.CreateNodeOperation;
import org.openbpmn.bpmn.elements.BPMNProcess;
import org.openbpmn.bpmn.elements.Participant;
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
import org.openbpmn.glsp.bpmn.PoolGNode;
import org.openbpmn.glsp.model.BPMNGModelState;
Expand Down Expand Up @@ -81,17 +80,10 @@ protected BPMNProcess findProcessByCreateNodeOperation(final CreateNodeOperation
}
GPoint dropPoint = operation.getLocation().orElse(null);

Participant participant = modelState.getBpmnModel()
.findParticipantByPoint(BPMNGModelUtil.createBPMNPoint(dropPoint));

if (participant != null) {
return participant.getBpmnProcess();
} else {
// default to the default process
return modelState.getBpmnModel().openDefaultProces();
}
return BPMNGModelUtil.findProcessByPoint(modelState, dropPoint);
}


/**
* This method is a helper method to compute the container element. E.g. when a
* EventDefinition is placed into a Event or when a Extension is placed into a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -107,15 +108,14 @@ private void executeOperation(PasteOperation operation) {
if (bpmnElementNode != null) {
try {
// clone BPMNElementNodes....
// BPMNProcess process =
// modelState.getBpmnModel().openProcess(bpmnElementNode.getProcessId());
BPMNProcess process = bpmnElementNode.getBpmnProcess();
BPMNElementNode newElementNode = process.cloneBPMNElementNode(bpmnElementNode);
if (newElementNode != null) {
clonedIDs.put(bpmnElementNode.getId(), newElementNode.getId());
newElementIDList.add(newElementNode.getId());

// adjust position...
// adjust position. This operation will automatically also update the
// containment!
newElementNode.setPosition(bpmnElementNode.getBounds().getPosition().getX() + xOffset,
bpmnElementNode.getBounds().getPosition().getY() + yOffset);
// adjust label position?
Expand All @@ -136,7 +136,7 @@ private void executeOperation(PasteOperation operation) {
BPMNElementEdge bpmnElementEdge = modelState.getBpmnModel().findElementEdgeById(id);
if (bpmnElementEdge != null && bpmnElementEdge instanceof SequenceFlow) {
try {
logger.info("...copy SequenceFlow - " + bpmnElementEdge.getId());
logger.debug("...copy SequenceFlow - " + bpmnElementEdge.getId());

// do we have the corresponding source and target element?
String newSourceID = clonedIDs.get(bpmnElementEdge.getSourceRef());
Expand All @@ -148,6 +148,19 @@ private void executeOperation(PasteOperation operation) {
if (newElementEdge != null) {
newElementEdge.setSourceRef(newSourceID);
newElementEdge.setTargetRef(newTargetID);
// and finally we need to move the new sequenceFlow into the target process...
BPMNElement sourceElement = modelState.getBpmnModel().findElementById(newSourceID);
String processID = sourceElement.getProcessId();
BPMNProcess targetProcess = modelState.getBpmnModel().findProcessById(processID);
((SequenceFlow) newElementEdge).updateBPMNProcess(targetProcess);

// update waypoints
Set<BPMNPoint> sourceWayPoints = bpmnElementEdge.getWayPoints();
newElementEdge.clearWayPoints();
for (BPMNPoint _point : sourceWayPoints) {
BPMNPoint newPoint = new BPMNPoint(_point.getX() + xOffset, _point.getY() + yOffset);
newElementEdge.addWayPoint(newPoint);
}
}
}
} catch (BPMNModelException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openbpmn.bpmn.elements.core.BPMNBounds;
import org.openbpmn.bpmn.elements.core.BPMNLabel;
import org.openbpmn.bpmn.elements.core.BPMNPoint;
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
import org.openbpmn.bpmn.exceptions.BPMNMissingElementException;
import org.openbpmn.glsp.bpmn.BPMNGNode;
import org.openbpmn.glsp.bpmn.IconGCompartment;
Expand Down Expand Up @@ -271,6 +272,32 @@ public static BPMNProcess findProcessByContainer(final BPMNGModelState modelStat
return bpmnProcess;
}

/**
* Helper method resolves the containing BPMNProcess by a given Drop Point.
* This can be either the default process or the process of a Participant
* (Pool).
* <p>
* The method computes the matching process by testing the DropPoint with the
* dimensions of the existing BPMN Pools (Participants). In case the model is
* not a collaboration diagram, the method always returns the default process.
* <p>
*/
public static BPMNProcess findProcessByPoint(final BPMNGModelState modelState, final GPoint dropPoint)
throws BPMNInvalidTypeException {
if (!modelState.getBpmnModel().isCollaborationDiagram() || dropPoint == null) {
return modelState.getBpmnModel().openDefaultProces();
}
Participant participant = modelState.getBpmnModel()
.findParticipantByPoint(BPMNGModelUtil.createBPMNPoint(dropPoint));

if (participant != null) {
return participant.getBpmnProcess();
} else {
// default to the default process
return modelState.getBpmnModel().openDefaultProces();
}
}

/**
* Creates a BPMNPoint from a GPoint
*
Expand Down
16 changes: 16 additions & 0 deletions open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,22 @@ public Element findChildNodeByName(Element parent, BPMNNS ns, String nodeName) {
}
}

/**
* Find a BPMNProcess by its ID.
* The method returns null if no process with this ID exists.
*
* @param processid
* @return
*/
public BPMNProcess findProcessById(String processid) {
for (BPMNProcess _process : processes) {
if (_process.getId().equals(processid)) {
return _process;
}
}
return null;
}

/**
* Writes the current instance to the file system.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,19 @@ public BPMNElementEdge cloneBPMNElementEdge(BPMNElementEdge _bpmnElementEdge) th
Element element = (Element) this.getElementNode().appendChild(newElement);
result = this.createBPMNSequenceFlowByNode(element);
}

// update alls id of bpmn2: childs
NodeList childList = result.getElementNode().getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
Element child = (Element) childList.item(i);
// test if we have an id...
if (child.hasAttribute("id")) {
String tag = child.getLocalName();
// update id....
child.setAttribute("id", BPMNModel.generateShortID(tag));
}
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.core.BPMNElementEdge;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.exceptions.BPMNInvalidTypeException;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.w3c.dom.Element;

Expand All @@ -28,6 +29,26 @@ public BPMNProcess getProcess() {
return bpmnProcess;
}

/**
* This method updates the process assignment of the SequenceFlow. The element
* will be removed form the current process and added to the new process.
*
* @param newProcess
* @throws BPMNInvalidTypeException
*/
public void updateBPMNProcess(BPMNProcess newProcess) throws BPMNInvalidTypeException {

// ...remove the element from the corresponding element list
// and add it to the new process
this.bpmnProcess.getSequenceFlows().remove(this);
newProcess.getSequenceFlows().add(this);

// remove element from old process and assign it ot the new
this.bpmnProcess.getElementNode().removeChild(this.elementNode);
this.bpmnProcess = newProcess;
this.bpmnProcess.getElementNode().appendChild(this.elementNode);
}

/**
* Returns the conditionExpression if exits or null if no conditionExpression is
* defined.
Expand Down

0 comments on commit 86989ba

Please sign in to comment.