Search in sources :

Example 1 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AcyclicDirectedGraphRuleTest method checkCyclicalConnection.

@Test
@SuppressWarnings("unchecked")
public void checkCyclicalConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge c1 = new EdgeImpl<>("edge1");
    node1.getOutEdges().add(c1);
    node2.getInEdges().add(c1);
    c1.setSourceNode(node1);
    c1.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node2));
    when(context.getTarget()).thenReturn(Optional.of(node1));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(AcyclicDirectedGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 2 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class SingleConnectorPerTypeGraphRuleTest method checkHasExistingConnection.

@Test
@SuppressWarnings("unchecked")
public void checkHasExistingConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge existingConnector = new EdgeImpl<>("edge1");
    final ViewConnector existingConnectorView = mock(ViewConnector.class);
    existingConnector.setContent(existingConnectorView);
    when(existingConnectorView.getDefinition()).thenReturn(new Definition());
    node1.getOutEdges().add(existingConnector);
    node2.getInEdges().add(existingConnector);
    existingConnector.setSourceNode(node1);
    existingConnector.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node1));
    when(context.getTarget()).thenReturn(Optional.of(node2));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 3 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class GraphValidatorImplTest method testValidateEmptyViewConnectorNodes.

@Test
@SuppressWarnings("unchecked")
public void testValidateEmptyViewConnectorNodes() {
    final RuleSet ruleSet = graphTestHandler.ruleSet;
    final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
    final TestingGraphInstanceBuilder.TestGraph1 testGraph1 = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    // Update the edge2 and remove the connection's target node.
    // From this point, a validation error is expected.
    graphTestHandler.removeTargetConnection(testGraph1.edge2);
    tested.validate(graph, ruleSet, ruleViolations -> {
        assertEquals(1, ruleViolations.size());
        final RuleViolation violation = ruleViolations.iterator().next();
        assertNotNull(violation);
        assertTrue(violation instanceof EmptyConnectionViolation);
        EmptyConnectionViolation v = (EmptyConnectionViolation) violation;
        final Optional<Object[]> arguments = v.getArguments();
        assertTrue(arguments.isPresent());
        assertEquals(testGraph1.edge2.getUUID(), arguments.get()[0]);
        assertEquals(testGraph1.intermNode.getUUID(), arguments.get()[1]);
        assertNull(arguments.get()[2]);
    });
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) EmptyConnectionViolation(org.kie.workbench.common.stunner.core.rule.violations.EmptyConnectionViolation) TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 4 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation 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 5 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AddNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final CommandResult<RuleViolation> parentResult = super.check(context);
    final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
    parentResult.getViolations().forEach(builder::addViolation);
    final Element<? extends Definition<?>> graph = (Element<? extends Definition<?>>) getGraph(context);
    final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), graph, getCandidate()));
    builder.addViolations(containmentRuleViolations);
    return builder.build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Aggregations

RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)122 Test (org.junit.Test)81 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)59 Node (org.kie.workbench.common.stunner.core.graph.Node)27 Edge (org.kie.workbench.common.stunner.core.graph.Edge)26 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)21 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)18 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)16 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)16 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)15 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)15 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)13 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)12 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)11 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)10 Collection (java.util.Collection)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)7