Search in sources :

Example 1 with DiagramElementViolation

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();
            }
        }
    });
}
Also used : ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) ClientResourceType(org.uberfire.client.workbench.type.ClientResourceType) CopySelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.CopySelectionSessionCommand) ClearStatesSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ClearStatesSessionCommand) ExportToPdfSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToPdfSessionCommand) ClearSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ClearSessionCommand) DeleteSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.DeleteSelectionSessionCommand) PasteSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.PasteSelectionSessionCommand) RedoSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.RedoSessionCommand) CutSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.CutSelectionSessionCommand) UndoSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.UndoSessionCommand) ExportToPngSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToPngSessionCommand) ExportToBpmnSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToBpmnSessionCommand) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) VisitGraphSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.VisitGraphSessionCommand) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Command(org.uberfire.mvp.Command) ExportToJpgSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToJpgSessionCommand) SwitchGridSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.SwitchGridSessionCommand) Collection(java.util.Collection) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)

Example 2 with DiagramElementViolation

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();
            }
        }
    });
}
Also used : ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Command(org.uberfire.mvp.Command) Collection(java.util.Collection) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) EditorToolbar(org.kie.workbench.common.stunner.client.widgets.toolbar.impl.EditorToolbar) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)

Example 3 with DiagramElementViolation

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();
            }
        }
    });
}
Also used : ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Command(org.uberfire.mvp.Command) NavigateToExpressionEditorCommand(org.kie.workbench.common.dmn.client.commands.general.NavigateToExpressionEditorCommand) Collection(java.util.Collection) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) EditorToolbar(org.kie.workbench.common.stunner.client.widgets.toolbar.impl.EditorToolbar) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)

Example 4 with DiagramElementViolation

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));
}
Also used : Collection(java.util.Collection) ModelValidator(org.kie.workbench.common.stunner.core.validation.ModelValidator) DiagramValidator(org.kie.workbench.common.stunner.core.validation.DiagramValidator) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Supplier(java.util.function.Supplier) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Consumer(java.util.function.Consumer) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) BiConsumer(java.util.function.BiConsumer) Element(org.kie.workbench.common.stunner.core.graph.Element) Optional(java.util.Optional) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) LinkedList(java.util.LinkedList) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) LinkedList(java.util.LinkedList)

Example 5 with DiagramElementViolation

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));
}
Also used : DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) CanvasValidationFailEvent(org.kie.workbench.common.stunner.core.client.validation.canvas.CanvasValidationFailEvent) Test(org.junit.Test)

Aggregations

DiagramElementViolation (org.kie.workbench.common.stunner.core.validation.DiagramElementViolation)5 Collection (java.util.Collection)4 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)4 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)3 Command (org.uberfire.mvp.Command)3 EditorToolbar (org.kie.workbench.common.stunner.client.widgets.toolbar.impl.EditorToolbar)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 Test (org.junit.Test)1 NavigateToExpressionEditorCommand (org.kie.workbench.common.dmn.client.commands.general.NavigateToExpressionEditorCommand)1 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)1 ClearSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.ClearSessionCommand)1 ClearStatesSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.ClearStatesSessionCommand)1 CopySelectionSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.CopySelectionSessionCommand)1 CutSelectionSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.CutSelectionSessionCommand)1 DeleteSelectionSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.impl.DeleteSelectionSessionCommand)1