Rule not firing for same object through java main() but runs okay with Junit tests
by vanshi
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.
16 years
Guvnor - bind variables not working
by David Sinclair
Has anyone had any problems with bind variables in the M2 version of Guvnor
using the business rules editor? If I try and set a bind variable for a
property, it always assigns it to the "main" object, not the property.
For example, if I try to write the following
Foo( bar != null)
And tried to assign the bar property the variable name $bar, Guvnor always
does this
$bar : Foo (bar != null)
I am using FireFox 3.0.3. Anyone else experience this?
dave
16 years
use multiple drl files with a dsl
by Thierry B
Hello,
I try to use several drl files declared with same package with a dsl, but
it doesn't work.
java.lang.RuntimeException: ExempleTest6.java *****************: Unable to
compile drl files.....
at com.pv.rules.test.Exemple6Test.readRule(Exemple6Test.java:85)
at com.pv.rules.test.Exemple6Test.test1(Exemple6Test.java:35)
at com.pv.rules.test.Exemple6Test.main(Exemple6Test.java:26)
I have an Unexpected token from a word that I've define on my dsl which
works if I use only one drl file.
I used that to check errors:
// Check the builder for errors
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "ExempleTest6.java
*****************:
Unable to compile drl files.....");
}
I use that in my java readRule method :
private static RuleBase readRule() throws Exception {
Reader source1 = new InputStreamReader(
Exemple6Test.class.getResourceAsStream( "/com/pv/rules/drl/Exemple61.drl"
) );
Reader source2 = new InputStreamReader(
Exemple6Test.class.getResourceAsStream(
"/com/pv/rules/drl/Exemple62.drl" ) );
Reader dsl = new InputStreamReader(
Exemple6Test.class.getResourceAsStream(
"/com/pv/rules/dsl/XPathLanguageExemple4.dsl" ) );
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source1, dsl );
builder.addPackageFromDrl( source2, dsl );
builder.addPackageFromDrl( source3, dsl );
// Check the builder for errors
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "ExempleTest6.java *****************:
Unable to compile drl files.....");
}
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
Do you have an idea ?
Thanks :-)
PS: Sorry for the previous message, I sent it in error, I didn't finish to
type it.
16 years
use multiple drl files and dsl
by Thierry B
Hello,
I try to use several drl files declared with same package with a dsl, but
it doesn't work.
java.lang.RuntimeException: ExempleTest6.java *****************: Unable to
compile drl files.....
at com.pv.rules.test.Exemple6Test.readRule(Exemple6Test.java:85)
at com.pv.rules.test.Exemple6Test.test1(Exemple6Test.java:35)
at com.pv.rules.test.Exemple6Test.main(Exemple6Test.java:26)
I have an Unexpected token from a word that I've define on my dsl which
works if I use only one drl file.
I used that to check errors:
// Check the builder for errors
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "ExempleTest6.java *****************:
Unable to compile drl files.....");
}
I use that in my java method :
private static RuleBase readRule() throws Exception {
Reader source1 = new InputStreamReader(
Exemple6Test.class.getResourceAsStream( "/com/pv/rules/drl/Exemple61.drl"
) );
Reader source2 = new InputStreamReader(
Exemple6Test.class.getResourceAsStream(
"/com/pv/rules/drl/Exemple62.drl" ) );
Reader dsl = new InputStreamReader(
Exemple6Test.class.getResourceAsStream(
"/com/pv/rules/dsl/XPathLanguageExemple4.dsl" ) );
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source1, dsl );
builder.addPackageFromDrl( source2, dsl );
builder.addPackageFromDrl( source3, dsl );
// Check the builder for errors
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "ExempleTest6.java *****************:
Unable to compile drl files.....");
}
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
16 years
2 levels of sorting / distribution in Drools (Date + Proportionate)
by Nimesh Muley
Hi,
I have tried to implement 2 levels (nested) of sorting / distribution (Date and Proportionate) in Drools and failed :-(. I could not accomplish when the second level was 'proportionate'. Let me clear the terms before I give the example.
2 level --> The criteria chosen for the first level is same then only apply the second level criteria. In SQL terms it would be "order by date, avg price". The first level was Date.
Proportionate --> Proportionate means distribute the items / amount as proportion to what it contains.
The rule that is mentioned below did not work. There was no issue in implementing sequence number as second priority.
What happens is that the "$totalTrancheAmount" does not include the facts (Tranche objects) that were already matched or being matched. Basically the sum is always of the facts that are 'yet' to be matched.
Also what is needed is a fact understanding whether Tranche got selected as a "proportionate" one or only based on date. For this we can use if ($totalTrancheAmount > 0) condition on "then" side I suppose.
Is there any way of getting hold of all facts which taking sum of childTrancheValue?
rule "LIFO And Proportionate"
dialect "java"
salience 101
when
$product : Product($productSeq : productSeq, vestedAmt > 0)
$tranche : Tranche(productSeq == $productSeq, $maintrancheSeq : trancheSeq, $trancheValue : trancheValue > trancheVestedAmt, $trancheCreationDate : trancheCreationDt)
not Tranche(claimProductSeq == $claimProductSeq, trancheSeq != $maintrancheSeq, trancheValue > trancheVestedAmt, trancheCreationDt > $trancheCreationDate )
and
(
$totalTrancheAmount : Double () from accumulate ( Tranche($childtrancheValue : trancheValue, trancheCreationDt == $trancheCreationDate, trancheValue > trancheVestedAmt), sum( $childtrancheValue ))
or
eval(true)
)
then
// Vesting should happen based on proportionate if the dates were matched otherwise based on which amount is greater.
// Proportionate = $trancheValue / $ totalTrancheAmount
vestTranche($claimProductDetail, $trancheDetail);
System.out.println("$totalTrancheAmount : " + $ totalTrancheAmount);
update ($trancheDetail);
update ($claimProductDetail);
end
Thanks.
Regards,
- Nimesh
MASTEK LTD.
Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 years
cannot find class errors when deploying 5.0.0.MR2 drools-guvnor.war
by Ittyavirah, Seegler
Hi,
I am getting these errors when deploying drools-guvnor.war in jboss?
What might be causing this? Looks like a seam issue. How do I debug
further?
2008-11-25 07:34:02,770 +0530 ERROR [STDERR] [error] cannot
find WEB-INF.classes.org.drools.guvnor.server.files.FileManagerUtils:
org.drools.guvnor.server.files.FileManagerUtils found in
WEB-INF/classes/org/drools/guvnor/server/files/FileManagerUtils.class..
Do verbose mode if you want full stack trace.
2008-11-25 07:34:03,081 +0530 ERROR [STDERR] [error] cannot
find
WEB-INF.classes.org.drools.guvnor.server.repository.BRMSRepositoryConfig
uration: org.drools.guvnor.server.repository.BRMSRepositoryConfiguration
found in
WEB-INF/classes/org/drools/guvnor/server/repository/BRMSRepositoryConfig
uration.class.. Do verbose mode if you want full stack trace.
2008-11-25 07:34:03,291 +0530 ERROR [STDERR] [error] cannot
find
WEB-INF.classes.org.drools.guvnor.server.repository.RulesRepositoryManag
er: org.drools.guvnor.server.repository.RulesRepositoryManager found in
WEB-INF/classes/org/drools/guvnor/server/repository/RulesRepositoryManag
er.class.. Do verbose mode if you want full stack trace.
2008-11-25 07:34:03,331 +0530 ERROR [STDERR] [error] cannot
find
WEB-INF.classes.org.drools.guvnor.server.security.DefaultAuthenticator:
org.drools.guvnor.server.security.DefaultAuthenticator found in
WEB-INF/classes/org/drools/guvnor/server/security/DefaultAuthenticator.c
lass.. Do verbose mode if you want full stack trace.
2008-11-25 07:34:03,331 +0530 ERROR [STDERR] [error] cannot
find WEB-INF.classes.org.drools.guvnor.server.security.NilAuthenticator:
org.drools.guvnor.server.security.NilAuthenticator found in
WEB-INF/classes/org/drools/guvnor/server/security/NilAuthenticator.class
.. Do verbose mode if you want full stack trace.
2008-11-25 07:34:03,371 +0530 ERROR [STDERR] [error] cannot
find
WEB-INF.classes.org.drools.guvnor.server.security.RoleBasedPermissionMan
ager: org.drools.guvnor.server.security.RoleBasedPermissionManager found
in
WEB-INF/classes/org/drools/guvnor/server/security/RoleBasedPermissionMan
ager.class.. Do verbose mode if you want full stack trace.
2008-11-25 07:34:03,381 +0530 ERROR [STDERR] [error] cannot
find
WEB-INF.classes.org.drools.guvnor.server.security.RoleBasedPermissionSto
re: org.drools.guvnor.server.security.RoleBasedPermissionStore found in
WEB-INF/classes/org/drools/guvnor/server/security/RoleBasedPermissionSto
re.class.. Do verbose mode if you want full stack trace.
Thanks
Seegler
16 years
javassist.NotFoundException: org.drools.spi.Consequence in 5.0.0.MR2
by Ittyavirah, Seegler
Hi,
I am getting this error message when executing rules in MR2. I use
drools runtime wrapped in an ejb and deployed in jboss.
Is this javassist version issue? Which version is required for MR2? How
do I debug this further?
8:15:05,731 ERROR [STDERR] [error] javassist.NotFoundException:
org.drools.spi.
onsequence.. Do verbose mode if you want full stack trace.
Thanks
Seegler
16 years
Drools Workbench on Eclipse 3.4?
by Brian Sam-Bodden
Has anybody gotten the Drools Workbench working on Ganymede. I'm trying to
install on a fresh Ganymede install and getting all kinds of dependency
issues. I see the 5.0 version supports 3.4 but will it work with Drools
4.0.7?
16 years
Best (better) practice question
by J. Michael Dean
I have an application that classifies glucose levels in a patient,
looks at the insulin dose, and provides advice. Works reasonably well
(using 4.07 and local drl file). However, my "decision object" has a
text field in it where the advice and explanation is put, by the
relevant rules. This means that the RHS always modifies the decision
object, so no-loop does not prevent looping. For this reason, I have
created a "state object" that has a bunch of Booleans in it, and the
RHS sets a flag as well as modifying the decision object. This works.
My question is whether feeding a state object with a bunch of Booleans
is really the right thing to do, or should I be asserting new facts
(one fact object for each current Boolean). I could have a "helper
object" with inner classes that represent these facts. It feels like
I ought be be inserting and retracting facts rather than the approach
I am using, but not sure it matters.
Thank you.
- Mike
16 years
Best (better) practice question
by J. Michael Dean
I have an application that classifies glucose levels in a patient,
looks at the insulin dose, and provides advice. Works reasonably well
(using 4.07 and local drl file). However, my "decision object" has a
text field in it where the advice and explanation is put, by the
relevant rules. This means that the RHS always modifies the decision
object, so no-loop does not prevent looping. For this reason, I have
created a "state object" that has a bunch of Booleans in it, and the
RHS sets a flag as well as modifying the decision object. This works.
My question is whether feeding a state object with a bunch of Booleans
is really the right thing to do, or should I be asserting new facts
(one fact object for each current Boolean). I could have a "helper
object" with inner classes that represent these facts. It feels like
I ought be be inserting and retracting facts rather than the approach
I am using, but not sure it matters.
Thank you.
- Mike
16 years