[jboss-jira] [JBoss JIRA] (DROOLS-1654) Don'ing a Map-Based Fact Loses the Fact
KimJohn Quinn (JIRA)
issues at jboss.org
Sun Jul 9 10:48:00 EDT 2017
[ https://issues.jboss.org/browse/DROOLS-1654?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13433171#comment-13433171 ]
KimJohn Quinn commented on DROOLS-1654:
---------------------------------------
All right, I am pretty much about to toss in the towel with this.
_I've attached a zip of my latest test case as well as all the corresponding DRL files (latest-with-traits.zip). _
Either I am doing something drastically wrong or this is potentially a bug with traits when applied to maps or map-based objects.
All I want to do is use a 'trait' to create strongly-type facts against a map-based model. The map-based model is a large bucket of key-value pairs but using traits would give me the ability to create some structure/hierarchy that can be used in the rules rather than trying to constrain against a bunch of map properties directly. My approach was to use the model itself to "prep" or "populate" values initially and then don one to many traits against that model for later use.
What I am tending to see, using your own example or mine is the following:
* Using a type that 'extends' map does not seem to work - I lose that type after the don is performed.
* Using a map directly gets me closer but there are multiple map facts in WM after the don is performed.
* Using a pure type works fine.
* Using a wrapper gives me the same results as #2.
In all cases that do work, the resulting trait is updating the backed model fact as well. In fact, my test cases would pass because the expected 'bmi' result was correct. It was not until I started to apply rules after the don that I realized the problems.
-----------------------------
Here are the latest results of my outputs from each of the tests:
*1. Using the TraitMapCoreTest from Drools: I see multiple Maps in WM after running. Also, until I constrained the 'Don' rule, it fired multiple times but there was only one PersonMap trait in WM - I would of thought that there would be multiple traits in WM from that.*
{quote}Donned
(@org.drools.traits.test.PersonMap.org.drools.core.factmodel.MapCore_Proxy) : [name=john, age=18, height=null]
(@org.drools.traits.test.PersonMap.org.drools.core.factmodel.MapCore_Proxy) : [name=john, height=184.0, age=18]
Model: 2
Trait: 1
Model: MapCore{__$$dynamic_properties_map$$={name=john, age=18, height=184.0}}
Model: MapCore{__$$dynamic_properties_map$$={name=john, age=18, height=184.0}}{quote}
*2. Don'ing a strongly-typed class (with getters/setters) - this is the only example I can get to work as I would expect.*
{quote}Rule 1
Rule 2A: 1.0 (before don)
Rule 2B: 1.0 (after don)
Rule 2C: 1.0
Rule 3: 1.0
Rule 4A: 2.0
Rule 4B: 1.0
Rule 5: 3.0
Model: 1
Trait: 1{quote}
*3. Don'ing with a pure Map. Similar to #1, I see multiple maps in WM after the don. The end result is correct but the multiple maps, which are the same value, worry me for later rules.*
{quote}Rule 1
Rule 2A: 1.0 (before don)
Rule 2B: 1.0 (after don)
Rule 2C: 1.0
Rule 2D: 1
Rule 3: 1.0
Rule 3A: 2
Rule 4A: 2.0
Rule 4B: 1.0
Rule 4A: 2.0
Rule 4B: 1.0
Rule 5: 3.0
Rule 3: 1.0
Rule 3A: 2
Rule 4A: 2.0
Rule 4B: 1.0
Model: 2
Trait: 1
Model: MapCore{__$$dynamic_properties_map$$={weight=1.0, height=2.0, bmi=3.0}}
Model: MapCore{__$$dynamic_properties_map$$={weight=1.0, height=2.0, bmi=3.0}}{quote}
*4. Don'ing using a type that extends Map. This is really the scenario I am shooting for and what started this. The model that I am don'ing against disappears after the don rule and not of the rules after fire because the constraints are not being met.*
{quote}Rule 1
Rule 2A: 1.0 (before don)
Rule 2B: 1.0 (after don)
Rule 2C: 1.0
Rule 3A: 1.0
Rule 3B: (@drools.MyTrait.org.drools.core.factmodel.MapCore_Proxy) : [weight=1.0, height=2.0, bmi=null]
Model: 0
Trait: 1 {quote}
*5. Don'ing using a wrapper which contains the model inside. This gets me close, albeit a lot more effort, but demonstrates the same results. I lose my actual model during the process and eventually need to fall back to getting the model out of the wrapper, even though I insert it from the wrapper early on, to use it. This all happens after performing the don.*
{quote}Rule 0 : {weight=1.0}
Rule 1 : {weight=1.0, height=2.0}
Rule 2A: {weight=1.0, height=2.0} (before don)
Rule 2B: {weight=1.0, height=2.0, bmi=null} (after don)
Rule 2C: (@drools.MyTrait.org.drools.core.factmodel.MapCore_Proxy) : [weight=1.0, height=2.0, bmi=null]
Rule 3 : (@drools.MyTrait.org.drools.core.factmodel.MapCore_Proxy) : [weight=1.0, height=2.0, bmi=null]
Rule 4 : {weight=1.0, height=2.0, bmi=null}
Rule 5 : {weight=1.0, height=2.0, bmi=3.0}
Wrapper: 1
Model : 0
Map : 2
Trait : 1 {quote}
> Don'ing a Map-Based Fact Loses the Fact
> ---------------------------------------
>
> Key: DROOLS-1654
> URL: https://issues.jboss.org/browse/DROOLS-1654
> Project: Drools
> Issue Type: Bug
> Components: core engine
> Affects Versions: 7.0.0.Final
> Environment: * Alpine Linux (in a Docker container)
> * Oracle JDK 8
> * Drools 7.0.0.Final
> * Spring Boot v1.5.4.RELEASE (though testing without any Spring)
> Reporter: KimJohn Quinn
> Assignee: Mario Fusco
> Labels: traits
> Attachments: TraitDonningTest.java, latest-with-traits.zip, traits-with-class.drl, traits-with-maps.drl, traits-with-model.drl, traits.drl
>
>
> It appears that after don'ing the trait the map-based fact it is proxying disappears (or gets retracted).
> There does not seem to be any issue using the trait properties to access the model properties.
> We are trying to use the model, mostly for constraints and updates, then within the rules apply and use traits to give us a stronger-typed fact and easier rule constraining.
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
More information about the jboss-jira
mailing list