Bug 724629 (BRMS-536) - Enum support in Guvnor is not functional
Summary: Enum support in Guvnor is not functional
Keywords:
Status: VERIFIED
Alias: BRMS-536
Product: JBoss Enterprise BRMS Platform 5
Classification: JBoss
Component: BRM (Guvnor)
Version: 5.1.0 GA
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: ---
: BRMS 5.2.0.GA
Assignee: manstis
QA Contact:
URL: http://jira.jboss.org/jira/browse/BRM...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-01-18 16:27 UTC by Alessandro Lazarotti
Modified: 2023-05-15 19:53 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
When using Java Enums in a fact model the Guided Editor showed a combo box with the correct values however, the values were parsed as strings and didn't work as expected. This has been resolves and the values are being parsed as expected.
Clone Of:
Environment:
fedora 12, jdk 1.6 sun/oracle, BRMS 5.1
Last Closed:
Type: Bug
Embargoed:
manstis: needinfo+


Attachments (Terms of Use)
person2.jar (1.79 KB, application/x-java-archive)
2011-01-18 16:32 UTC, Alessandro Lazarotti
no flags Details
EnumDropDownLabel.patch (1.99 KB, text/x-patch)
2011-02-24 22:28 UTC, Alessandro Lazarotti
no flags Details
ConstraintValueEditor.patch (3.17 KB, text/x-patch)
2011-02-24 22:28 UTC, Alessandro Lazarotti
no flags Details
sceb.patch (980 bytes, text/x-patch)
2011-02-24 22:28 UTC, Alessandro Lazarotti
no flags Details
BRDRLPersistence.patch (769 bytes, text/x-patch)
2011-02-24 22:28 UTC, Alessandro Lazarotti
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1047879 0 unspecified CLOSED GRE regression in handling nested enum values 2021-02-22 00:41:40 UTC
Red Hat Issue Tracker BRMS-536 0 Major Closed Enum support in Guvnor is not functional 2018-05-18 01:15:25 UTC

Internal Links: 1047879

Description Alessandro Lazarotti 2011-01-18 16:27:34 UTC
Help Desk Ticket Reference: https://c.na7.visual.force.com/apex/Case_View?id=500A0000005hhkr&sfdc.override=1
Steps to Reproduce: Person fact with enum (attached)

public class Person {
	
	public enum Sex{
		MALE,FEMALE
	}	
	public Sex getSex() {
		return sex;
	}
	public void setSex(Sex sex) {
		this.sex = sex;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private Sex sex;
	private String name;
}

And a rule like the printcreen attached.
It should generate the code:


1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == Person.Sex.Female )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end



but it does not. It generated this:

1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == "1" )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end

... that never (obviously) is matched.
securitylevel_name: Public

From version 5.1 you can use Java Enum in fact models and the Guided Editor should help you to pick a correct option to build your rule (https://issues.jboss.org/browse/GUVNOR-182). However, it does not.
Guided Editor show a combobox with the values correctly to choose a value but the value parsed to rule is wrong, it is a ordinal as a String, that don't work.

Comment 1 Alessandro Lazarotti 2011-01-18 16:28:22 UTC
Release Notes Text: Removed: Person fact with enum (attached)

public class Person {
	
	public enum Sex{
		MALE,FEMALE
	}	
	public Sex getSex() {
		return sex;
	}
	public void setSex(Sex sex) {
		this.sex = sex;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private Sex sex;
	private String name;
}

And a rule like the printcreen attached.
It should generate the code:


1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == Person.Sex.Female )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end



But it should not. It generated this:

1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == "1" )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end

... that never (obviously) is matched. 
Steps to Reproduce: Removed: obviously Added: Person fact with enum (attached)

public class Person {
	
	public enum Sex{
		MALE,FEMALE
	}	
	public Sex getSex() {
		return sex;
	}
	public void setSex(Sex sex) {
		this.sex = sex;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private Sex sex;
	private String name;
}

And a rule like the printcreen attached.
It should generate the code:


1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == Person.Sex.Female )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end



But it should not. It generated this:

1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == "1" )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end

... that never (obviously) is matched.


Comment 2 Alessandro Lazarotti 2011-01-18 16:31:12 UTC
Steps to Reproduce: Removed: Person fact with enum (attached)

public class Person {
	
	public enum Sex{
		MALE,FEMALE
	}	
	public Sex getSex() {
		return sex;
	}
	public void setSex(Sex sex) {
		this.sex = sex;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private Sex sex;
	private String name;
}

And a rule like the printcreen attached.
It should generate the code:


1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == Person.Sex.Female )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end



But it should not. It generated this:

1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == "1" )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end

... that never (obviously) is matched. Added: Person fact with enum (attached)

public class Person {
	
	public enum Sex{
		MALE,FEMALE
	}	
	public Sex getSex() {
		return sex;
	}
	public void setSex(Sex sex) {
		this.sex = sex;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private Sex sex;
	private String name;
}

And a rule like the printcreen attached.
It should generate the code:


1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == Person.Sex.Female )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end



but it does not. It generated this:

1.	|	rule "rule1"
2.	|	    dialect "mvel"
3.	|	    when
4.	|	        Person( sex == "1" )
5.	|	    then
6.	|	        System.out.println("sexo feminino")
7.	|	end

... that never (obviously) is matched.


Comment 3 Alessandro Lazarotti 2011-01-18 16:32:27 UTC
fact model

Comment 4 Alessandro Lazarotti 2011-01-18 16:32:27 UTC
Attachment: Added: person2.jar


Comment 5 Alessandro Lazarotti 2011-01-18 16:39:21 UTC
Link: Added: This issue is related to GUVNOR-182


