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; } }
public static void addRule(String ruleName, RuleImpl firingRule) throws Exception { String rule = rules.get(ruleName); CommonTestMethodBase testBaseMethod = new CommonTestMethodBase(); kbase.addPackages(testBaseMethod.loadKnowledgePackagesFromString( rule )); if (firingRule != null) { kbase.removeRule("defaultpkg", firingRule.getName()); } }
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { if ( act.getRule().getName().equals( "rule3" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() ); } else if ( act.getRule().getName().equals( "rule1" ) ) { list.add( act.getRule().getName() + ":" + act.isQueued() ); } else if ( act.getRule().getName().equals( "rule2" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { if ( act.getRule().getName().equals( "rule3" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.getDeclarationValue( "$s2" ) + ":" + act.getDeclarationValue( "$s3" ) + ":" + act.isQueued() ); } else if ( act.getRule().getName().equals( "rule1" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.getDeclarationValue( "$s2" ) + ":" + act.isQueued() ); } else if ( act.getRule().getName().equals( "rule2" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { if ( act.getRule().getName().equals( "rule3" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() ); } else if ( act.getRule().getName().equals( "rule1" ) ) { list.add( act.getRule().getName() + ":" + act.isQueued() ); } else if ( act.getRule().getName().equals( "rule2" ) ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() );
Iterator it = TerminalNodeIterator.iterator(kbase); for ( TerminalNode node = (TerminalNode) it.next(); node != null; node = (TerminalNode) it.next() ) { nodes.add( ((RuleTerminalNode) node).getRule().getName() );
list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() );
@Test public void testEmptyRule() throws Exception { String rule = "package org.drools.compiler.test;\n"; rule += "global java.util.List list\n"; rule += "rule \"Rule 1\"\n"; rule += "when\n"; rule += "then\n"; rule += " list.add( \"fired\" );\n"; rule += "end"; KieBase kBase = loadKnowledgeBaseFromString( rule ); // Make sure the rete node map is created correctly Map<Integer, BaseNode> nodes = RuleBaseNodes.getNodeMap((InternalKnowledgeBase) kBase); assertEquals( 2, nodes.size() ); assertEquals( "InitialFactImpl", ((ClassObjectType) ((ObjectTypeNode) nodes.get( 2 )).getObjectType()).getClassType().getSimpleName() ); assertEquals( "Rule 1", ((RuleTerminalNode) nodes.get( 4 )).getRule().getName() ); KieSession session = kBase.newKieSession(); List list = new ArrayList(); session.setGlobal( "list", list ); session = SerializationHelper.getSerialisedStatefulKnowledgeSession( session, kBase, true ); session.fireAllRules(); session = SerializationHelper.getSerialisedStatefulKnowledgeSession( session, kBase, true ); assertEquals( 1, ((List) session.getGlobal( "list" )).size() ); assertEquals( "fired", ((List) session.getGlobal( "list" )).get( 0 ) ); }
((ClassObjectType) ((ObjectTypeNode) nodes.get( 3 )).getObjectType()).getClassType().getSimpleName() ); assertEquals( "Rule 1", ((RuleTerminalNode) nodes.get( 5 )).getRule().getName() );
list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.isQueued() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() ); list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.getDeclarationValue( "$s2" ) + ":" + act.isQueued() ); list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.getDeclarationValue( "$s2" ) + ":" + act.isQueued() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() ); list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.getDeclarationValue( "$s2" ) + ":" + act.isQueued() ); list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s1" ) + ":" + act.getDeclarationValue( "$s2" ) + ":" + act.isQueued() );
RuleTerminalNode remainingRTN = rtn1.getRule().getName().equals( "yyy" ) ? rtn1 : rtn2; assertTrue( asList(rian.getPathEndNodes()).containsAll( asList(remainingRTN, rian) ) );
((ClassObjectType) ((ObjectTypeNode) nodes.get( 2 )).getObjectType()).getClassType().getSimpleName() ); assertEquals( "Rule 1", ((RuleTerminalNode) nodes.get( 4 )).getRule().getName() );
List list = new ArrayList(); for ( AgendaItem act = (AgendaItem) it.next(); act != null; act = (AgendaItem) it.next() ) { list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() ); list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() );
LeftTuple first = handle.getFirstLeftTuple(); assertTrue( first instanceof RuleTerminalNodeLeftTuple ); assertEquals( "Check", ((RuleTerminalNodeLeftTuple) first).getRule().getName() );
list.add( act.getRule().getName() + ":" + act.getDeclarationValue( "$s" ) + ":" + act.isQueued() );
private RuleImpl createRule( final ConditionalElementDescr ceDescr, final KnowledgeBuilderImpl builder, final String consequence ) throws Exception { final PackageDescr packageDescr = new PackageDescr( "p1" ); final RuleDescr ruleDescr = new RuleDescr( "rule-1" ); packageDescr.addRule( ruleDescr ); final AndDescr lhs = new AndDescr(); ruleDescr.setLhs( lhs ); lhs.addDescr( (BaseDescr) ceDescr ); final PatternDescr patternDescr = new PatternDescr( Cheese.class.getName(), "stilton" ); patternDescr.addConstraint( new ExprConstraintDescr( "type == \"stilton\" ") ); ceDescr.addDescr( patternDescr ); ruleDescr.setConsequence( consequence ); builder.addPackage( packageDescr ); InternalKnowledgePackage pkg = builder.getPackage(packageDescr.getName()); final RuleImpl rule = pkg.getRule( "rule-1" ); assertEquals( "rule-1", rule.getName() ); return rule; }