Search in sources :

Example 31 with RuleTerminalNode

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);
}
Also used : ConditionalBranchEvaluator(org.drools.core.reteoo.ConditionalBranchEvaluator) UpdateContext(org.drools.core.common.UpdateContext) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 32 with RuleTerminalNode

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;
}
Also used : GroupElement(org.drools.core.rule.GroupElement) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ActivationListenerFactory(org.drools.core.ActivationListenerFactory) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) TerminalNode(org.drools.core.reteoo.TerminalNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 33 with RuleTerminalNode

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));
}
Also used : WorkingMemory(org.drools.core.WorkingMemory) Calendar(java.util.Calendar) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 34 with RuleTerminalNode

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));
}
Also used : WorkingMemory(org.drools.core.WorkingMemory) Calendar(java.util.Calendar) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 35 with RuleTerminalNode

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));
}
Also used : WorkingMemory(org.drools.core.WorkingMemory) Calendar(java.util.Calendar) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Aggregations

RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)69 Test (org.junit.Test)54 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)38 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)30 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)28 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)23 KieBase (org.kie.api.KieBase)23 SegmentMemory (org.drools.core.reteoo.SegmentMemory)18 JoinNode (org.drools.core.reteoo.JoinNode)16 PathMemory (org.drools.core.reteoo.PathMemory)16 ArrayList (java.util.ArrayList)14 ClassObjectType (org.drools.core.base.ClassObjectType)13 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)13 List (java.util.List)12 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)11 WorkingMemory (org.drools.core.WorkingMemory)10 RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)9 FactHandle (org.kie.api.runtime.rule.FactHandle)9 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)9 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)8