Drools 6.4.0 PropertyReactive Documentation Inconsistency

416 views
Skip to first unread message

Adrian McGrath

unread,
Jun 2, 2016, 3:15:09 PM6/2/16
to Drools Usage
Use Case:
1. I have a java object with the @PropertyReactive annotation
2. I have one rule with a salience of 50 which sets the field names: 'make' and 'model'
3. I have another rule with a salience of 40 which, given certain values of the 'make' field, will modify the value of: 'model'
4. I have a final rule with a salience of 30 which triggers a hardcoded java function with various parameters to do the rest of the processing

Issue:
Section '8.8.3.5. Fine grained property change listeners' of the Documentation (http://docs.jboss.org/drools/release/6.4.0.Final/drools-docs/html/ch08.html) says to use modify() in the drl files with the @PropertyReactive annotation in the java class.

When I attempt to do this, I receive a compiler error saying modify() is undefined. A google search indicated to me that I should use update() instead, since modify() has been removed. When I use update(), it doesn't work as expected - the value of 'make' set in the first rule is not available in the when clause for the second rule. 

Further reading of the documentation lead to this quote:
Note that this feature does not work for update(), and this is one of the reasons why we promote modify() since it encapsulates the field changes within the statement.

Even more looking at the documentation (including the 6.4.0 release notes) suggests that the update() syntax is the older one and modify() should be used (https://docs.jboss.org/drools/release/latest/drools-docs/html/ch02.html#d0e1660): 
Historically these editors supported the older update(x) syntax and hence rules created within the Workbench would not respond correctly to @PropertyReactive and associated annotations within a model. This has now been rectified with the use of modify(x){...} blocks.


Based on everything I'm reading in the documentation, the only way to properly use PropertyReactive is with the modify() syntax however according the drools compiler, the modify() syntax no longer exists. Is all of the documentation wrong or is there something else I'm missing?

Mark Proctor

unread,
Jun 2, 2016, 4:00:28 PM6/2/16
to drools...@googlegroups.com
On 2 Jun 2016, at 20:15, Adrian McGrath <aussi...@gmail.com> wrote:

Use Case:
1. I have a java object with the @PropertyReactive annotation
2. I have one rule with a salience of 50 which sets the field names: 'make' and 'model'
3. I have another rule with a salience of 40 which, given certain values of the 'make' field, will modify the value of: 'model'
4. I have a final rule with a salience of 30 which triggers a hardcoded java function with various parameters to do the rest of the processing

Issue:
Section '8.8.3.5. Fine grained property change listeners' of the Documentation (http://docs.jboss.org/drools/release/6.4.0.Final/drools-docs/html/ch08.html) says to use modify() in the drl files with the @PropertyReactive annotation in the java class.

When I attempt to do this, I receive a compiler error saying modify() is undefined.
you probably used modify wrong

A google search indicated to me that I should use update() instead, since modify() has been removed.
google lies

When I use update(), it doesn't work as expected - the value of 'make' set in the first rule is not available in the when clause for the second rule. 
google lies, you need to use modify, as this captures the changed properties.


Further reading of the documentation lead to this quote:
Note that this feature does not work for update(), and this is one of the reasons why we promote modify() since it encapsulates the field changes within the statement.

Even more looking at the documentation (including the 6.4.0 release notes) suggests that the update() syntax is the older one and modify() should be used (https://docs.jboss.org/drools/release/latest/drools-docs/html/ch02.html#d0e1660): 
Historically these editors supported the older update(x) syntax and hence rules created within the Workbench would not respond correctly to @PropertyReactive and associated annotations within a model. This has now been rectified with the use of modify(x){...} blocks.


Based on everything I'm reading in the documentation, the only way to properly use PropertyReactive is with the modify() syntax however according the drools compiler, the modify() syntax no longer exists. Is all of the documentation wrong or is there something else I'm missing?
I use property reactive and modify in the invaders set of examples. Work through those, it builds up over 6 stages.

Mark

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/4d958d9d-5210-48aa-a4c7-fd6c318bc8a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adrian McGrath

unread,
Jun 3, 2016, 11:48:59 AM6/3/16
to Drools Usage
Hmm, strange. So after looking at what you're doing, I made some modifications and noticed something odd.

This code:
rule "Test Modify"
    salience
50
   
when
        $scanMessage
: ScanMessage(obj.descr != null)
 
             $oidD1 : Oid () from $scanMessage.obj.descr
        Boolean(booleanValue == true) from $oidD1.oid == "v1"
   
        $oidD2
: Oid () from $scanMessage.obj.descr2
        
Boolean(booleanValue == true) from $oidD2.oid == "v2"
   
then
       
String newMake = StringUtils.splitPreserveAllTokens($oidD1.getAttrvalue(), " ")[0].toUpperCase();
   
         modify($scanMessage) {
                  getObj().setMake(newMake);
                  getObj().setName($oidD1.getAttrvalue());
             }
end

Results in the following exception:
Rule Compilation error : [Rule name='Test Modify']
 com
/x/rules/Rule_Test_Modify1738095096.java (8:885) : The method modify(ScanMessage) is undefined for the type Rule_Test_Modify1738095096
 com
/x/rules/Rule_Test_Modify1738095096.java (8:904) : Syntax error, insert ";" to complete Statement
 com
/x/rules/Rule_Test_Modify1738095096.java (9:915) : The method getObj() is undefined for the type Rule_Test_Modify1738095096
 com
/x/rules/Rule_Test_Modify1738095096.java (10:953) : The method getObj() is undefined for the type Rule_Test_Modify1738095096


However, if I change it to this:
rule "Test Modify"
    salience
50
   
when
        $scanMessage
: ScanMessage(obj.descr != null)
        $oidD1
: Oid () from $scanMessage.obj.descr
       
Boolean(booleanValue == true) from $oidD1.oid == "v1"
   
        $oidD2
: Oid () from $scanMessage.obj.descr2
       
Boolean(booleanValue == true) from $oidD2.oid == "v2"
   
then
       
String newMake = StringUtils.splitPreserveAllTokens($oidD1.getAttrvalue(), " ")[0].toUpperCase();
        modify
($scanMessage) {
            getObj
().setMake(newMake);
        }
        modify($scanMessage) {
            getObj
().setName($oidD1.getAttrvalue());
        
}
end

It compiles correctly. I guess you can only make one modification per block. The documentation shows multiple modifications in the same block, so I'm not sure why I cannot do that.

Unfortunately, this also seems to trigger an infinite loop, as the rule reevaluates when the value changes, which is what I was attempting to avoid with the PropertyReactive annotation...
Message has been deleted

Adrian McGrath

unread,
Jun 3, 2016, 11:59:34 AM6/3/16
to Drools Usage
I just realized it uses commas instead of semicolons. The infinite loop issue is still a thing, however.

Mark Proctor

unread,
Jun 3, 2016, 12:28:43 PM6/3/16
to drools...@googlegroups.com
 getObj().setMake(newMake);
That is not going to work. We can only analyse the first accessor, not the nested accessor.

It must be in the format
modify (myObject) { setMyField( value) }

Mark

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages