From 678bc8500e023266ba210c5754f37c664aba924d Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sun, 3 Mar 2024 09:51:04 +0100 Subject: [PATCH] refactoring Issue #340 --- .../elements/edge/BPMNGEdgeCreateHandler.java | 17 +++-- .../BPMNReconnectEdgeOperationHandler.java | 3 + .../glsp/validators/BPMNGLSPValidator.java | 69 +++++++++++-------- .../openbpmn/bpmn/elements/BPMNProcess.java | 2 + 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/edge/BPMNGEdgeCreateHandler.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/edge/BPMNGEdgeCreateHandler.java index 2b48c472..6c2c3092 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/edge/BPMNGEdgeCreateHandler.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/elements/edge/BPMNGEdgeCreateHandler.java @@ -72,6 +72,9 @@ protected void executeOperation(final CreateEdgeOperation operation) { String edgeId = null; BPMNGNode sourceNode = null; BPMNGNode targetNode = null; + BPMNElementNode sourceElementNode = null; + BPMNElementNode targetElementNode = null; + String edgeType = operation.getElementTypeId(); try { Optional element = null; @@ -93,6 +96,10 @@ protected void executeOperation(final CreateEdgeOperation operation) { // Depending on the edgeType we use here different method to create the BPMN // edge + sourceElementNode = (BPMNElementNode) modelState.getBpmnModel() + .findElementById(sourceId); + targetElementNode = (BPMNElementNode) modelState.getBpmnModel() + .findElementById(targetId); if (BPMNTypes.SEQUENCE_FLOW.equals(edgeType)) { @@ -112,10 +119,6 @@ protected void executeOperation(final CreateEdgeOperation operation) { if (BPMNTypes.ASSOCIATION.equals(edgeType)) { // if one of the element nodes is assigned to the default process, than we // assign the association also to the default process - BPMNElementNode sourceElementNode = (BPMNElementNode) modelState.getBpmnModel() - .findElementById(sourceId); - BPMNElementNode targetElementNode = (BPMNElementNode) modelState.getBpmnModel() - .findElementById(targetId); BPMNProcess sourceProcess = sourceElementNode.getBpmnProcess(); BPMNProcess targetProcess = targetElementNode.getBpmnProcess(); edgeId = BPMNModel.generateShortID("association"); @@ -132,6 +135,10 @@ protected void executeOperation(final CreateEdgeOperation operation) { modelState.getBpmnModel().addMessageFlow(edgeId, sourceId, targetId); } + // invalidate source/target elements + sourceElementNode.resetValidation(); + targetElementNode.resetValidation(); + // finally update he current selection updateSelection(sourceNode, targetNode, edgeId); modelState.reset(); @@ -170,7 +177,7 @@ private void updateSelection(BPMNGNode sourceNode, BPMNGNode targetNode, String || BPMNTypes.BPMN_GATEWAYS.contains(targetNode.getType())) { deselectedElementsIDs.add(targetNode.getId() + "_bpmnlabel"); } - actionDispatcher.dispatchAfterNextUpdate(new SelectAction(List.of(edgeId), + actionDispatcher.dispatch(new SelectAction(List.of(edgeId), deselectedElementsIDs)); } } diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNReconnectEdgeOperationHandler.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNReconnectEdgeOperationHandler.java index 29635544..8d128f10 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNReconnectEdgeOperationHandler.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/operations/BPMNReconnectEdgeOperationHandler.java @@ -82,6 +82,9 @@ private void executeOperation(final ReconnectEdgeOperation operation) { bpmnElementEdge.setSourceRef(sourceElementID); bpmnElementEdge.setTargetRef(targetElementID); + // invalidate source/target + sourceElement.resetValidation(); + targetElement.resetValidation(); // remove routing points bpmnElementEdge.clearWayPoints(); modelState.reset(); diff --git a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java index 7c9b2cad..c1af2506 100644 --- a/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java +++ b/open-bpmn.glsp-server/src/main/java/org/openbpmn/glsp/validators/BPMNGLSPValidator.java @@ -24,7 +24,6 @@ import org.eclipse.glsp.server.features.validation.MarkerKind; import org.eclipse.glsp.server.features.validation.MarkersReason; import org.eclipse.glsp.server.features.validation.ModelValidator; -import org.openbpmn.bpmn.BPMNModel; import org.openbpmn.bpmn.validation.BPMNValidationHandler; import org.openbpmn.bpmn.validation.BPMNValidationMarker; import org.openbpmn.glsp.model.BPMNGModelState; @@ -52,19 +51,27 @@ public class BPMNGLSPValidator implements ModelValidator { @Inject protected BPMNGModelState modelState; - private List bpmnMarkers = null;; + private List bpmnMarkers = null;; + /** + * This method validates a given BPMNModel. It returns a list of + * validationErrors that contains a lable and a short description pointing to an + * element that causes a problem. + *

