2010/10/14 Navdeep Kumar <span dir="ltr">&lt;<a href="mailto:nkumar@objectwave.com">nkumar@objectwave.com</a>&gt;</span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for your reply...could you please tell me what is this myGlobal? <br><br></blockquote><div><br>java.util.Set&lt;Rule&gt; myGlobal<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote">2010/10/13 Michael Anstis <span dir="ltr">&lt;<a href="mailto:michael.anstis@gmail.com" target="_blank">michael.anstis@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">You could store all rules in a global and remove those that execute in 
an AgendaEventListener&#39;s activtionCreated event (re-adding those that 
get retracted by Truth Maintenance in the AgendaEventListeners 
activationCancelled event).<br>
<br>//Loads rules<br>KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>kbuilder.add(ResourceFactory.newClassPathResource(&quot;myrules.drl&quot;), ResourceType.DRL);<br>KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>


Collection&lt;KnowledgePackage&gt; kpackages = kbuilder.getKnowledgePackages();<br>
kbase.addKnowledgePackages(kpackages);<br>
<br>//Get all rules<br>for(KnowledgePackage kpackage : kpackages) {<br>    for(Rule rule : kpackage.getRules()) {<br>        myGlobal.add(rule);<br>    }<br>}<br><br>//The usual suspects<br>StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();<br>


ksession.addEventListener(new DefaultAgendaEventListener() {<br>    @Override<br>    void activationCreated(ActivationCreatedEvent event) {<br>        myGlobal.remove(event.getActivation().getRule());<br>    }<br><br>    @Override<br>


    void activationCancelled(ActivationCancelledEvent event) {<br>
        myGlobal.add(event.getActivation().getRule());<br>
    }<br>
});<br><br>ksession.fireAllRules();<br><br>You could also use an AgendaEventListener to better manage the contents of the Rule collection for more complex scenarios where Truth Maintenance could retract an activation - that the simpler solution above wold <br>


<br><br><br><div class="gmail_quote">2010/10/13 Navdeep Kumar <span dir="ltr">&lt;<a href="mailto:nkumar@objectwave.com" target="_blank">nkumar@objectwave.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div></div><div>
Hi All,<div><br></div><div>I am new to Drools. I am working on a project where nature of rules are dynamic. I want to capture that rule which does not get executed. i need to store that rule because i have to display that rule in the UI.</div>



<div><br></div><div>Here is my rule file</div><div><br></div><div>rule &quot;FrontAxle:Capacity|FrontSuspension:Capacity&quot;</div><div><div><br></div><div><span style="white-space: pre-wrap;">        </span>when</div>
<div><span style="white-space: pre-wrap;">                </span>b:Feature(featureClass.name==&quot;FrontSuspension&quot;) </div><div><span style="white-space: pre-wrap;">                </span>c:Feature(featureClass.name==&quot;FrontAxle&quot;)</div>


<div><span style="white-space: pre-wrap;">                </span>//eval(b.getCapacity() &gt;= c.getCapacity())</div><div><span style="white-space: pre-wrap;">                </span></div><div><span style="white-space: pre-wrap;">        </span>then</div>
<div><span style="white-space: pre-wrap;">                        </span></div><div><span style="white-space: pre-wrap;">                        </span>System.out.println(&quot;These are compatible&quot;);</div><div><span style="white-space: pre-wrap;">                        </span>System.out.println(b.getFeatureClass().getName());</div>



<div><span style="white-space: pre-wrap;">                        </span>availablity.put(b.getFeatureClass().getName()+&quot;-&quot;+c.getFeatureClass().getName(),&quot;12.35&quot;);</div><div><span style="white-space: pre-wrap;">                        </span>//availablity.put(b.getName()+&quot;-&quot;+c.getName(),new Double(b.getCapacity()));</div>



<div><span style="white-space: pre-wrap;">                        </span> insert(availablity);</div><div><span style="white-space: pre-wrap;">        </span>end</div><div><span style="white-space: pre-wrap;">        </span></div>
<div>rule &quot;FrontSuspension:Type|FrontAxle:Type&quot;<span style="white-space: pre-wrap;">        </span></div><div><span style="white-space: pre-wrap;">        </span></div><div><span style="white-space: pre-wrap;">        </span>when</div>


<div><span style="white-space: pre-wrap;">                </span>b:Feature(featureClass.name==&quot;FrontSuspension&quot;) </div><div><span style="white-space: pre-wrap;">                </span>c:Feature(featureClass.name==&quot;FrontAxle&quot;)</div>


<div><span style="white-space: pre-wrap;">                </span>not Feature(b.attributes.Type==&quot;I Beam&quot; &amp;&amp; c.attributes.Type==&quot;Multi Link Air&quot;)</div><div><span style="white-space: pre-wrap;">        </span>//NOT (FrontAxle.type = &quot;I-Beam&quot; AND FrontSuspension.type = &quot;Multi-link Air&quot;) - mounting restriction<span style="white-space: pre-wrap;">                                                                                </span></div>



<div><span style="white-space: pre-wrap;">        </span>then</div><div><span style="white-space: pre-wrap;">                        </span>System.out.println(&quot;I am in  2&quot;);</div><div><span style="white-space: pre-wrap;">        </span>end</div>


<div><span style="white-space: pre-wrap;">        </span></div><div><span style="white-space: pre-wrap;">        </span></div><div>rule &quot;FrontAxle:FeatureCode|FrontSuspension:Type&quot;</div><div><span style="white-space: pre-wrap;">        </span>when</div>



<div><span style="white-space: pre-wrap;">                </span>b:Feature(featureClass.name==&quot;FrontSuspension&quot;) </div><div><span style="white-space: pre-wrap;">                </span>Feature(featureClass.name==&quot;FrontAxle&quot; &amp;&amp; code==&quot;002ASW&quot;)and not Feature(b.attributes.Type==&quot;Multi Link Air&quot; || b.attributes.Type==&quot;Monoleaf Spring&quot;)</div>



<div><span style="white-space: pre-wrap;">                </span>//FrontAxle.featureCode = &quot;002ASW&quot; AND NOT (FrontSuspension.type = &quot;Multi-link  Air&quot; OR FrontSuspension.type = &quot;Monoleaf Spring&quot;)</div>
<div><span style="white-space: pre-wrap;">        </span>then</div><div><span style="white-space: pre-wrap;">                </span>System.out.println(&quot;I am in 3&quot;);</div><div><span style="white-space: pre-wrap;">        </span>end</div>
</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>now if these two objects named FrontAxle and FrontSuspension are compatible then it has to meet all the 3 rules, but if any combination of these objects does not meet one of the rule listed above then i have to store the rule for the displaying purpose that this combination didn&#39;t meet this rule thats why they are not compatible. any kind of help will be appreciated.</div>



<div><br></div><div><br></div><div><br></div><div>Thanks.</div>
<br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>