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; } }
context, context.getRule(), context.getRule().getSalience(), new Person( "bob" + i, 30 + (i * 3) ) );
@Test public void testSimpleExpression() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); final Person p = new Person( "mark", "", 31 ); final InternalFactHandle f0 = (InternalFactHandle) ksession.insert( p ); final LeftTupleImpl tuple = new LeftTupleImpl( f0, null, true ); RuleTerminalNode rtn = new RuleTerminalNode(); rtn.setSalienceDeclarations( context.getDeclarationResolver().getDeclarations( context.getRule() ).values().toArray( new Declaration[1] ) ); AgendaItem item = new AgendaItemImpl(0, tuple, 0, null, rtn, null); assertEquals( 25, context.getRule().getSalience().getValue( new DefaultKnowledgeHelper( item, ksession ), context.getRule(), ksession ) ); }
((MVELSalienceExpression) context.getRule().getSalience()).compile( (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" ) );
@Test public void test() { // RULE CheeseWorld_11 has salience "=3+2" RuleImpl cheeseWorld11 = (RuleImpl) kieBase.getRule( "test", "CheeseWorld_11" ); assertEquals( 5, cheeseWorld11.getSalience().getValue() ); // RULE CheeseWorld_12 has salience "=ROW()" RuleImpl cheeseWorld12 = (RuleImpl) kieBase.getRule( "test", "CheeseWorld_12" ); assertEquals( 12, cheeseWorld12.getSalience().getValue() ); } }