@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 RuleViolations evaluate(final Occurrences rule, final ElementCardinalityContext context) { final DefaultRuleViolations results = new DefaultRuleViolations(); final Optional<Element<? extends View<?>>> candidate = context.getCandidate(); final String role = rule.getRole(); final Set<String> roles = Collections.singleton(role); final Map<String, Integer> graphLabelCount = countLabels(context.getGraph(), roles); // Ensure processing the role even if not used along the graph, so // cardinality min rules can be evaluated. final int count = graphLabelCount.isEmpty() ? 0 : graphLabelCount.get(role); final Optional<CardinalityContext.Operation> operation = context.getOperation(); results.addViolations( cardinalityEvaluationHandler .evaluate(rule, RuleContextBuilder.DomainContexts.cardinality(roles, count, operation)) ); if (candidate.isPresent()) { return GraphEvaluationHandlerUtils.addViolationsSourceUUID(candidate.get().getUUID(), results); } return results; }
@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 @SuppressWarnings("unchecked") public RuleViolations evaluate(final EdgeOccurrences rule, final ConnectorCardinalityContext context) { final DefaultRuleViolations result = new DefaultRuleViolations(); final Node<? extends View<?>, ? extends Edge> candidate = (Node<? extends View<?>, ? extends Edge>) context.getCandidate(); final Edge<? extends View<?>, Node> edge = context.getEdge(); final Optional<CardinalityContext.Operation> operation = context.getOperation(); final EdgeCardinalityContext.Direction direction = context.getDirection(); final List<? extends Edge> edges = isIncoming(direction) ? candidate.getInEdges() : candidate.getOutEdges(); final String edgeId = evalUtils.getElementDefinitionId(edge); final int count = evalUtils.countEdges(edgeId, edges); // Delegate to the domain model cardinality rule manager. result.addViolations( edgeCardinalityEvaluationHandler .evaluate(rule, RuleContextBuilder.DomainContexts.edgeCardinality(candidate.getLabels(), edgeId, count, rule.getDirection(), operation)) ); return GraphEvaluationHandlerUtils.addViolationsSourceUUID(edge.getUUID(), result); }