<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Hi Ian,<br>
<br>
I tried using Enums with Guvnor twice: once back in the 4.0 times of
Drools, once again when we got the 5.0 update.<br>
<br>
My experience: Java enums and Guvnor simply don't work together. Stick
with writing DRL rule files in a text editor, or even better, using the
Eclipse plugin. This way, enums work somehow (still no code completion
for enum values, even when using the Eclipse plugin). If for some
reason you must use guvnor, you'll probably need to convert your beans
properties now holding Java enums into properties of type String and
use string constants to define the allowed value range.<br>
<br>
Guvnor experts: I'd be very happy to be proven wrong by someone of you.
Some kind of "HOWTO use Java Enums in Guvnor correctly" blog post etc.
very much appreciated ;-)<br>
<br>
Best regards<br>
<br>
Ansgar<br>
<br>
<br>
On 19.05.2010 18:36, <a class="moz-txt-link-abbreviated" href="mailto:Ian-D.Jones@ubs.com">Ian-D.Jones@ubs.com</a> wrote:<br>
<br>
<blockquote
 cite="mid:9DB464DCBA993D42A6E6ACEB763E0EA30AA0C58D@NLDNC108PEX1.ubsw.net"
 type="cite">
  <meta http-equiv="Content-Type"
 content="text/html; charset=ISO-8859-1">
  <meta content="MSHTML 6.00.2900.5945" name="GENERATOR">
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">Hi All,</font></span></div>
  <div><span class="568371416-19052010"></span>&nbsp;</div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">I've recently started using Drools and Guvnor, and so
far really like it!</font></span></div>
  <div><span class="568371416-19052010"></span>&nbsp;</div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">I have one problem however, to do with Java enums in
Guvnor. </font></span></div>
  <div><span class="568371416-19052010"></span>&nbsp;</div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">I have a simple enum as follows:</font></span></div>
  <b><font color="#7f0055"><font color="#7f0055"></font></font></b>
  <p align="left"><b><font color="#7f0055"><font color="#7f0055"><font
 size="2" face="Courier New">public</font></font></font></b><font
 face="Courier New"><font size="2"> <b><font color="#7f0055"><font
 color="#7f0055">enum</font></font></b></font></font><font
 face="Courier New"><font size="2"> STPRuleAction<br>
{<br>
  <i><font color="#0000c0"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>UNKNOWN</font></i>,
  <i><font color="#0000c0"><font color="#0000c0">ACCEPT</font></font></i></font></font><font
 face="Courier New"><font size="2">, <i><font color="#0000c0"><font
 color="#0000c0">REJECT</font></font></i></font></font><i><font
 color="#0000c0"><font color="#0000c0"><font size="2" face="Courier New"><br>
  </font></font></font></i><font size="2" face="Courier New">}</font></p>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">I can hand write a rule that works fine with this enum
as follows:</font></span></div>
  <b><font color="#960000"><font color="#960000"></font></font></b>
  <p align="left"><b><font color="#960000"><font color="#960000"><font
 size="2" face="Courier New">rule</font></font></font></b><font size="2"
 face="Courier New"> </font><font face="Courier New"><font size="2"><font
 color="#008000"><font color="#008000">"Retract rejected"<br>
  </font></font><b><font color="#960000"><span
 class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>dialect</font></b> </font></font><font
 color="#008000"><font color="#008000" size="2" face="Courier New">"mvel"<br>
  </font></font><font face="Courier New"><font size="2"><b><font
 color="#960000"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>when<br>
  </font></b><span class="568371416-19052010">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>o :
CtasOrder( stpRuleAction == STPRuleAction.REJECT )<br>
  </font></font><font face="Courier New"><font size="2"><b><font
 color="#960000"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>then<br>
  </font></b><span class="568371416-19052010">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>o.setStatus(
1 );<br>
  <b><font color="#960000"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>retract</font></b>(
o );<br>
  <b><font color="#960000"><font color="#960000">end</font></font></b></font></font></p>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">However, if I create a rule with Guvnor, it always puts
quotes around the condition, so seems to treat it as a string and it is
never triggered.&nbsp;I have created a Guvnor&nbsp;enumeration as follows:</font></span></div>
  <div><span class="568371416-19052010"></span>&nbsp;</div>
  <div><span class="568371416-19052010"><font size="2"
 face="Courier New">'CtasOrder.stpRuleAction' :
['STPRuleAction.UNKNOWN=UNKNOWN', 'STPRuleAction.ACCEPT=ACCEPT',
'STPRuleAction.REJECT=REJECT']</font></span></div>
  <div><span class="568371416-19052010"></span>&nbsp;</div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">Which gives me the correct drop down values in the
Business Rule editor, but the source of the rule looks like:</font></span></div>
  <div><span class="568371416-19052010"><font color="#000080"
 face="Tahoma">
  <p align="left"><font size="2"><font color="#800000"
 face="Courier New"><strong>rule</strong></font><font color="#000000"
 face="Courier New"> </font></font><font face="Courier New"><font
 size="2"><font color="#008000"><font color="#008000">"Retract rejected"<br>
  </font></font><b><font color="#960000"><span
 class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>dialect</font></b><font
 color="#000000"> </font></font></font><font color="#008000"><font
 color="#008000" size="2" face="Courier New">"mvel"<br>
  </font></font><b><font color="#960000"><font face="Courier New"><font
 size="2"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>when<br>
  </font></font></font></b><font color="#000000"><font
 face="Courier New"><font size="2"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  </span>o : CtasOrder( stpRuleAction == <font color="#008000"><font
 color="#008000"><strong>"STPRuleAction.REJECT"</strong></font></font>)<br>
  </font></font></font><b><font color="#960000"><font face="Courier New"><font
 size="2"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp; </span>then<br>
  </font></font></font></b><font face="Courier New"><font size="2"><font
 color="#000000"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>o.setStatus(
1 );<br>
  </font><b><font color="#960000"><span class="568371416-19052010">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  </span>retract</font></b></font></font><font face="Courier New"><font
 size="2"><font color="#000000">( o );<br>
  </font><b><font color="#960000"><font color="#960000">end</font></font></b></font></font></p>
  </font></span></div>
  <div><font size="2"><span class="568371416-19052010"><font
 color="#000080" face="Tahoma">I've tried without the mapping in the
enumeration (e.g <font color="#000000" face="Courier New">... :
['STPRuleAction.UNKNOWN', ...</font></font></span><span
 class="568371416-19052010"><font color="#000080" face="Tahoma">) and
even removing the enumeration and adding the text manually as a literal
value. I can't see any way to specfy a enum/qualifiedIdentifier as a
condition in Guvnor. It works fine as a consequence and produces a rule
without quotes around (e.g. <font color="#000000" face="Courier New">o.setStpRuleAction(
STPRuleAction.REJECT )...</font></font></span><span
 class="568371416-19052010"><font color="#000080" face="Tahoma">)</font></span></font></div>
  <div><font color="#000080" size="2" face="Tahoma"><span
 class="568371416-19052010"></span></font>&nbsp;</div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">Many thanks for any assistance you can give.</font></span></div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">Regards,</font></span></div>
  <div><span class="568371416-19052010"><font color="#000080" size="2"
 face="Tahoma">Ian</font></span></div>
  <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
  </pre>
</blockquote>
<br>
</body>
</html>