[rules-users] Runing Rules in Two Phases ( using AgendaFilters ) with inference

Wolfgang Laun wolfgang.laun at gmail.com
Mon Aug 12 04:49:09 EDT 2013


Use agenda groups, not agenda filters. The latter will fire your rules
as "blanks" whereas agenda groups are just the thing for letting rules
fire in controlled stages.

(And: please refrain from posting twice.)

-W

On 12/08/2013, viraj <mayuraviraj at gmail.com> wrote:
> Hi all,
>
> I have problem with using AgendaFilters to select rules when rules written
> to use inference. First I will try to explain the situation. In my project
> I
> have two sets of rules. First set is eligible rules which run to evaluate
> eligibility of products and second phase is selection rules which run on
> results of eligible products.
>
> Ex : Eligible Rule
> package rule.eligible
> rule "Eligible Rule 1 - 3 "
> no-loop true
> when
> $evaluationResults : EvaluationResults( validProducts not contains "3" );
> UserProfile( status == 1 ) // other conditions
> then
>   modify( $evaluationResults ) { addIntoEvaluatedProducts(3 + ""  ) } ; //
> Add into validProducts HashSet
> end
>
> Ex: Selection Rule
> package rule.selection
> rule "Selection Rule - 1"
> no-loop true
> when
>   $evaluationResults  : EvaluationResults( validOffers.keySet not contains
> "1" ,  validProducts contains "3" ) // Other conditions
> then
>   modify( $evaluationResults ){ addIntoEvaluatedOffers("1", "3")} //Add
> into
> validOffers Map
> end;
>
> when i use fireAllRule() the above rules run correctly. Now I want to run
> only eligible rules and later selection rules since in some scenarios I
> need
> only valid products. So I tried using following code
>
> Run only eligible rules which rule name start with "Eligible Rule"
> statefulKnowledgeSession.fireAllRules(DroolsHelper.getActivatedRulesFromRuleStartWith("Eligible
> Rule"));
>
> Run only selection rules which rule name start with "Selection Rule"
> statefulKnowledgeSession.fireAllRules(DroolsHelper.getActivatedRulesFromRuleStartWith("Selection
> Rule"));
>
> Method DroolsHelper.getActivatedRulesFromRuleStartWith
>     public static AgendaFilter getActivatedRulesFromRuleStartWith(final
> String startWith) {
>         AgendaFilter filter = new AgendaFilter() {
>             public boolean accept(Activation activation) {
>                 FactHandle objects =
> activation.getPropagationContext().getFactHandle() ;
>                 if (activation.getRule().getName().startsWith(startWith)) {
>                     return true;
>                 }
>                 return false;
>             }
>         };
>         return filter;
>     }
>
> I checked rule execution using KnowledgeRuntimeLogger. It shows eligible
> rules correctly activate selection rules but when I run selection rules
> only, it does not get executed. Is there a way do this kind of task ?
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Runing-Rules-in-Two-Phases-using-AgendaFilters-with-inference-tp4025460.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list