Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Issue #340
  • Loading branch information
rsoika committed Mar 3, 2024
1 parent 7c45a9c commit 678bc85
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BPMNGNode> element = null;
Expand All @@ -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)) {

Expand All @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,19 +51,27 @@ public class BPMNGLSPValidator implements ModelValidator {
@Inject
protected BPMNGModelState modelState;

private List<Marker> bpmnMarkers = null;;
private List<BPMNValidationMarker> 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.
* <p>
*
* This method calls the Meta Model Validation method and converts the Meta
* Model Error markers into GLSP marker objects.
*/
public void beforeValidate(final List<GModelElement> elements, final String reason) {

logger.info("---==== Starte Validate new....");
bpmnMarkers = new ArrayList<>();

bpmnMarkers = new ArrayList<BPMNValidationMarker>();
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);
}
}

Expand All @@ -80,6 +87,8 @@ public List<Marker> validate(final List<GModelElement> 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;
}

Expand All @@ -104,12 +113,14 @@ private List<Marker> doValidate(final List<GModelElement> elements, final String
@Override
public List<Marker> doBatchValidation(final GModelElement element) {

logger.info("...BatchValidate " + element.getId());
// logger.info("...BatchValidate " + element.getId());

List<Marker> 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));
}
}

Expand All @@ -119,12 +130,14 @@ public List<Marker> doBatchValidation(final GModelElement element) {
@Override
public List<Marker> doLiveValidation(GModelElement element) {

logger.info("...LiveValidate " + element.getId());
// logger.info("...LiveValidate " + element.getId());

List<Marker> 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));
}
}

Expand All @@ -140,21 +153,23 @@ public List<Marker> 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<BPMNValidationMarker> errorList = new BPMNValidationHandler().validate(model, forceValidation);
// // Meta Model validation...
// List<BPMNValidationMarker> 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));

}
}
// }
// }

}
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ private void removeElementEdge(String id) {
}
}
}
targetElement.resetValidation();
}
BPMNElementNode sourceElement = findElementNodeById(sourceRef);
if (sourceElement != null) {
Expand All @@ -953,6 +954,7 @@ private void removeElementEdge(String id) {
}
}
}
sourceElement.resetValidation();
}

// Finally delete the flow element and the edge
Expand Down

0 comments on commit 678bc85

Please sign in to comment.