[rules-users] Newbie question.

KASINATH Gautham [PD74129] Gautham.KASINATH at police.wa.gov.au
Thu Nov 29 18:03:51 EST 2007


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.
*******************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071130/e38e0887/attachment.html 


More information about the rules-users mailing list