Search in sources :

Example 66 with RuleViolation

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

the class AddControlPointCommand method execute.

@Override
public CommandResult<RuleViolation> execute(GraphCommandExecutionContext context) {
    if (checkExistingControlPoints(getEdgeContent().getControlPoints())) {
        // skipping in case adding already existing control points
        return GraphCommandResultBuilder.SUCCESS;
    }
    CommandResult<RuleViolation> allowResult = allow(context);
    if (CommandUtils.isError(allowResult)) {
        return allowResult;
    }
    HasControlPoints edgeContent = getEdgeContent();
    if (Objects.isNull(edgeContent.getControlPoints())) {
        edgeContent.setControlPoints(new LinkedList<>());
    }
    // add on the right index position on the list
    getControlPointList().stream().forEach(cp -> {
        // the effective index should not consider the head point that is a control point on the connector
        int effectiveIndex = cp.getIndex() - 1;
        if (edgeContent.getControlPoints().size() > effectiveIndex) {
            edgeContent.getControlPoints().add(effectiveIndex, cp);
        } else {
            edgeContent.getControlPoints().add(cp);
        }
    });
    // update index control points
    updateControlPointsIndex(edgeContent.getControlPoints());
    return GraphCommandResultBuilder.SUCCESS;
}
Also used : HasControlPoints(org.kie.workbench.common.stunner.core.graph.content.HasControlPoints) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 67 with RuleViolation

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

the class DeregisterNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    // And check it really exist on the graph storage as well.
    final org.kie.workbench.common.stunner.core.graph.Graph graph = getGraph(context);
    final Node<View<?>, Edge> candidate = (Node<View<?>, Edge>) checkCandidateNotNull(context);
    final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
    final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(graph, Optional.of(candidate), Optional.of(CardinalityContext.Operation.DELETE)));
    builder.addViolations(cardinalityRuleViolations);
    return builder.build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 68 with RuleViolation

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

the class DockNodeCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
    final CommandResult<RuleViolation> results = allow(context);
    if (!results.getType().equals(CommandResult.Type.ERROR)) {
        final Node<?, Edge> parent = getParent(context);
        final Node<?, Edge> candidate = getCandidate(context);
        final String uuid = UUID.uuid();
        final Edge<Dock, Node> edge = new EdgeImpl<>(uuid);
        edge.setContent(new Dock());
        edge.setSourceNode(parent);
        edge.setTargetNode(candidate);
        parent.getOutEdges().add(edge);
        candidate.getInEdges().add(edge);
        getMutableIndex(context).addEdge(edge);
    }
    return results;
}
Also used : Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 69 with RuleViolation

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

the class DockNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
    final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
    final Collection<RuleViolation> dockingRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.docking(getGraph(context), parent, candidate));
    return new GraphCommandResultBuilder(dockingRuleViolations).build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 70 with RuleViolation

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

the class MorphNodeCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
    final CommandResult<RuleViolation> results = allow(context);
    if (!results.getType().equals(CommandResult.Type.ERROR)) {
        final DefinitionManager definitionManager = context.getDefinitionManager();
        final Object currentDef = candidate.getContent().getDefinition();
        final String currentDefId = definitionManager.adapters().forDefinition().getId(currentDef);
        this.oldMorphTarget = currentDefId;
        final MorphAdapter<Object> morphAdapter = context.getDefinitionManager().adapters().registry().getMorphAdapter(currentDef.getClass());
        if (null == morphAdapter) {
            throw new RuntimeException("No morph adapter found for definition [" + currentDef.toString() + "] " + "and target morph [" + morphTarget + "]");
        }
        final Object newDef = morphAdapter.morph(currentDef, morphDefinition, morphTarget);
        if (null == newDef) {
            throw new RuntimeException("No morph resulting Definition. [ morphSource=" + currentDefId + ", " + "morphTarget=" + morphTarget + "]");
        }
        // Morph the node definition to the new one.
        candidate.getContent().setDefinition(newDef);
        // Update candidate roles.
        final Set<String> newLabels = definitionManager.adapters().forDefinition().getLabels(newDef);
        candidate.getLabels().clear();
        if (null != newLabels) {
            candidate.getLabels().addAll(newLabels);
        }
    }
    return results;
}
Also used : DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) 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