@Before public void setup() throws Exception { context = RuleContextBuilder.DomainContexts.containment(Collections.singleton("id1"), Collections.emptySet()); violation1 = new RuleViolationImpl("v1"); violations1 = new DefaultRuleViolations().addViolation(violation1); when(handler1.getRuleType()).thenReturn(RuleExtension.class); when(handler1.getContextType()).thenReturn(ContainmentContext.class); when(handler2.getRuleType()).thenReturn(RuleExtension.class); when(handler2.getContextType()).thenReturn(ContainmentContext.class); tested = new RuleExtensionMultiHandler(); tested.addHandler(handler1); tested.addHandler(handler2); }
@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())); }
add("role2"); }}); ruleEvaluationContext = RuleContextBuilder.DomainContexts.containment(Collections.singleton("r1-cId"), new HashSet<String>(1) {{ add("r2-cId");
protected ParentAssignment getParentAssignment(final Node<View<?>, Edge> parent, final Object definition) { Objects.requireNonNull(definition); final Set<String> labels = clientDefinitionManager.adapters().forDefinition().getLabels(definition); final RuleSet ruleSet = canvasHandler.getRuleSet(); // Check containment rules. if (null != parent) { final Set<String> parentLabels = parent.getLabels(); final RuleViolations dockingViolations = ruleManager.evaluate(ruleSet, RuleContextBuilder.DomainContexts.docking(parentLabels, labels)); if (isValid(dockingViolations)) { return ParentAssignment.DOCKING; } final RuleViolations containmentViolations = ruleManager.evaluate(ruleSet, RuleContextBuilder.DomainContexts.containment(parentLabels, labels)); if (isValid(containmentViolations)) { return ParentAssignment.CONTAINMENT; } } return ParentAssignment.NONE; }
@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); } }