use of org.kie.workbench.common.stunner.core.validation.DiagramElementViolation in project kie-wb-common by kiegroup.
the class AbstractProjectDiagramEditor method save.
/**
* This method is called just once clicking on save.
* Before starting the save process, let's perform a diagram validation
* to check all it's valid.
* It's allowed to continue with the save process event if warnings found,
* but cannot save if any error is present in order to
* guarantee the diagram's consistency.
*/
@Override
protected void save() {
final Command continueSaveOnceValid = () -> super.save();
getCommand(ValidateSessionCommand.class).execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
continueSaveOnceValid.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (maxSeverity.equals(Violation.Type.ERROR)) {
onValidationFailed(violations);
} else {
// Allow saving when only warnings founds.
continueSaveOnceValid.execute();
}
}
});
}
use of org.kie.workbench.common.stunner.core.validation.DiagramElementViolation in project kie-wb-common by kiegroup.
the class SessionDiagramEditorScreen method validateAndSave.
private void validateAndSave() {
final Command save = this::save;
final EditorToolbar toolbar = (EditorToolbar) presenter.getToolbar();
toolbar.getValidateToolbarCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
log(Level.INFO, "Validation success.");
save.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
log(Level.WARNING, "Validation failed [violations=" + violations.toString() + "].");
// Allow saving when only warnings founds.
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (!maxSeverity.equals(Violation.Type.ERROR)) {
save.execute();
}
}
});
}
use of org.kie.workbench.common.stunner.core.validation.DiagramElementViolation in project kie-wb-common by kiegroup.
the class SessionDiagramEditorScreen method validateAndSave.
private void validateAndSave() {
final Command save = this::save;
final EditorToolbar toolbar = (EditorToolbar) presenter.getToolbar();
toolbar.getValidateToolbarCommand().execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
log(Level.INFO, "Validation success.");
save.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
log(Level.WARNING, "Validation failed [violations=" + violations.toString() + "].");
// Allow saving when only warnings founds.
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (!maxSeverity.equals(Violation.Type.ERROR)) {
save.execute();
}
}
});
}
use of org.kie.workbench.common.stunner.core.validation.DiagramElementViolation in project kie-wb-common by kiegroup.
the class AbstractDiagramValidator method validate.
@Override
@SuppressWarnings("unchecked")
public void validate(final Diagram diagram, final Consumer<Collection<DiagramElementViolation<RuleViolation>>> resultConsumer) {
final Graph graph = diagram.getGraph();
final List<DiagramElementViolation<RuleViolation>> violations = new LinkedList<>();
graphValidator.validate(graph, Optional.empty(), Optional.of((g, v) -> consumeBeanAndViolations(() -> violations).accept(g, v)), Optional.of((n, v) -> consumeBeanAndViolations(() -> violations).accept(n, v)), Optional.of((e, v) -> consumeBeanAndViolations(() -> violations).accept(e, v)), // to use the resulting ones here.
vs -> resultConsumer.accept(violations));
}
use of org.kie.workbench.common.stunner.core.validation.DiagramElementViolation in project kie-wb-common by kiegroup.
the class NotificationsObserverTest method testNotifyValidationFailed.
@Test
@SuppressWarnings("unchecked")
public void testNotifyValidationFailed() {
final DiagramElementViolation violation = mock(DiagramElementViolation.class);
final Collection<DiagramElementViolation<RuleViolation>> violations = Collections.singletonList(violation);
validationFailedNotification = new ValidationFailedNotification(violations, notificationContext, "message1", Notification.Type.ERROR);
final CanvasValidationFailEvent validationFailEvent = new CanvasValidationFailEvent(UUID, NAME, TITLE, violations);
tested.onCanvasValidationFailEvent(validationFailEvent);
verify(onNotification, times(1)).execute(any(Notification.class));
verify(validationFailed, times(1)).execute(eq(validationFailedNotification));
verify(commandFailed, never()).execute(any(CommandNotification.class));
verify(validationSuccess, never()).execute(any(ValidationSuccessNotification.class));
verify(commandSuccess, never()).execute(any(CommandNotification.class));
}
Aggregations