use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class ConditionalBranchBuilder method buildConditionalBranchEvaluator.
private ConditionalBranchEvaluator buildConditionalBranchEvaluator(BuildContext context, ConditionalBranch conditionalBranch) {
RuleTerminalNode terminalNode = buildTerminalNodeForNamedConsequence(context, conditionalBranch.getNamedConsequence());
terminalNode.networkUpdated(new UpdateContext());
// adds the terminal node to the list of nodes created/added by this sub-rule
context.getNodes().add(terminalNode);
return new ConditionalBranchEvaluator(conditionalBranch.getEvalCondition(), context.getTupleSource().getPartitionId(), terminalNode, conditionalBranch.getNamedConsequence().isBreaking(), conditionalBranch.getElseBranch() != null ? buildConditionalBranchEvaluator(context, conditionalBranch.getElseBranch()) : null);
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class NamedConsequenceBuilder method buildTerminalNodeForNamedConsequence.
static RuleTerminalNode buildTerminalNodeForNamedConsequence(BuildContext context, NamedConsequence namedConsequence) {
RuleImpl rule = context.getRule();
GroupElement subrule = (GroupElement) context.peek();
ActivationListenerFactory factory = context.getKnowledgeBase().getConfiguration().getActivationListenerFactory(rule.getActivationListener());
context.setConsequenceName(namedConsequence.getConsequenceName());
TerminalNode terminal = factory.createActivationListener(context.getNextId(), context.getTupleSource(), rule, subrule, // subruleIndex,
0, context);
context.setConsequenceName(null);
return (RuleTerminalNode) terminal;
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class RuleTest method testRuleEnabled.
@Test
public void testRuleEnabled() {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
rule.setEnabled(EnabledBoolean.ENABLED_FALSE);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar past = Calendar.getInstance();
past.setTimeInMillis(10);
rule.setDateEffective(past);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
rule.setEnabled(EnabledBoolean.ENABLED_TRUE);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class RuleTest method testDateEffectiveExpires.
@Test
public void testDateEffectiveExpires() {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
final Calendar past = Calendar.getInstance();
past.setTimeInMillis(10);
final Calendar future = Calendar.getInstance();
future.setTimeInMillis(future.getTimeInMillis() + 100000000);
rule.setDateEffective(past);
rule.setDateExpires(future);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
rule.setDateExpires(past);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
rule.setDateExpires(future);
rule.setDateEffective(future);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.reteoo.RuleTerminalNode in project drools by kiegroup.
the class RuleTest method testDateEffective.
@Test
public void testDateEffective() {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar earlier = Calendar.getInstance();
earlier.setTimeInMillis(10);
rule.setDateEffective(earlier);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar later = Calendar.getInstance();
later.setTimeInMillis(later.getTimeInMillis() + 100000000);
assertTrue(later.after(Calendar.getInstance()));
rule.setDateEffective(later);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
}
Aggregations