+ * + * This method calls the Meta Model Validation method and converts the Meta + * Model Error markers into GLSP marker objects. + */ public void beforeValidate(final List elements, final String reason) { - logger.info("---==== Starte Validate new...."); - bpmnMarkers = new ArrayList<>(); - + bpmnMarkers = new ArrayList(); + logger.info("---==== Starte Validate new.... current BPMNmarker size=" + bpmnMarkers.size()); // init bpmn marker list.... if (MarkersReason.BATCH.equals(reason)) { - createBPMNMarkers(modelState.getBpmnModel(), true); + bpmnMarkers = new BPMNValidationHandler().validate(modelState.getBpmnModel(), true); } if (MarkersReason.LIVE.equals(reason)) { - createBPMNMarkers(modelState.getBpmnModel(), false); + bpmnMarkers = new BPMNValidationHandler().validate(modelState.getBpmnModel(), false); } } @@ -80,6 +87,8 @@ public List validate(final List elements, final String re afterValidate(elements, reason); logger.info("--------------------> validation took " + (System.currentTimeMillis() - l) + " ms"); + logger.info("--------------------- new BPMNmarker size=" + bpmnMarkers.size()); + logger.info("--------------------- final marker size=" + markers.size()); return markers; } @@ -104,12 +113,14 @@ private List doValidate(final List elements, final String @Override public List doBatchValidation(final GModelElement element) { - logger.info("...BatchValidate " + element.getId()); + // logger.info("...BatchValidate " + element.getId()); List result = new ArrayList<>(); - for (Marker marker : bpmnMarkers) { - if (marker.getElementId().equals(element.getId())) { - result.add(marker); + for (BPMNValidationMarker bpmnMarker : bpmnMarkers) { + if (bpmnMarker.getElementId().equals(element.getId())) { + result.add(new Marker(bpmnMarker.getLabel(), bpmnMarker.getDescription(), + bpmnMarker.getElementId(), + MarkerKind.ERROR)); } } @@ -119,12 +130,14 @@ public List doBatchValidation(final GModelElement element) { @Override public List doLiveValidation(GModelElement element) { - logger.info("...LiveValidate " + element.getId()); + // logger.info("...LiveValidate " + element.getId()); List result = new ArrayList<>(); - for (Marker marker : bpmnMarkers) { - if (marker.getElementId().equals(element.getId())) { - result.add(marker); + for (BPMNValidationMarker bpmnMarker : bpmnMarkers) { + if (bpmnMarker.getElementId().equals(element.getId())) { + result.add(new Marker(bpmnMarker.getLabel(), bpmnMarker.getDescription(), + bpmnMarker.getElementId(), + MarkerKind.ERROR)); } } @@ -140,21 +153,23 @@ public List doLiveValidation(GModelElement element) { * This method calls the Meta Model Validation method and converts the Meta * Model Error markers into GLSP marker objects. */ - private void createBPMNMarkers(BPMNModel model, boolean forceValidation) { - logger.fine("...starting validating model..."); + // private void createBPMNMarkers(BPMNModel model, boolean forceValidation) { + // logger.fine("...starting validating model..."); - // Meta Model validation... - List errorList = new BPMNValidationHandler().validate(model, forceValidation); + // // Meta Model validation... + // List errorList = new + // BPMNValidationHandler().validate(model, forceValidation); - // Convert ErrorList into a GLSP Marker List - for (BPMNValidationMarker _error : errorList) { - if (BPMNValidationMarker.ErrorType.ERROR.equals(_error.getErrorType())) { - bpmnMarkers.add(new Marker(_error.getLabel(), _error.getDescription(), _error.getElementId(), - MarkerKind.ERROR)); + // // Convert ErrorList into a GLSP Marker List + // for (BPMNValidationMarker _error : errorList) { + // if (BPMNValidationMarker.ErrorType.ERROR.equals(_error.getErrorType())) { + // bpmnMarkers.add(new Marker(_error.getLabel(), _error.getDescription(), + // _error.getElementId(), + // MarkerKind.ERROR)); - } - } + // } + // } - } + // } } \ No newline at end of file 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 b37db059..a2620792 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 @@ -938,6 +938,7 @@ private void removeElementEdge(String id) { } } } + targetElement.resetValidation(); } BPMNElementNode sourceElement = findElementNodeById(sourceRef); if (sourceElement != null) { @@ -953,6 +954,7 @@ private void removeElementEdge(String id) { } } } + sourceElement.resetValidation(); } // Finally delete the flow element and the edge