Comment 6 Alessandro Lazarotti 2011-01-18 17:20:44 UTC
I can't reopen GUVNOR-182, I don t have grants for it. Please, can you reopen Tihomir?

Comment 7 Tihomir Surdilovic 2011-01-18 17:22:54 UTC
Done, you should be able to add your comments to it now.

Comment 8 Alessandro Lazarotti 2011-02-24 22:28:57 UTC
Diffs for fix

Comment 9 Alessandro Lazarotti 2011-02-24 22:28:57 UTC
Attachment: Added: EnumDropDownLabel.patch
Attachment: Added: ConstraintValueEditor.patch
Attachment: Added: sceb.patch
Attachment: Added: BRDRLPersistence.patch


Comment 10 Alessandro Lazarotti 2011-03-01 14:56:20 UTC
Link: Added: This issue is related to GUVNOR-1171


Comment 11 Michael Anstis 2011-04-11 20:47:39 UTC
Escaping all literals with quotes is a wider issue than just enums. Create any rule with literals and they're all enclosed in quotes on IIRC all editors that generate their DRL from FactModel.

Comment 12 Michael Anstis 2011-06-07 22:09:42 UTC
I believe this has been fixed for 5.2.

Comment 13 Rick Wagner 2011-08-25 18:45:07 UTC
GSS prioritizes 'medium'.  Customer is watching issue, it's been a long time.

Comment 14 Ryan Zhang 2011-09-06 08:52:34 UTC
After checking the commit log, I think this issue should be fixed for BRMS-5.2 ER3.
So I will change it to ON_QA state

Comment 15 Zuzana Krejčová 2011-09-06 14:09:21 UTC
The source looks ok, POJO model with enum usable in rules, test scenarios show the rules are fired exactly when they should be.

Comment 16 lcarlon 2011-09-14 00:21:17 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
https://bugzilla.redhat.com/show_bug.cgi?id=724629

When using Java Enums in fact model the Guided Editor showed a combo box with the correct values however, the values were parsed as strings and didn't work as expected. This has been resolves and the values are being parsed as expected.

Comment 17 lcarlon 2011-09-14 04:30:38 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1,3 +1 @@
-https://bugzilla.redhat.com/show_bug.cgi?id=724629
-
 When using Java Enums in fact model the Guided Editor showed a combo box with the correct values however, the values were parsed as strings and didn't work as expected. This has been resolves and the values are being parsed as expected.

Comment 18 lcarlon 2011-10-10 03:19:57 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1 +1 @@
-When using Java Enums in fact model the Guided Editor showed a combo box with the correct values however, the values were parsed as strings and didn't work as expected. This has been resolves and the values are being parsed as expected.+When using Java Enums in a fact model the Guided Editor showed a combo box with the correct values however, the values were parsed as strings and didn't work as expected. This has been resolves and the values are being parsed as expected.

Comment 19 Alessandro Lazarotti 2012-04-16 14:17:35 UTC
This issue was not totally fixed yet. If you click on Literal Value instead of Formula (in BRL editor), you will look a value like Person$Sex.MALE wich is not valid.

Using nested Enum definitions inside classes is a very common approach. Please follow the steps commented in this BZ to test it.

Comment 20 Alessandro Lazarotti 2012-04-16 14:18:48 UTC
PS: I've tested with Drools/BRMS 5.3 bits and the issue happens there too

Comment 21 manstis 2012-04-16 17:31:29 UTC
Removed linked JIRA as it was unrelated. This Bugzilla item is shown as VERIFIED which normally means it has passed testing however the above comments suggest it has not. Which is correct?

Comment 22 manstis 2012-04-16 21:20:59 UTC
This has been fixed in master and community 5.4.x branch. Please advise if you want back-ported to 5.3.x branch.

Comment 23 Lukáš Petrovický 2012-04-17 07:06:39 UTC
(In reply to comment #22)
> This has been fixed in master and community 5.4.x branch. Please advise if you
> want back-ported to 5.3.x branch.

Please do. Comment 15 explains why this was marked as VERIFIED - if there were some other manifestations of the problem, we probably didn't know about them.

Comment 24 Zuzana Krejčová 2012-04-17 08:43:41 UTC
(In reply to comment #19)
> This issue was not totally fixed yet. If you click on Literal Value instead of
> Formula (in BRL editor), you will look a value like Person$Sex.MALE wich is not
> valid.
> 
> Using nested Enum definitions inside classes is a very common approach. Please
> follow the steps commented in this BZ to test it.

(In reply to comment #21)
> Removed linked JIRA as it was unrelated. This Bugzilla item is shown as
> VERIFIED which normally means it has passed testing however the above comments
> suggest it has not. Which is correct?


This is a slightly different issue, IMO. And it might have been introduced after this bug was verified, with the transition to 5.3 - which would also explain why it slipped through our testing as there were a lot of changes. I'd suggest a separate BZ.

Comment 25 manstis 2012-04-17 15:36:42 UTC
The enum issue reported herein (need for Person.Sex.MALE for a Sex enumeration nested inside the Person class, and not Person$Sex.MALE or other literal values) has been fixed and back-ported to 5.3.x branch. Set to MODIFIED so it can be tested with the next BRMS build.

Comment 26 Ryan Zhang 2012-05-11 12:00:37 UTC
This fix has been committed to project branch which BRMS 5.3 used.

Request block+ flag.

And the target release, and flag information seems not valid since it's expected for BRMS 5.3.0 and not a support patch.

Comment 27 Zuzana Krejčová 2012-07-09 11:53:18 UTC
This has been added to some previous product build and is working. I don't know, why it's still only MODIFIED - setting to VERIFIED, so it can be closed.


Note You need to log in before you can comment on or make changes to this bug.