protected List<Object> extractJustificationList(RuleContext kcontext) { // Unlike kcontext.getMatch().getObjects(), this includes the matches of accumulate and exists return ((org.drools.core.spi.Activation) kcontext.getMatch()).getObjectsDeep(); }
protected boolean checkDeclarationMatch(Match match, String matchVariable) { if (matchVariable == null) { // no extra check is needed return true; } Object dec = match.getDeclarationIds().contains("$" + matchVariable) ? match.getDeclarationValue("$" + matchVariable) : match.getDeclarationValue(matchVariable); Object var = getVariable(matchVariable); boolean check = var.equals(dec); return check; }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, int weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Integer> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
public boolean accept(Match activation) { return !"Cancel".equals(activation.getRule().getName()); } }
protected RuleContext mockRuleContext(Rule rule, Object... justifications) { if (justifications.length == 0) { justifications = new Object[]{DEFAULT_JUSTIFICATION}; } List<Object> justificationList = Arrays.asList(justifications); RuleContext kcontext = mock(RuleContext.class); AgendaItemImpl<TestModedAssertion> agendaItem = new AgendaItemImpl<TestModedAssertion>() { @Override public List<Object> getObjects() { return justificationList; } @Override public List<Object> getObjectsDeep() { return justificationList; } }; when(kcontext.getMatch()).thenReturn(agendaItem); when(kcontext.getRule()).thenReturn(rule); return kcontext; }
public void afterRuleFlowGroupDeactivated(final RuleFlowGroupDeactivatedEvent event) { if (kruntime instanceof StatefulKnowledgeSession) { signalManager.signalEvent( "RuleFlowGroup_" + event.getRuleFlowGroup().getName() + "_" + ((StatefulKnowledgeSession) kruntime).getIdentifier(), null ); } else { signalManager.signalEvent( "RuleFlowGroup_" + event.getRuleFlowGroup().getName(), null ); } } } );
public boolean accept(Match activation) { RuleImpl rule = (RuleImpl)activation.getRule(); if (currentSalience == null){ currentSalience = rule.getSalience() != null ? Integer.valueOf(rule.getSalience().toString()) : 0; } boolean nocancel = currentSalience >= Integer.valueOf(rule.getSalience().toString()); if(!nocancel){ logger.info("cancelling -> {}", rule.getName()); } return nocancel; } }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, BigDecimal weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, BigDecimal> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
protected void callOnUpdate(RuleContext ruleContext) { AgendaItem<?> agendaItem = (AgendaItem) ruleContext.getMatch(); agendaItem.getCallback().run(); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, double weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Double> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
protected void callOnDelete(RuleContext ruleContext) { AgendaItem<?> agendaItem = (AgendaItem) ruleContext.getMatch(); agendaItem.getCallback().run(); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, long weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Long> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, double weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Double> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, int weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Integer> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, BigDecimal weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, BigDecimal> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, long weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Long> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, long weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Long> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, BigDecimal weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, BigDecimal> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight} multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void reward(RuleContext kcontext, long weightMultiplier) { Rule rule = kcontext.getRule(); BiConsumer<RuleContext, Long> matchExecutor = matchExecutorByNumberMap.get(rule); if (matchExecutor == null) { throw new IllegalStateException("The DRL rule (" + rule.getPackageName() + ":" + rule.getName() + ") does not match a @" + ConstraintWeight.class.getSimpleName() + " on the @" + ConstraintConfiguration.class.getSimpleName() + " annotated class."); } matchExecutor.accept(kcontext, weightMultiplier); }
private ConstraintMatchTotal findConstraintMatchTotal(RuleContext kcontext) { Rule rule = kcontext.getRule(); String constraintPackage = rule.getPackageName(); String constraintName = rule.getName(); String constraintId = constraintPackage + "/" + constraintName; return constraintMatchTotalMap.computeIfAbsent(constraintId, k -> new ConstraintMatchTotal(constraintPackage, constraintName, null, zeroScore)); }