[rules-users] Drools Guvnor: DSL with multiple fact fields conditions using "-" and eval

Patricia Bogoevici patriciabogoevici at yahoo.com
Fri Aug 27 12:48:35 EDT 2010


Thx for your answer, Wolfgang.

To be honest, when I first ran into this, I was in doubt whether that is a parsing error in Drools (or  mvel)? Or is an error that I got into because of how I constructed the DSL expression?
It seems that it is an error in Drools and I wonder if that should be reported as an issue in Jira.

--- On Fri, 8/27/10, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:

From: Wolfgang Laun <wolfgang.laun at gmail.com>
Subject: Re: [rules-users] Drools Guvnor: DSL with multiple fact fields conditions using "-" and eval
To: "Rules Users List" <rules-users at lists.jboss.org>
Date: Friday, August 27, 2010, 2:58 AM

It seems that the initial hyphen merges the DSL definition's right hand side into the parenthesis of the last preceding term, even if that one is an eval, which itself is meant to go into some preceding pattern.


You could work around that by making all evals Conditional Elements rather than Inline Eval Constraints. The disadvantage is that you'll have to use full object qualification, e.g., 

[when]where name is empty=eval(StringUtils.isBlank( asset.getName() )


Patricia:
True. But, that is a test case, and does not affect the result of what I was testing

I think that your variant

   [when]-name empty=name=="''"

has to be written without the apostrophes:

   [when]-name empty=name==""

-W






2010/8/27 Patricia Bogoevici <patriciabogoevici at yahoo.com>


Thx for your answer.

I tried again the rule, removing the extra space after hyphen from DSL expresion. No luck. So, I tried a few more cases, and the only one that worked correctly was #3. 
It seems to me that is somehow related to the parenthesis, although it might be something else. Hope this info helps. 


1) only eval:
DSL:
[when] There is an Asset=asset:Asset()
[when]-name is empty=eval(name=="''")
[when]-tag is empty=eval(tag=="''")

Rule source:

    rule "test_rule"
    dialect "mvel"
        when
            asset:Asset( eval(name=="''", eval(tag=="''") ) )
        then
    end

2) no eval, but with the parenthesis:

DSL:
[when] There is an
 Asset=asset:Asset()
[when]-name is empty=(name=="''")
[when]-tag is empty=(tag=="''")

Rule source
    rule "test_rule"
    dialect "mvel"

        when
            asset:Asset( (name=="''", (tag=="''") ) )
        then
    end

3) simple case
DSL
[when] There is an Asset=asset:Asset()

[when]-name empty=name=="''"
[when]-tag empty=tag=="''"

Rule Source:
    rule "test_rule"
    dialect "mvel"
        when
             asset:Asset( name=="''", tag=="''" )

        then
    end

Thanks,

--- On Thu, 8/26/10, Mauricio Salatino <salaboy at gmail.com>
 wrote:

From: Mauricio Salatino <salaboy at gmail.com>

Subject: Re: [rules-users] Drools Guvnor: DSL with multiple fact fields conditions using "-" and eval
To: "Rules Users List" <rules-users at lists.jboss.org>

Date: Thursday, August 26, 2010, 10:43 PM

can you try with this:
[when] There is an Asset=asset:Asset()
[when] -name is 
empty=eval(StringUtils.isBlank(name))

[when] -tag is 
empty=eval(StringUtils.isBlank(tag))

2010/8/26 Patricia Bogoevici <patriciabogoevici at yahoo.com>




Hi all,

I am using the latest Guvnor release (5.1), and I have the following DSL expression where I use "-" to have conditions on multiple lines:

[when] There is an Asset=asset:Asset()
[when]- name is empty=eval(StringUtils.isBlank(name))


[when]- tag is empty=eval(StringUtils.isBlank(tag))

Having these DSL expressions, I wanted to create a rule, but I ran into some issues. 
To summarize: There seems to be a parsing error, when conditions are added in DSL using "-".  Did anybody else run into this problem? I wonder if I do something wrong, but, re-creating the DSL to have the 2 conditions into one expression, is all working fine. It may be a combination of "-" and eval? 



Below, is the description of rules created, and error I got.

First, I created a rule using the above DSL expressions in the BRL editor. While the
 rule looked ok in the editor, and it validated fine, only when I checked the source I noticed is wrong. So, the rule source looks like this:
rule "test_dsl"
        dialect "mvel"
        when


            asset:Asset( eval(StringUtils.isBlank(name, eval(StringUtils.isBlank(tag)) )) )
        then
            asset.setStatus("INVALID")
    end

It looks that the conditions are parsed incorrectly, and the second eval condition is added as a parameter to the StringUtils.isBlank from the first eval. Also, all the right parenthesis are added at the end of the expression. If I add one condition at a time, it all works fine. The error is when I have more than 1 condition. 



So, I created a new DSL, that contains both
 conditions into one line, eliminating the hyphen between conditions:

[when] There is an asset with name empty AND tag empty =asset:Asset(eval(StringUtils.isBlank(name)),eval(StringUtils.isBlank(tag)))

Using  BRL editor, I created a second rule using the DSL above. The rule validated ok, and the rule source looks fine:



rule "test_dsl_1"
        dialect "mvel"
        when
            asset:Asset(eval(StringUtils.isBlank(name)),eval(StringUtils.isBlank(tag)))
        then
            asset.setStatus("INVALID")


    end

I created a test for this rule, that ran correctly.


Thanks,
Patricia



      
_______________________________________________

rules-users mailing list

rules-users at lists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users





-- 
 - CTO @ http://www.plugtree.com  
 - MyJourney @ http://salaboy.wordpress.com


 - Co-Founder @ http://www.jbug.com.ar
 
 - Salatino "Salaboy" Mauricio -


-----Inline Attachment Follows-----

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users









      
_______________________________________________

rules-users mailing list

rules-users at lists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users





-----Inline Attachment Follows-----

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100827/7cbaab2d/attachment.html 


More information about the rules-users mailing list