Thanks for the reply.  I was hoping to avoid refactoring the fact objects.

2009/12/15 Edson Tirelli <ed.tirelli@gmail.com>

   2 ways:

1. If you have a common superclass/interface for your objects and the superclass/interface has the method to return your dln, just make use of inheritance:

when
    MyDTOInterface( dln not matches "^.{5,15}$")
then
   // do something

2. If you want to use composition instead, make dln a top level fact:

when
   DLN( id not matches "^.{5,15}$")
then
   // do something

   Edson

2009/12/15 Jason Davidson <jljdavidson@gmail.com>
Hello,

What is the best practice for reusing rules?  I've got a license number validation rule that I need to reuse for different fact types.  For example, the first rule uses the license number in a CitationDTO fact:
rule "Citation DL Number"
   ruleflow-group "CitationEntryValidationFlow"
    when
        CitationDTO($dln : citationSubject.driverLicense.driverAuthorizationId not matches "^.{5,15}$")
    then
        resultHolder.setMessage(GenericCitationFieldIds.DLN,"DLN [{0}] must be at least 5 characters long and no more than 15 characters long.", new Object[]{$dln});
end

Then I have another rule that uses the license number from the InCourtSearchDTO:
rule "InCourt DL Number"
    ruleflow-group "InCourtSearchValidationGroup"
    when
        InCourtSearchDTO( $d : dln not matches "^.{5,15}$")
    then
        resultHolder.setMessage(UserLogonFieldIds.END_DT,"DLN [{0}] must be at least 5 characters long and no more than 15 characters long.", new Object[]{$d});
end

Obviously this is a poor implementation because the license number check 'not matches "^.{5,15}$"' is duplicated.  Is there a way I can reuse this rule?

Thanks!

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users