2010/10/14 Navdeep Kumar <span dir="ltr"><<a href="mailto:nkumar@objectwave.com">nkumar@objectwave.com</a>></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<Rule> 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"><<a href="mailto:michael.anstis@gmail.com" target="_blank">michael.anstis@gmail.com</a>></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'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("myrules.drl"), ResourceType.DRL);<br>KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>
Collection<KnowledgePackage> 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"><<a href="mailto:nkumar@objectwave.com" target="_blank">nkumar@objectwave.com</a>></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 "FrontAxle:Capacity|FrontSuspension:Capacity"</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=="FrontSuspension") </div><div><span style="white-space: pre-wrap;">                </span>c:Feature(featureClass.name=="FrontAxle")</div>
<div><span style="white-space: pre-wrap;">                </span>//eval(b.getCapacity() >= 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("These are compatible");</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()+"-"+c.getFeatureClass().getName(),"12.35");</div><div><span style="white-space: pre-wrap;">                        </span>//availablity.put(b.getName()+"-"+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 "FrontSuspension:Type|FrontAxle:Type"<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=="FrontSuspension") </div><div><span style="white-space: pre-wrap;">                </span>c:Feature(featureClass.name=="FrontAxle")</div>
<div><span style="white-space: pre-wrap;">                </span>not Feature(b.attributes.Type=="I Beam" && c.attributes.Type=="Multi Link Air")</div><div><span style="white-space: pre-wrap;">        </span>//NOT (FrontAxle.type = "I-Beam" AND FrontSuspension.type = "Multi-link Air") - 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("I am in 2");</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 "FrontAxle:FeatureCode|FrontSuspension:Type"</div><div><span style="white-space: pre-wrap;">        </span>when</div>
<div><span style="white-space: pre-wrap;">                </span>b:Feature(featureClass.name=="FrontSuspension") </div><div><span style="white-space: pre-wrap;">                </span>Feature(featureClass.name=="FrontAxle" && code=="002ASW")and not Feature(b.attributes.Type=="Multi Link Air" || b.attributes.Type=="Monoleaf Spring")</div>
<div><span style="white-space: pre-wrap;">                </span>//FrontAxle.featureCode = "002ASW" AND NOT (FrontSuspension.type = "Multi-link Air" OR FrontSuspension.type = "Monoleaf Spring")</div>
<div><span style="white-space: pre-wrap;">        </span>then</div><div><span style="white-space: pre-wrap;">                </span>System.out.println("I am in 3");</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'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>