Search in sources :

Example 1 with GraphConnectionContext

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

the class GraphConnectionEvaluationHandler method evaluate.

@Override
public RuleViolations evaluate(final CanConnect rule, final GraphConnectionContext context) {
    final Edge<? extends View<?>, ? extends Node> connector = context.getConnector();
    final Node<? extends View<?>, ? extends Edge> source = context.getSource().orElse(null);
    final Node<? extends View<?>, ? extends Edge> target = context.getTarget().orElse(null);
    if (source == null || target == null) {
        return new DefaultRuleViolations();
    }
    final Set<String> edgeLabels = evalUtils.getLabels(connector);
    final Optional<Set<String>> sourceLabels = Optional.of(evalUtils.getLabels(source));
    final Optional<Set<String>> targetLabels = Optional.of(evalUtils.getLabels(target));
    final DefaultRuleViolations result = new DefaultRuleViolations();
    edgeLabels.stream().filter(pr -> rule.getRole().equals(pr)).forEach(pr -> result.addViolations(connectionEvaluationHandler.evaluate(rule, RuleContextBuilder.DomainContexts.connection(pr, sourceLabels, targetLabels))));
    return GraphEvaluationHandlerUtils.addViolationsSourceUUID(connector.getUUID(), result);
}
Also used : RuleEvaluationHandler(org.kie.workbench.common.stunner.core.rule.RuleEvaluationHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Set(java.util.Set) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) GraphConnectionContext(org.kie.workbench.common.stunner.core.rule.context.GraphConnectionContext) Inject(javax.inject.Inject) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Optional(java.util.Optional) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Node(org.kie.workbench.common.stunner.core.graph.Node) Set(java.util.Set) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)

Aggregations

Optional (java.util.Optional)1 Set (java.util.Set)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 RuleEvaluationHandler (org.kie.workbench.common.stunner.core.rule.RuleEvaluationHandler)1 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)1 GraphConnectionContext (org.kie.workbench.common.stunner.core.rule.context.GraphConnectionContext)1 RuleContextBuilder (org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder)1 CanConnect (org.kie.workbench.common.stunner.core.rule.impl.CanConnect)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1