use of org.drools.core.definitions.rule.impl.RuleImpl 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.definitions.rule.impl.RuleImpl 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));
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class ReteooBuilder method removeRules.
public synchronized void removeRules(Collection<RuleImpl> rulesToBeRemoved) {
// reset working memories for potential propagation
InternalWorkingMemory[] workingMemories = this.kBase.getWorkingMemories();
for (RuleImpl rule : rulesToBeRemoved) {
if (rule.hasChildren() && !rulesToBeRemoved.containsAll(rule.getChildren())) {
throw new RuntimeException("Cannot remove parent rule " + rule + " without having removed all its chikdren");
}
final RuleRemovalContext context = new RuleRemovalContext(rule);
context.setKnowledgeBase(kBase);
BaseNode[] rulesTerminalNodes = rules.remove(rule.getFullyQualifiedName());
if (rulesTerminalNodes == null) {
// there couldn't be any rule to be removed if it comes from a broken drl
continue;
}
for (BaseNode node : rulesTerminalNodes) {
removeTerminalNode(context, (TerminalNode) node, workingMemories);
}
if (rule.isQuery()) {
this.queries.remove(rule.getName());
}
if (rule.getParent() != null && !rulesToBeRemoved.contains(rule.getParent())) {
rule.getParent().removeChild(rule);
}
}
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class QueryTerminalNodeVisitor method doVisit.
@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
QueryTerminalNode rtn = (QueryTerminalNode) node;
RuleImpl rule = rtn.getRule();
// first thing, associate all nodes belonging to this rule
for (NetworkNode snode : nodeStack) {
info.assign(snode, rule);
}
// Query Terminal Nodes no longer have memory
// TODO delete this
// final LinkedList<?> memory = (LinkedList<?>) info.getSession().getNodeMemory( rtn );
// final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo( node );
// ni.setMemoryEnabled( true );
// ni.setTupleMemorySize( memory.size() );
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleTerminalNodeVisitor method doVisit.
@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
RuleTerminalNode rtn = (RuleTerminalNode) node;
RuleImpl rule = rtn.getRule();
// first thing, associate all nodes belonging to this rule
for (NetworkNode snode : nodeStack) {
info.assign(snode, rule);
}
final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo(node);
ni.setMemoryEnabled(false);
}
Aggregations