Red Hat Bugzilla – Bug 754093
Declarative type extension not working properly
Last modified: 2016-07-31 21:12:52 EDT
Description of problem:
It should be possible (according to docs) to extend
A) Facts inside the same Declarative Model:
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
Guvnor documentation states to extend a POJO you need to complete the following:-
126.96.36.199.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?
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.
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).
Fixed (B) and back-ported to 5.3.x branch.
(A) and (C) no longer issues.
Please verify the issue on 5.3 ER4.
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.
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.
Setting Blocker flag as agreed on in triage meeting.
Michael Anstis <firstname.lastname@example.org> updated the status of jira JBRULES-3418 to Coding In Progress
Michael Anstis <email@example.com> updated the status of jira JBRULES-3417 to Coding In Progress
Michael Anstis <firstname.lastname@example.org> updated the status of jira JBRULES-3418 to Resolved
Michael Anstis <email@example.com> updated the status of jira JBRULES-3417 to Resolved
Update status to ON_QA. Please verify them against ER6.
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:
and another one childModel:
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.
Created attachment 580190 [details]
Created attachment 580192 [details]
Please attach your repository export too, it'll make tracking down the problem much easier. Thanks, Mike
Created attachment 580201 [details]
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.
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
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.
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)
The fixed for this issue should be included in ER7. Please do verification on it.