Hi Ian,

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.

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.

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 ;-)

Best regards

Ansgar


On 19.05.2010 18:36, ian-d.jo...@ubs.com wrote:

Hi All,
I've recently started using Drools and Guvnor, and so far really like it!
I have one problem however, to do with Java enums in Guvnor.
I have a simple enum as follows:
**

*public* *enum* STPRuleAction
{
/ UNKNOWN/, /ACCEPT/, /REJECT//
/}

I can hand write a rule that works fine with this enum as follows:
**

*rule* "Retract rejected"
* dialect* "mvel"
* when
* o : CtasOrder( stpRuleAction == STPRuleAction.REJECT )
* then
* o.setStatus( 1 );
* retract*( o );
*end*

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. I have created a Guvnor enumeration as follows: 'CtasOrder.stpRuleAction' : ['STPRuleAction.UNKNOWN=UNKNOWN', 'STPRuleAction.ACCEPT=ACCEPT', 'STPRuleAction.REJECT=REJECT'] Which gives me the correct drop down values in the Business Rule editor, but the source of the rule looks like:

*rule* "Retract rejected"
* dialect* "mvel"
* when
* o : CtasOrder( stpRuleAction == *"STPRuleAction.REJECT"*)
* then
* o.setStatus( 1 );
* retract*( o );
*end*

I've tried without the mapping in the enumeration (e.g ... : ['STPRuleAction.UNKNOWN', ...) 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. o.setStpRuleAction( STPRuleAction.REJECT )...)
Many thanks for any assistance you can give.
Regards,
Ian


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

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

Reply via email to