Drools rules not getting fired
by arunodhaya80
(Sorry about the repost. Was rejected earlier from the mailing list for lack
of subscription)
I am pretty new to Drools and am probably doing something really silly. The
problem is that for some reason my Drools rules are not getting fired.
If it helps, the rules fire when I shift back to a StatelessKnowledgeSession
and use the execute method to fire the rules. However, I need to use
AgendaFilter to filter rules and I understand that agenda filters aren't
supported on StatelessKnowledgeSession yet. As a first step, I just flipped
the session to a StatefulKnowledgeSession, inserted the facts and fired all
the rules.
Had to humbly say that I was breaking my head for the past couple of days on
this. Too bad, the documentation isn't that friendly for drools (I refer to
the official documentation and the user guide.
The Rule Validator code and the Spring factory bean with which I load the
Knowledge from the rule file is quoted below. I, personally, don't see any
issues with the FactoryBean. Any pointers would be of great help.
RuleValidator.java
StatefulKnowledgeSession ksession =
knowledgeBase.newStatefulKnowledgeSession();
ksession.setGlobal("validationReport", validationReport);
ksession.setGlobal("simpleCache", simpleCache);
ksession.setGlobal("ruleValidator", this);
ksession.insert(allClientDetails); //this is a list of ClientDetails objects
(facts)
ksession.fireAllRules();
ksession.dispose();
return validationReport;
KnowledgeBaseFactory.java
import java.io.IOException;
import java.util.Map;
import org.apache.log4j.Logger;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.springframework.beans.factory.FactoryBean;
public class KnowledgeBaseFactory implements FactoryBean<KnowledgeBase> {
private static Logger
logger=Logger.getLogger(KnowledgeBaseFactory.class);
private KnowledgeBase knowledgeBase;
public KnowledgeBaseFactory(Map<String,ResourceType> resourceMap) throws
IOException {
logger.debug("Resource Map : "+resourceMap);
final KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
for (Map.Entry<String, ResourceType>
eachRuleResource:resourceMap.entrySet()){
knowledgeBuilder.add(ResourceFactory.newClassPathResource(eachRuleResource.getKey()),eachRuleResource.getValue());
}
if (knowledgeBuilder.hasErrors()){
logger.error(knowledgeBuilder.getErrors().toString());
throw new
RuntimeException(knowledgeBuilder.getErrors().toString());
}
knowledgeBase = knowledgeBuilder.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
}
@Override
public KnowledgeBase getObject() throws Exception {
return knowledgeBase;
}
@Override
public Class<?> getObjectType() {
return knowledgeBase.getClass();
}
@Override
public boolean isSingleton() {
return true;
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-rules-not-getting-fired-tp401952...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Insert global into working memory via Spring?
by dunnlow
I am using the drools 5.4 Integration Server (with Guvnor).
I have two instances of the Integration Server and (ideally) one instance of
the rules in Guvnor. I would like to create some rules that depend on the
instance of the Integration Server on which they are running. The vision is
that I would set a global variable somewhere that provided the server name
then use that variable in my rules.
I thought about adding a global variable via guvnor package configuration,
but I can only declare it (not set it). Also, if I could do that, I would
need another knowledge base, which I am trying to avoid.
I am considering setting up a declared object (so that the rule just fires
once) and a rule that if the object doesnt exist, creates it and calls a
function that checks a System Property and sets the value (I know, I've read
not to set globals in rules). If this rule has a high salience, this seems
like it could work - but is REALLY ugly.
Is there a better way?
Basically, I think I want to inject that value into the knowledge session
via Spring.
Thanks for any thoughts,
-J
--
View this message in context: http://drools.46999.n3.nabble.com/Insert-global-into-working-memory-via-S...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months