The global ao must be assigned to the ksession, from your Java code, by
calling
ksession.setGlobal( "ao", assertionObject )
before you do anything that triggers LHS evaluations. See Drools Expert,
section 4.5.2.
The WM and rule setup as you present it does not make sense (to me). If you
insert an AssertionObject as a WM fact, you shouldn't have it as a global.
If you want it as a fact, you'll need rules with patterns like
when
AssertionObject(...)
And the same goes for BillingRecord
-W
2009/8/1 Abarna Ramachandran <rabarna(a)archstone.in>
I am getting the following error when trying to insert my object
into
ksession. I have attached my rules and java object. Please help me in
debugging why this is happening. I am using java 5 and drools 5.0
thanks
*error while inserting:*
org.drools.RuntimeDroolsException:
defaultpkg.Rule_CheckStationNumber_0Eval0Invoker@e4aea391 :
java.lang.NullPointerException
*rules.drl*
import java.lang.*;
import java.util.*;
import ct.fw.rules.*;
import ct.fw.utils.*;
import ct.fw.rules.*;
import ct.fw.logging.*;
import ct.fw.pf.dbi.*;
import ct.fw.pf.dao.*;
import ct.fw.pf.seq.*;
import ct.fw.pf.util.*;
import ct.fw.pf.vo.*;
import ct.fw.ex.*;
import org.apache.commons.lang.*;
import com.aa.gccp.domain.*;
global ct.fw.rules.AssertionObject ao
global ct.fw.logging.SmartLogger log
function BillingRecord getRecord(AssertionObject ao)
{
return (BillingRecord) ao.get(0);
}
function void debug(String msg,SmartLogger log)
{
log.debug(BusinessRulesValidator.class, msg);
}
function void error(String msg,SmartLogger log)
{
log.error(BusinessRulesValidator.class, msg);
System.out.println("Message from rules "+msg);
}
rule CheckTrue
when
eval(true)
then
System.out.println("evaluating true");
end
rule CheckTrue2
when
eval(true)
then
error("evaluating from rules2",log);
end
rule CheckStationNumber
when
eval(((getRecord(ao)).getStationNo()) == null)
then
error("station number should not be null",log);
end
*part where i load the rules and insert the facts. There is no error when
loading the rules.drl. That means no parsing errors. The error happens at
ksessio.insert(assertionObject).*
public void assertRulesObject(AssertionObject assertionObject) throws
BusinessRuleException
{
long current = System.currentTimeMillis();
KnowledgeBase kbase = knowledgeBasesMap.get(rulesFileName);
if (kbase == null)
{
kbase = knowledgeBasesMap.get(rulesFileName + DRL);
}
if ((kbase == null) || ((current - lastRefreshedMilliseconds) >
refreshTimeMilliseconds))
{
if (rulesFileName.toLowerCase().indexOf(DRL) == -1)
{
kbase = load(rulesFileName + DRL);
}
else
{
kbase = load(rulesFileName);
}
lastRefreshedMilliseconds = System.currentTimeMillis();
}
this.assertionObject = assertionObject;
List assertionobjectslist = new ArrayList();
*// i am just doing this part just to make sure assertion object is not
null and i will get some answer. this part runs fine. *
if (assertionObject != null)
{
assertionobjectslist = assertionObject.getValidationObjects();
String StationNumber = ((BillingRecord)
assertionObject.get(0)).getStationNo();
System.out.println("Station Number in assertion object is " +
StationNumber);
}
else
{
System.out.println("Assertion Object is null");
}
System.out.println("The number of objects in assertionobject is " +
assertionobjectslist.size());
try
{
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
*//the next line throws the exception*
ksession.insert(assertionObject);
ksession.fireAllRules();
ksession.dispose();
}
catch (RuntimeDroolsException e1)
{
throw new BusinessRuleException(e1.getMessage());
}
businessRulesErrors = assertionObject.getBusinessRulesErrors();
if (throwException)
{
if (!assertionObject.getBusinessRulesErrors().isEmpty())
{
throw new BusinessRuleException(businessRulesErrors);
}
}
}
Any help is appreciated. thanks
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users