Newbie question.
by KASINATH Gautham [PD74129]
Hello all,
I am about a day old to Drools. I have had success in executing the
examples in a Windows, JDK1.6 environment.
Based on the success of the examples, I am trying to put together a
sample usecase myself to understand Drools. I write to you since I
havent had much success in that.
My use case is:
1) Check the type of person.
2) If person is an Employee, then print the Employee ID.
3) If person is a customer then print the customer first and last name.
4) If the person is an Employee and the employee id is missing, then
throw an exception, so that the calling API can handle the error.
To realize this, I have three interfaces, IPerson, IEmployee extends
IPerson and ICustomer extends IPerson.
IPerson has the common attribute getters such as; getFirstName,
getLastName
IEmployee has the getter getEmployeeId, while the ICustomer is only a
marker interface (at the moment).
The DRL file with the rules contains:
rule "If no Employee Number, then print error"
dialect "java"
when
IPerson( empNumber <= -1 )
then
System.out.println( "Invalid Employee number" );
end
rule "Rule to print the Employee number"
dialect "mvel"
when
$person : IPerson( personType == IPerson.EMPLOYEE_PERSON_TYPE )
then
System.out.println( "The Employee Number is "+$person.empNumber);
end
rule "Rule to print the first name and last name if it is a Customer"
dialect "mvel"
when
$person : IPerson( personType == IPerson.CUSTOMER_PERSON_TYPE )
then
System.out.println( "The Customers' name is "+$person.firstName+"
"+$person.lastName );
end
The error I get for the rule is:
Unable to create Field Extractor for 'empNumber' of '[ClassObjectType
class=com.drools.local.samples.model.IPerson]
The above error did suggest that the IPerson doesnot expose any methods
to retrieve the empNumber, such as getEmpNumber. But then, when I do a
$person.empNumber, it does print the empNumber. Hence, the Drools
framework must somehow be able to *auto-magically* cast down the object.
This is what is confusing me.
Could you advice if my usecase is possible with Drools and if yes, then
what am I missing? Is my rules approach wrong? Also, if there a way to
throw exceptions in the then case?
The JSR-94 provides mechanism to get the results, is there a similar way
in Drools?
Thanks.
Cheers
Gautham Kasinath
*******************************************************
This email message and any attached files may contain
information that is confidential and subject of legal
privilege intended only for use by the individual or
entity to whom they are addressed. If you are not the
intended recipient or the person responsible for
delivering the message to the intended recipient be
advised that you have received this message in error
and that any use, copying, circulation, forwarding,
printing or publication of this message or attached
files is strictly forbidden, as is the disclosure of
the information contained therein. If you have received
this message in error, please notify the sender
immediately and delete it from your Inbox.
*******************************************************
17 years
Storing/Loading Rules In/From a Database
by Tong Wang
Greetings, everyone!
I would like to get some advice/guide from you on storing/loading rules
in/from a database.
Here is my use case, in my domain object model, there is a class named
Promotion, and for each instance of Promotion (there could be thousands
promotions), I need to configure one or more rules for the promotion, so
there is a one-to-many relation between the promotion and its rules. I plan
to store the rules in the same DB as Promotion and also maintain the
one-to-many relation between them. At runtime, when facts are inserted, all
promotions' rules need to be evaluated, and I'd like the firing rules to
know their "owning" promotion instances and take some action on those
instances.
And here are my questions/confusions:
1. Do I need to create my own tables for storing rules/conditions/actions OR
can I use the Drools Repository? (Remember I have to keep the relation
between a promotion and its rules)
2. If I need to create my own tables, how should I load the rules at
runtime? The only way I can think of right now is something like string
concatenation and end up with the DRL source format and then use the
PackageBuilder. Would this work? Is there any better ways?
3. At runtime, I need to evaluate ALL the rules to find which promotion(s)
will match, so do I just create a single RuleBase, add all the packages
(there could be tens of thousands of rules), then create the session and
insert the fact and then fire them? Will this cause any performance issue?
What is the best practices to deal with large number of rules?
Thanks in advance.
Tong
17 years, 1 month
'exists' asa field in an Object causes error
by Arjun Dhar
Hi I have a BusinessObject with a field called "exists".
I think the rule engine interprets this in some special way.
Is there a way I can emphasize its a variable and not a syntax word?
Thanks,
Arjun
17 years, 1 month
Stop Processing Rules
by Ronald R. DiFrango
All,
I have a situation where I want the rules execution to stop processing
immediately when it encounters a situation like the following:
rule "Invalid RTV Line"
salience 100
when
rtvDetailLine : DetailLine(detailRtvNumber:rtvNumber != null,
lineNumber != null )
rtvHeader : RtvHeader( rtvNumber != detailRtvNumber )
then
logger.debug("Invalid RTV Line");
throw new RuntimeException("Invalid RTV Line");
end
Basically this is a parent child relationship and under some circumstances
the process that feeds data into the rules it corrupts this relationship. I
want to stop the rules process immediately and do nothing further. As you
see above, my first attempt is just throw a runtime exception that is
caught/ logged and report by the calling program. Does this seem like a
reasonable approach or is there a better approach to do this?
Ron
17 years, 1 month
Duplicate variable issue
by Eric Miles
All,
I have a rule that I'm trying to run against, but I'm getting a
duplicate parameter error that doesn't make much sense to me. Here is
the rule:
rule "Daily Core Hours"
ruleflow-group "maxiflex-messages"
when
ScheduleDay($day: day, $schedIn: timeIn, $schedOut: timeOut)
not SmartTimeMessage(message == ("Core hours for day " + ($day + 1) +
" have not been met"))
Integer(intValue > 0 && intValue < ($schedOut - $schedIn))
from accumulate( SmartTimeLine(tito.day == $day, $timeOut:
tito.timeOut, $timeIn: tito.timeIn),
init( int total = 0; ),
action( total += calculateTime($schedIn,
$schedOut, (Integer)$timeIn, (Integer)$timeOut); ),
reverse( total -= calculateTime($schedIn,
$schedOut, (Integer)$timeIn, (Integer)$timeOut); ),
result( total ) )
then
SmartTimeMessage message = new SmartTimeMessage();
message.setType(SmartTimeMessageType.WARNING);
message.setMessage("Core hours for day " + ($day + 1) + " have not
been met");
insert(message);
end
function int calculateTime(int schedIn, int schedOut, int timeIn, int
timeOut) {
int beginTime = 0, endTime = 0;
if(timeIn < schedIn) {
beginTime = schedIn;
} else {
beginTime = timeIn;
}
if(timeOut > schedOut) {
endTime = schedOut;
} else {
endTime = timeOut;
}
return (endTime - beginTime);
}
The following is the error:
org.drools.rule.InvalidRulePackage: Rule Compilation error : [Rule
name=Daily Core Hours, agendaGroup=MAIN, salience=0, no-loop=false]
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(32:1301) : Duplicate parameter $schedOut
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(32:1330) : Duplicate parameter $schedIn
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(41:1735) : Duplicate parameter $schedOut
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(41:1764) : Duplicate parameter $schedIn
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(51:2330) : Duplicate parameter $schedOut
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(51:2359) : Duplicate parameter $schedIn
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(58:2738) : Duplicate parameter $schedOut
com/kronos/webta/service/smarttime/rules/Rule_Daily_Core_Hours_0.java
(58:2767) : Duplicate parameter $schedIn
at org.drools.rule.Package.checkValidity(Package.java:424)
at
org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:364)
at
com.kronos.webta.service.smarttime.rules.maxiflex.FlowTest.setUpBeforeClass(FlowTest.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:49)
at
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:36)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Any help with this? Thanks in advance!
Eric
17 years, 1 month
Choosing JackRabbit 1.3 JNDI PersistenceManager
by mmquelo massi
First of All.......*Environment: Drools BRMS 4.0.3, JBossAS 4.2.2, MySql 5*
Hi Guys,
It's making me waste all the day trying to set
"JNDIDatabasePersistenceManager" as mysql-repository persistence manager.
I show u the issue...
*In MySql I've got an empty "brms-db" schema.*
*In JBoss default workspace I've got the following datasource definition in
mysql-ds.xml:*
*<datasources>
<local-tx-datasource>
<jndi-name>jdbc/MySQLDB</jndi-name>
<connection-url>jdbc:mysql:///brms-db</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>drools</user-name>
<password>drools</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>5</idle-timeout-minutes>
<exception-sorter-class-name>
com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
</exception-sorter-class-name>
<valid-connection-checker-class-name>
com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
</valid-connection-checker-class-name>
</local-tx-datasource>
</datasources>*
*I've got the following persistence manager set-up in
<jboss_home>\bin\repository.xml:*
* <PersistenceManager class="
org.apache.jackrabbit.core.persistence.db.JNDIDatabasePersistenceManager">
<param name="dataSourceLocation" value="java:jdbc/MySQLDB"/>
<param name="schema" value="mysql"/>
<param name="schemaObjectPrefix" value="${wsp.name}_"/>
<param name="externalBLOBs" value="false" />
</PersistenceManager> *
*Once I start JBoss I get back the following exception:*
*2007-11-28 16:48:36,766 INFO [STDOUT] ERROR 28-11 16:48:36,743 (
RepositoryImpl.java:initStartupWorkspaces:389) Failed to initialize
workspace 'default'
javax.jcr.RepositoryException: Cannot instantiate persistence manager
org.apache.jackrabbit.core.persistence.db.JNDIDatabasePersistenceManager:
null: null
at org.apache.jackrabbit.core.RepositoryImpl.createPersistenceManager(
RepositoryImpl.java:1184)
at org.apache.jackrabbit.core.RepositoryImpl.access$600(RepositoryImpl.java
:103)
at org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.initialize(
RepositoryImpl.java:1758)
at org.apache.jackrabbit.core.RepositoryImpl.initWorkspace(
RepositoryImpl.java:603)
at org.apache.jackrabbit.core.RepositoryImpl.initStartupWorkspaces(
RepositoryImpl.java:386)
at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java
:293)
at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java
:584)
at org.apache.jackrabbit.core.TransientRepository$2.getRepository(
TransientRepository.java:245)*
*...*
I tried to replace "*
org.apache.jackrabbit.core.persistence.db.JNDIDatabasePersistenceManager*"
with "*org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager*
"
and It *DOES* Work ....so I think we can exclude it's something related to
"JackRabbit API" null references...
Have U got any idea?
What is the reason?
Did I miss any binding concernig the DataSource definition?????
Is it just impossible to bind JackRabbit to any datasources although JNDI
APIs do exist?????
Is it a matter related to the "weird JackRabbit JNDI client"??
Let me know.
Thank You again.
Massi
17 years, 1 month
about use of org.drools.concurrent package
by prateek.katiyar@wipro.com
Hello all
I am using Drools 4.0.3 in my application.
I want to know about the use of org.drools.concurrent package which is in the drools-core-4.0.3.jar.
What type of concurrent operations I can do by the classes of this package.
Any information will be appreciated.
Thanks.
With Regards
Prateek
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com
17 years, 1 month
RegEx in LHS
by Markus Helbig
Hi all,
i'd like to have following DSL conditions
[condition][]Title contains {value}=title matches {value}
[condition][]Title contains not {value}=title not matches {value}
Currently (using Drools 4.0.3) it seems the parsers resolves to the
first condtion and is matching the word "not" to {value}, so i tried
[condition][]Title contains\s+{value}=title matches {value}
[condition][]Title contains\snot\s{value}=title not matches {value}
but this doesn't help, because second one again matches to the first
rule ... also it is missing one parameter ...
Any solutions?
Cheers
Markus
17 years, 1 month
Combine DSL and Java Code?
by Markus Helbig
Hi,
following example:
Item Class:
public class MyItem {
public MyItem() {}
public String getMessage()
{
return "Hello World!";
}
}
DSL:
[condition][]is of type MyItem=MyItem()
[consequence][]write "{value}" to stdout=System.out.println("{value}");
DSRL File:
rule
when
$item: is of type MyItem
then
write $item.getMessage() to stdout
end
Is this "write $item.getMessage() to stdout" possible in any way?
Currently i'm not able to get it to work ...
Cheers
Markus
17 years, 1 month