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(); }
/** * 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); }
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 static void addMessage(RuleContext drools, Message.Type type, String msgKey, Object... context) { KieRuntime knowledgeRuntime = drools.getKieRuntime(); ValidationReport validationReport = (ValidationReport) knowledgeRuntime.getGlobal("validationReport"); validationReport.addMessage(MessageFactory.createMessage(type, msgKey, context)); }
/** * 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); }
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, 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, 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); }
protected void registerConstraintMatch(RuleContext kcontext, final Runnable constraintUndoListener, Supplier<Score_> scoreSupplier) { AgendaItem<?> agendaItem = (AgendaItem) kcontext.getMatch(); ConstraintActivationUnMatchListener constraintActivationUnMatchListener = new ConstraintActivationUnMatchListener(constraintUndoListener); agendaItem.setCallback(constraintActivationUnMatchListener); if (constraintMatchEnabled) { List<Object> justificationList = extractJustificationList(kcontext); // Not needed in fast code: Add ConstraintMatch constraintActivationUnMatchListener.constraintMatchTotal = findConstraintMatchTotal(kcontext); ConstraintMatch constraintMatch = constraintActivationUnMatchListener.constraintMatchTotal .addConstraintMatch(justificationList, scoreSupplier.get()); List<Indictment> indictmentList = justificationList.stream() .distinct() // One match might have the same justification twice .map(justification -> { Indictment indictment = indictmentMap.computeIfAbsent(justification, k -> new Indictment(justification, zeroScore)); indictment.addConstraintMatch(constraintMatch); return indictment; }).collect(Collectors.toList()); constraintActivationUnMatchListener.constraintMatch = constraintMatch; constraintActivationUnMatchListener.indictmentList = indictmentList; } }
/** * 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, 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, 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, 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); }