@Override public boolean accepts(final CanConnect rule, final GraphConnectionContext context) { final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); final Set<String> labels = evalUtils.getLabels(connector); return labels.stream() .filter(cr -> rule.getRole().equals(cr) && // As for acceptance the delegated handler only needs the connector id, no need // to calculate roles for current source/target nodes. connectionEvaluationHandler.accepts(rule, RuleContextBuilder.DomainContexts.connection(cr, Optional.empty(), Optional.empty()))) .findAny() .isPresent(); }
@Override public boolean accepts(final CanContain rule, final NodeContainmentContext context) { final Set<String> parenteLabels = evalUtils.getLabels(context.getParent()); // As for acceptance checking, the delegated handler only needs the parent node id, no need // to calculate roles for the candidate node. return containmentHandler.accepts(rule, RuleContextBuilder.DomainContexts.containment(parenteLabels, Collections.emptySet())); }
@Override public boolean accepts(final CanDock rule, final NodeDockingContext context) { final Set<String> parentLabels = evalUtils.getLabels(context.getParent()); // As for acceptance checking, the delegated handler only needs the parent node id, no need // to calculate roles for the candidate node, so using an empty set. return dockingHandler.accepts(rule, RuleContextBuilder.DomainContexts.docking(parentLabels, Collections.emptySet())); }
@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); } }
@Override @SuppressWarnings("unchecked") public boolean accepts(final Occurrences rule, final ElementCardinalityContext context) { if (context.getCandidate().isPresent()) { final Set<String> candidateLabels = evalUtils.getLabels(context.getCandidate().get()); return cardinalityEvaluationHandler .accepts(rule, RuleContextBuilder.DomainContexts.cardinality( candidateLabels, -1, context.getOperation())); } return true; }
@Override public RuleViolations evaluate(final CanDock rule, final NodeDockingContext context) { final Node<? extends Definition<?>, ? extends Edge> target = context.getCandidate(); final Set<String> parentLabels = evalUtils.getLabels(context.getParent()); final Set<String> candidateLabels = evalUtils.getLabels(target); final DefaultRuleViolations result = new DefaultRuleViolations(); result.addViolations( dockingHandler .evaluate(rule, RuleContextBuilder.DomainContexts.docking(parentLabels, candidateLabels)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(target.getUUID(), result); } }
@Override public RuleViolations evaluate(final CanContain rule, final NodeContainmentContext context) { final Element<? extends Definition<?>> source = context.getParent(); final Node<? extends Definition<?>, ? extends Edge> target = context.getCandidate(); final Set<String> candidateLabels = evalUtils.getLabels(target); final Set<String> parentLabels = evalUtils.getLabels(source); final DefaultRuleViolations result = new DefaultRuleViolations(); result.addViolations( containmentHandler .evaluate(rule, RuleContextBuilder.DomainContexts.containment(parentLabels, candidateLabels)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(target.getUUID(), result); } }
@Override public boolean accepts(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final Edge<? extends View<?>, Node> edge = context.getEdge(); final Element<? extends View<?>> candidate = context.getCandidate(); final String edgeId = evalUtils.getElementDefinitionId(edge); final Set<String> candidateRoles = evalUtils.getLabels(candidate); // Take into account that there is no need to provide the candidate count value, as not necessary // just to check if the handler accepts the runtime rule and candidates. return edgeCardinalityEvaluationHandler.accepts(rule, RuleContextBuilder.DomainContexts.edgeCardinality(candidateRoles, edgeId, -1, context.getDirection(), context.getOperation())); }