Bug 754093

Summary: Declarative type extension not working properly
Product: [JBoss] JBoss Enterprise BRMS Platform 5 Reporter: Zuzana Krejčová <zkrejcov>
Component: BRM (Guvnor)Assignee: manstis
Status: VERIFIED --- QA Contact:
Severity: high Docs Contact:
Priority: unspecified    
Version: BRMS 5.3.0.GACC: manstis, mproctor
Target Milestone: ER7Keywords: Regression
Target Release: BRMS 5.3.0.GA   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 796612    
Bug Blocks:    
Attachments:
Description Flags
rule
none
stacktrace
none
repository none

Description Zuzana Krejčová 2011-11-15 11:53:11 UTC
Description of problem:

It should be possible (according to docs) to extend 

A) Facts inside the same Declarative Model: 
Works well.

B) Facts from a different D. Model from the same Package: 
It is NOT possible to do that in Guvnor - while creating a new Fact, there isn't the other (parent) Fact listed as a type to extend. There's a workaround for that, though not very good - export the repository, edit the xml so that the model has something like "declare fact extends anotherFact ...some fields... end", import it back into Guvnor.

C) Imported Java classes: 
This does not work at all. Not even after manually editing the repository.xml.



Version-Release number of selected component (if applicable):

BRMS 5.3.0 dev5

Comment 1 manstis 2012-01-22 10:23:31 UTC
Guvnor documentation states to extend a POJO you need to complete the following:-

4.12.3.1.3.1. Extending a Java class

To extend a Java class the following steps need to be completed:-

* Import the applicable Java JAR into Guvnor

* If the Java package name in which the class belongs is different to the Guvnor package name in to which the JAR has been imported ensure the Guvnor package imports the class from which you want to extend. This is normally completed for you automatically when you upload a JAR model however if you have multiple classes with the same name in the JAR you should check the appropriate one has been imported.

* Within the Declarative Modelling screen define an empty type (i.e. with no fields) of the same name as that you want to extend.

* Create a new declarative type as appropriate, extending the empty declaration created in the preceeding step.

Please clarify what does not work as documented?

Comment 2 Zuzana Krejčová 2012-01-23 10:28:32 UTC
Doing it this way works - though I'd swear this bit of information (define an empty type of the same name, then extend this one) got added/changed after I reported the issue.. Never mind. 

Now I can't even find any specific mention of extending a fact from a different declarative model in the same package, as in B) - which still doesn't work.

Tested on BRMS 5.3.0 ER2.

Comment 3 manstis 2012-01-23 12:01:43 UTC
Hi Zuzana, 

I don't know why you couldn't find C) (it has always been this way in both Drools' DRL and Guvnor) but as you say, never mind.

I will hopefully work on B) soon - it should be quite simple (we only load declared types for use in the screen from the model being opened, I need to change it to load all Facts in all declarative models in the package).

Thanks,

Mike

Comment 4 manstis 2012-01-30 11:39:36 UTC
Fixed (B) and back-ported to 5.3.x branch.

(A) and (C) no longer issues.

Comment 5 Ryan Zhang 2012-02-15 09:12:15 UTC
Please verify the issue on 5.3 ER4.

Comment 6 Zuzana Krejčová 2012-02-21 12:31:28 UTC
Case B is still not working in ER4. 
What it does now:
It allows you to choose a fact to extend, but upon save, it changes it to Object - this, obviously, does not bring anything new to the fact...

Say I have a model with fact F1 which has a field f1. Then I create another model in the same package and create a new fact in it, F2, and choose it's to extend the fact F1. I add a field f2 to the fact and save the model.
Upon save, i see the "F2 extends F1" change to "F2 extends Object". Field f1 is not accessible from fact F2.

Comment 7 manstis 2012-02-21 12:46:28 UTC
This is due to a regression in Drools Expert. I have asked for a fix made to master to be back-ported... and am awaiting confirmation it has been completed.

Comment 8 Anne-Louise Tangring 2012-03-28 14:48:37 UTC
Setting Blocker flag as agreed on in triage meeting.

Comment 9 JBoss JIRA Server 2012-03-30 12:50:03 UTC
Michael Anstis <michael.anstis> updated the status of jira JBRULES-3418 to Coding In Progress

Comment 10 JBoss JIRA Server 2012-03-30 12:50:08 UTC
Michael Anstis <michael.anstis> updated the status of jira JBRULES-3417 to Coding In Progress

Comment 11 JBoss JIRA Server 2012-03-30 12:54:34 UTC
Michael Anstis <michael.anstis> updated the status of jira JBRULES-3418 to Resolved

Comment 12 JBoss JIRA Server 2012-03-30 12:54:42 UTC
Michael Anstis <michael.anstis> updated the status of jira JBRULES-3417 to Resolved

Comment 13 Ryan Zhang 2012-04-23 07:36:41 UTC
Update status to ON_QA. Please verify them against ER6.

Comment 14 Zuzana Krejčová 2012-04-25 15:19:16 UTC
I am sorry to say it still needs some tweaking.

I got "[rule] Unable to validate this asset. (Check log for detailed messages)." upon validation of a rule using such Facts (B) or either of the models.

I have a model parentModel:
declare ParentFact
    parentFiled: String
end

and another one childModel:
declare ChildFact
    childFiled: String
end

and a simple rule using both of those.

There's also NPE in the server log, "Unable to build asset." at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:130). 

See attachments for the rule and the stacktrace.

Comment 15 Zuzana Krejčová 2012-04-25 15:20:06 UTC
Created attachment 580190 [details]
rule

Comment 16 Zuzana Krejčová 2012-04-25 15:20:37 UTC
Created attachment 580192 [details]
stacktrace

Comment 17 manstis 2012-04-25 15:23:14 UTC
Please attach your repository export too, it'll make tracking down the problem much easier. Thanks, Mike

Comment 18 Zuzana Krejčová 2012-04-25 15:56:08 UTC
Created attachment 580201 [details]
repository

I have found out that this Error happens due to my model names, when the first letters aren't like this: childModel, ParentModel. 
Meaning, if I havechildModel, ParentModel, it is okay. 
If I have childModel, parentModel it is not, same with ChildModel and whatever.

Comment 19 manstis 2012-04-25 21:58:24 UTC
I suspect this relates to the ordering of Declarative model names. The DRL for the attached repository reads:-

4.	|	declare ChildFact extends ParentFact
5.	|	    childField: Boolean
6.	|	end
7.	|	
8.	|	declare ParentFact
9.	|	    parentField: String
10.	|	end

Hence we are trying to extend a type before the super-type is declared. This is further substantiated if you try to build the package - it fails :( We need to add some code to order the DRL by parent->child types where one extends another.

Comment 20 manstis 2012-04-27 15:35:13 UTC
Problem was that the sub-type was being declared in package DRL before super-type. Fixed in master and 5.3.x branch (https://github.com/droolsjbpm/guvnor/commit/7b32666c4451a075074a5f9a69a85e85dc093015)

Comment 24 Ryan Zhang 2012-05-14 08:16:16 UTC
The fixed for this issue should be included in ER7. Please do verification on it.