Can somebody plz look in to this?
I'm writing a java standalone program to test my rules. This is reading in
32 of properties (name/value pairs) from property file and then takes those
name value pairs and creates a Java object (bean). Then this object is
inserted in the session and sent to the rule engine to fire rules, which
based on some conditions ...fires a set of rule.
What happening is that my unit tests are running fine but similar object
created from property file (same value of properties), no rule is getting
fired. I've checked that all the properties of the java bean is getting set
in the main() and when I send this object to rule engine....it enters the
method of ruleEngine but no rule gets fired....
Take a look at the shortened version of code:
public class DroolsTest {
private static StatefulSession sess = null;
private static FileInputStream in;
private static Properties props=null;
private static Person p;
public static void readPropertyFiles(File f)
{
FileInputStream in = new FileInputStream(f);
props = new Properties();
props.load(in);
initializeProperty(props);
}catch(Exception e){}
}
private static void initializeProperty(Properties properties)
{
p = new Person();
p.setSourceType(properties.getProperty("RecordType"));
p.setAge(new Long(properties.getProperty("Age")));
p.setFattyFood(properties.getProperty("FattyFood"));
}
public static void main(String[] args) {
sess = RuleEngine.getSession();
readPropertyFiles(files[i]);
sess.insert(p);
RuleEngine.fireSelectedRules(p, sess);
writeResult(p);
System.out.println("going to close session");
RuleEngine.cleanUp(sess);
}
}
Rule Engine is like this:
public static StatefulSession getSession()
{
StratificationLogging.logInfo(RuleEngine.class,"Creating a new
StatefulSession");
StatefulSession session=null;
try{
session = ruleBase.newStatefulSession();
// setup the debug listeners
session.addEventListener( new DebugAgendaEventListener() );
session.addEventListener( new DebugWorkingMemoryEventListener() );
// setup the audit logging
logger = new WorkingMemoryFileLogger( session );
logger.setFileName( "../log/auditlog.txt" );
}catch(Exception e){
StratificationLogging.logError(e);
}
StratificationLogging.logInfo(RuleEngine.class,"Returned a new Stateful
session");
return session;
}
/**
* Fires Rules based on presence/absence of policy and the source type
* @param personToArray
*/
public static void fireSelectedRules(Person person, StatefulSession
session) {
int len = person.getPolicy().length();
if(len > 0){
System.out.println("Entered fire all rules");
session.fireAllRules();
}
if(len==0 && policy.trim().equalsIgnoreCase("WORKSITE")){
System.out.println("Entered to fire worksite rules");
session.fireAllRules(new RuleNameStartsWithAgendaFilter("WORKSITE_WC"));}
}
/**
* can be called to dispose off the session
* also to write log to disk
*/
public static void cleanUp(StatefulSession session)
{
logger.writeToDisk();
session.dispose();
}
--
View this message in context:
http://www.nabble.com/Rule-not-firing-for-same-object-through-java-main%2...
Sent from the drools - user mailing list archive at
Nabble.com.