Skip to content

Commit

Permalink
refactoring, logging, added some reconnect checks
Browse files Browse the repository at this point in the history
Issue imixs#235
  • Loading branch information
rsoika committed Apr 19, 2023
1 parent 8a58c65 commit 81796da
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public DefaultBPMNEdgeExtension() {
*/
@Override
public boolean handlesElementTypeId(final String elementTypeId) {
return BPMNTypes.BPMN_EDGES.contains(elementTypeId);
return BPMNTypes.BPMN_EDGE_ELEMENTS.contains(elementTypeId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ public List<ShapeTypeHint> getShapeTypeHints() {
* edges are allowed without having to query the server again.
* <p>
* Note: here we need to add the :bpmn prefix which is used in the diagram.
* <p>
* TODO We need to define a EdgeTypeHint for all types of flows in BPMN.
* Currently we only support the SequenceFlow
*
* @return List of all edge type hints for the diagram implementation.
*/
Expand All @@ -150,8 +147,8 @@ public List<EdgeTypeHint> getEdgeTypeHints() {

// SequenceFLow
EdgeTypeHint sequenceFlowHint = createDefaultEdgeTypeHint(BPMNTypes.SEQUENCE_FLOW);
sequenceFlowHint.setSourceElementTypeIds(BPMNTypes.BPMN_FLOWELEMENTS);
sequenceFlowHint.setTargetElementTypeIds(BPMNTypes.BPMN_FLOWELEMENTS);
sequenceFlowHint.setSourceElementTypeIds(BPMNTypes.BPMN_FLOWELEMENT_NODES);
sequenceFlowHint.setTargetElementTypeIds(BPMNTypes.BPMN_FLOWELEMENT_NODES);
edgeHints.add(sequenceFlowHint);

// MessageFLow
Expand All @@ -177,7 +174,7 @@ public List<EdgeTypeHint> getEdgeTypeHints() {
private ShapeTypeHint createRootHint() {
ShapeTypeHint rootHint = new ShapeTypeHint(DefaultTypes.GRAPH, false, false, false, false);
List<String> elementList = new ArrayList<>();
elementList.addAll(BPMNTypes.BPMN_FLOWELEMENTS);
elementList.addAll(BPMNTypes.BPMN_FLOWELEMENT_NODES);
// remove Boundary Event
elementList.remove(BPMNTypes.BOUNDARY_EVENT);

Expand All @@ -194,7 +191,7 @@ private ShapeTypeHint createRootHint() {
private ShapeTypeHint createPoolHint() {
ShapeTypeHint poolHint = new ShapeTypeHint(BPMNTypes.POOL, true, true, true, true);
List<String> elementList = new ArrayList<>();
elementList.addAll(BPMNTypes.BPMN_FLOWELEMENTS);
elementList.addAll(BPMNTypes.BPMN_FLOWELEMENT_NODES);
// remove Boundary Event
elementList.remove(BPMNTypes.BOUNDARY_EVENT);
// add lane
Expand All @@ -214,7 +211,7 @@ private ShapeTypeHint createPoolHint() {
private ShapeTypeHint createLaneHint() {
ShapeTypeHint laneHint = new ShapeTypeHint(BPMNTypes.LANE, false, true, false, true);
List<String> elementList = new ArrayList<>();
elementList.addAll(BPMNTypes.BPMN_FLOWELEMENTS);
elementList.addAll(BPMNTypes.BPMN_FLOWELEMENT_NODES);
// remove Boundary Event
elementList.remove(BPMNTypes.BOUNDARY_EVENT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class BPMNGEdgeCreateHandler extends CreateBPMNEdgeOperationHandler {
* We use this constructor to overwrite the handledElementTypeIds
*/
public BPMNGEdgeCreateHandler() {
super(BPMNTypes.BPMN_EDGES);
super(BPMNTypes.BPMN_EDGE_ELEMENTS);
this.label = "Sequence Flow";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ public void applyBPMNExtensions(final GModelElement elementNode, final BPMNEleme

/**
* This helper method finds an GModelElement by its ID in a given List of
* GModelElements. The
* method returns null if not element with the given ID exists.
* GModelElements. The method returns null if no element with the given ID
* exists.
*
* If the list of elements contains Pools the method searches recursively the
* elements within the pool.
Expand All @@ -347,7 +347,7 @@ public void applyBPMNExtensions(final GModelElement elementNode, final BPMNEleme
* @param id - id to search for
* @return GModelElement - or null if no elment was found.
*/
GModelElement findElementById(final List<GModelElement> entityNodes, final String id) {
GModelElement findGElementById(final List<GModelElement> entityNodes, final String id) {
if (entityNodes != null) {
for (GModelElement element : entityNodes) {
if (element.getId().equals(id)) {
Expand All @@ -357,7 +357,7 @@ GModelElement findElementById(final List<GModelElement> entityNodes, final Strin
if (element instanceof PoolGNode) {
// recursive call!
PoolGNode gPool = (PoolGNode) element;
GModelElement child = findElementById(gPool.getChildren(), id);
GModelElement child = findGElementById(gPool.getChildren(), id);
if (child != null) {
return child;
}
Expand Down Expand Up @@ -562,8 +562,8 @@ List<GModelElement> computeGModelMessageFlows(final List<GModelElement> gRootNod
for (MessageFlow messageFlow : bpmnModel.getMessageFlows()) {
// 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 = findElementById(gRootNodeList, messageFlow.getSourceRef());
GModelElement target = findElementById(gRootNodeList, messageFlow.getTargetRef());
GModelElement source = findGElementById(gRootNodeList, messageFlow.getSourceRef());
GModelElement target = findGElementById(gRootNodeList, messageFlow.getTargetRef());
if (source == null) {
logger.warn("Source element '" + messageFlow.getSourceRef() + "' not found - skip MessageFlow id="
+ messageFlow.getId());
Expand Down Expand Up @@ -665,16 +665,16 @@ private void createGEdges(final Set<BPMNElementEdge> bpmnEdges, final List<GMode
for (BPMNElementEdge bpmnEdge : bpmnEdges) {
// first we need to verify if the target and source objects exist in our model
// if not we need to skip this sequenceFlow element!
GModelElement source = findElementById(gNodeList, bpmnEdge.getSourceRef());
GModelElement target = findElementById(gNodeList, bpmnEdge.getTargetRef());
GModelElement source = findGElementById(gNodeList, bpmnEdge.getSourceRef());
GModelElement target = findGElementById(gNodeList, bpmnEdge.getTargetRef());
if (source == null) {
logger.warn("Source element '" + bpmnEdge.getSourceRef() + "' not found - skip SequenceFlow id="
+ bpmnEdge.getId());
logger.warn("createGEdge '" + bpmnEdge.getId() + "' failed: Source element '" + bpmnEdge.getSourceRef()
+ "' not found");
continue;
}
if (target == null) {
logger.warn("Target element '" + bpmnEdge.getTargetRef() + "' not found - skip SequenceFlow id="
+ bpmnEdge.getId());
logger.warn("createGEdge '" + bpmnEdge.getId() + "' failed: Target element '" + bpmnEdge.getTargetRef()
+ "' not found");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.logging.log4j.Logger;
import org.eclipse.glsp.server.operations.AbstractOperationHandler;
import org.eclipse.glsp.server.operations.ReconnectEdgeOperation;
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.core.BPMNElementEdge;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.glsp.model.BPMNGModelState;
Expand Down Expand Up @@ -47,14 +48,30 @@ public void executeOperation(final ReconnectEdgeOperation operation) {
String sourceElementID = operation.getSourceElementId();
String targetElementID = operation.getTargetElementId();

logger.info("Reconnect: " + edgeID + " " + sourceElementID + "<-->" + targetElementID);
logger.debug("Reconnect: " + edgeID + " " + sourceElementID + "<-->" + targetElementID);

BPMNElementEdge bpmnElementEdge = modelState.getBpmnModel().findElementEdgeById(edgeID);

BPMNElementNode targetElement = modelState.getBpmnModel().findElementNodeById(targetElementID);
BPMNElementNode sourceElement = modelState.getBpmnModel().findElementNodeById(sourceElementID);

if (bpmnElementEdge != null && targetElement != null && sourceElement != null) {

// Test some edge-cases for SequenceFlows
if (BPMNTypes.isSequenceFlow(bpmnElementEdge)) {
// target and the source MUST be a BPMN FlowElement Node!
if (!BPMNTypes.isFlowElementNode(sourceElement)
|| !BPMNTypes.isFlowElementNode(targetElement)) {
logger.warn("SequenceFlows can only be reconnected with FlowElement Nodes! ");
return;
}
// Process must be the same for target and source!
if (!targetElement.getProcessId().equals(sourceElement.getProcessId())) {
logger.warn("SequenceFlows can only be reconnected within the same Process! ");
return;
}
}

bpmnElementEdge.setSourceRef(sourceElementID);
bpmnElementEdge.setTargetRef(targetElementID);

Expand Down
47 changes: 27 additions & 20 deletions open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/BPMNTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class BPMNTypes {
public static final String LANESET = "laneSet";

// Type Collections
public static List<String> BPMN_TASKS = Arrays.asList(new String[] { //
public final static List<String> BPMN_TASKS = Arrays.asList(new String[] { //
BPMNTypes.TASK, //
BPMNTypes.MANUAL_TASK, //
BPMNTypes.USER_TASK, //
Expand All @@ -89,7 +89,7 @@ public class BPMNTypes {
BPMNTypes.RECEIVE_TASK //
});

public static List<String> BPMN_ACTIVITIES = Arrays.asList(new String[] { //
public final static List<String> BPMN_ACTIVITIES = Arrays.asList(new String[] { //
BPMNTypes.TASK, //
BPMNTypes.MANUAL_TASK, //
BPMNTypes.USER_TASK, //
Expand All @@ -100,7 +100,7 @@ public class BPMNTypes {
BPMNTypes.RECEIVE_TASK, //
"subProcess", "adHocSubProcess", "transaction", "callActivity" });

public static List<String> BPMN_EVENTS = Arrays.asList(new String[] { //
public final static List<String> BPMN_EVENTS = Arrays.asList(new String[] { //
BPMNTypes.EVENT, //
BPMNTypes.START_EVENT, //
BPMNTypes.END_EVENT, //
Expand All @@ -109,7 +109,7 @@ public class BPMNTypes {
BPMNTypes.BOUNDARY_EVENT //
});

public final static List<String> BPMN_FLOWELEMENTS = Arrays.asList(//
public final static List<String> BPMN_FLOWELEMENT_NODES = Arrays.asList(//
BPMNTypes.TASK, //
BPMNTypes.MANUAL_TASK, //
BPMNTypes.USER_TASK, //
Expand All @@ -129,21 +129,28 @@ public class BPMNTypes {
BPMNTypes.END_EVENT, //
BPMNTypes.CATCH_EVENT, //
BPMNTypes.THROW_EVENT, //
BPMNTypes.BOUNDARY_EVENT, //
BPMNTypes.BOUNDARY_EVENT //
);

BPMNTypes.SEQUENCE_FLOW);
/**
* Returns true if the given element is a FlowElement, which are all
* BPMNElementNodes from the type Event, Gateway or Activity.
* SequenceFlows are not included as this is a Edge type!
*/
public static boolean isFlowElementNode(BPMNElement element) {
if (element instanceof BPMNElementNode) {
return BPMN_FLOWELEMENT_NODES.contains(((BPMNElementNode) element).getType());
}
return false;
}

/**
* Returns true if the given element is a FlowElement,
* which are Events, Gateways , Sequence Flows or Activities
* Returns true if the given element is a SequenceFlow
*/
public static boolean isFlowElement(BPMNElement element) {
public static boolean isSequenceFlow(BPMNElement element) {
if (element instanceof SequenceFlow) {
return true;
}
if (element instanceof BPMNElementNode) {
return BPMN_FLOWELEMENTS.contains(((BPMNElementNode) element).getType());
}
return false;
}

Expand Down Expand Up @@ -174,7 +181,13 @@ public static boolean isFlowElement(BPMNElement element) {

BPMNTypes.POOL);

public static List<String> BPMN_EVENT_DEFINITIONS = Arrays.asList(new String[] { //
public final static List<String> BPMN_EDGE_ELEMENTS = Arrays.asList(new String[] { //
BPMNTypes.SEQUENCE_FLOW, //
BPMNTypes.MESSAGE_FLOW, //
BPMNTypes.ASSOCIATION //
});

public final static List<String> BPMN_EVENT_DEFINITIONS = Arrays.asList(new String[] { //
BPMNTypes.EVENT_DEFINITION_CONDITIONAL, //
BPMNTypes.EVENT_DEFINITION_TIMER, //
BPMNTypes.EVENT_DEFINITION_SIGNAL, //
Expand All @@ -184,7 +197,7 @@ public static boolean isFlowElement(BPMNElement element) {
BPMNTypes.EVENT_DEFINITION_TERMINATE, //
BPMNTypes.EVENT_DEFINITION_COMPENSATION });

public static List<String> BPMN_GATEWAYS = Arrays.asList(new String[] { //
public final static List<String> BPMN_GATEWAYS = Arrays.asList(new String[] { //
BPMNTypes.GATEWAY, //
BPMNTypes.EXCLUSIVE_GATEWAY, //
BPMNTypes.INCLUSIVE_GATEWAY, //
Expand All @@ -193,10 +206,4 @@ public static boolean isFlowElement(BPMNElement element) {
BPMNTypes.COMPLEX_GATEWAY //
});

public static List<String> BPMN_EDGES = Arrays.asList(new String[] { //
BPMNTypes.SEQUENCE_FLOW, //
BPMNTypes.MESSAGE_FLOW, //
BPMNTypes.ASSOCIATION //
});

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public void setPosition(double x, double y) {
*
*/
private void updateContainment(double x, double y) {
// update is only needed for collaboration diagrams and FlowElements
if (!this.model.isCollaborationDiagram() || !BPMNTypes.isFlowElement(this)) {
// update is only needed for collaboration diagrams and FlowElement Nodes
if (!this.model.isCollaborationDiagram() || !BPMNTypes.isFlowElementNode(this)) {
return;
}
try {
Expand Down Expand Up @@ -189,9 +189,9 @@ private void updateContainment(double x, double y) {
}

/**
* This method updates the process assignment of a FlowElement. The element will
* be removed form the current process and added to the new process. All edges
* will be removed.
* This method updates the process assignment of a FlowElement Node. The element
* will be removed form the current process and added to the new process. All
* edges will be removed.
*
* Also the element will be removed from an optional laneSet of the old process.
*
Expand All @@ -200,7 +200,7 @@ private void updateContainment(double x, double y) {
*/
public void updateBPMNProcess(BPMNProcess newProcess) throws BPMNInvalidTypeException {

if (!BPMNTypes.isFlowElement(this)) {
if (!BPMNTypes.isFlowElementNode(this)) {
throw new BPMNInvalidTypeException(
"updateBPMNProcess can only be applied for BPMN FlowElements (Event, Gateway, Activity)");
}
Expand Down

0 comments on commit 81796da

Please sign in to comment.