<br> 2 ways:<br><br>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:<br><br>when<br> MyDTOInterface( dln not matches "^.{5,15}$")<br>
then<br> // do something<br><br>2. If you want to use composition instead, make dln a top level fact:<br><br>when<br> DLN( id not matches "^.{5,15}$")<br>then<br> // do something<br><br> Edson<br><br><div class="gmail_quote">
2009/12/15 Jason Davidson <span dir="ltr"><<a href="mailto:jljdavidson@gmail.com">jljdavidson@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br><br>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:<br>
rule "Citation DL Number"<br> ruleflow-group "CitationEntryValidationFlow"<br> when<br> CitationDTO($dln : citationSubject.driverLicense.driverAuthorizationId not matches "^.{5,15}$")<br>
then<br> resultHolder.setMessage(GenericCitationFieldIds.DLN,"DLN [{0}] must be at least 5 characters long and no more than 15 characters long.", new Object[]{$dln});<br>end<br><br>Then I have another rule that uses the license number from the InCourtSearchDTO:<br>
rule "InCourt DL Number"<br> ruleflow-group "InCourtSearchValidationGroup"<br> when<br> InCourtSearchDTO( $d : dln not matches "^.{5,15}$")<br> then<br> resultHolder.setMessage(UserLogonFieldIds.END_DT,"DLN [{0}] must be at least 5 characters long and no more than 15 characters long.", new Object[]{$d});<br>
end<br><br>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?<br><br>Thanks!<br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>