[rules-users] Test if String endsWith()

Omar Baqueiro baqueiro at ooyala.com
Tue Nov 13 09:56:45 EST 2012


It seems I have to use 5.0.I am using Drools as part of a third party
framework called MuleESB (
http://www.mulesoft.org/documentation/display/MULE3USER/Drools+Module+Reference
), so I don't think I have to use the provided version.

Is the str[endsWith] operator available on this 5.0 version?

Otherwise, it seems I'll have to do create my own like:
http://blog.athico.com/2010/06/creating-pluggable-oprators.html


Thanks a lot.
O.

On Tue, Nov 13, 2012 at 2:02 AM, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:
> Which version are you using?
>
> 5.4.0 works for me, using either
>    Message(  message.endsWith( "World" ) )
> or
>    Message(  message str[endsWith] "World"  )
>
> -W
>
> On 13/11/2012, Omar Baqueiro <baqueiro at ooyala.com> wrote:
>> Follow up from my question. I have read more from the Drools expert
>> guide (
>> http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html_single
>> ), and in Section 5.8.3.3.10.9 it talks about the str operator:
>>
>> Message( routingValue str[endsWith] "R2" )
>>
>>
>> However, when I try to use the str operator I get an error:
>>
>> no viable alternative at input 'str' in rule "Check the items of the
>> list and remove the ones that satisfy the condition" in pattern
>> OfferWrapper[19,26]: [ERR 102] Line 19:26 mismatched input '
>> "endsWith" ' expecting ']'
>>
>> I tried both using endsWith with quotes and without quotes and I get a
>> similar error in both cases.
>>
>> Mu rule is:
>>> import java.lang.String
>> rule "Check the items of the list and remove the ones that satisfy the
>> condition"
>>      lock-on-active
>>  when
>>      $wrapper : Wrapper(
>>                  id == "itemId",
>>                  email str[endsWith] "@email.com",
>>                  $items : list)
>>      $item    : Map() from $items
>>  then
>>      $items.remove($item)
>>  end
>>
>>
>> Any clue on why am I getting an error?
>> Thanks.
>> O.
>>
>> On Mon, Nov 12, 2012 at 4:44 PM, Omar Baqueiro <baqueiro at ooyala.com> wrote:
>>>
>>> Hello,
>>>
>>> I am trying to evaluate certain data with Drools based on the end of a
>>> string. So far, I have got the following mvel based DRL ( My Wrapper class
>>> has the fields (with all their accessors) id, email and list):
>>>
>>> ---
>>> rule "Check the items of the list and remove the ones that satisfy the
>>> condition"
>>>     lock-on-active
>>> when
>>>     $wrapper : Wrapper(
>>>                 id == "itemId",
>>>                 email.endsWith("@email.com") == true,
>>>                 $items : list)
>>>     $item    : Map() from $items
>>> then
>>>     $items.remove($item)
>>> end
>>> ----
>>>
>>>
>>> However, when trying to apply this rule, I get the  error: no viable
>>> alternative at input '"@gmail.com"' in rule ...".
>>>
>>> What is the correct way to test whether a string ends with certain text
>>> (i.e, using the String.endsWith function using MVEL)
>>>
>>> Thanks for any help!
>>>
>>>
>>> --
>>> --
>>> Omar Baqueiro Espinosa
>>> Software Engineer |
>>> baqueiro at ooyala.com | +52 (33) 3817-0861
>>> www.ooyala.com | blog | @ooyala
>>>
>>
>>
>>
>> --
>> --
>> Omar Baqueiro Espinosa
>> Software Engineer |
>> baqueiro at ooyala.com | +52 (33) 3817-0861
>> www.ooyala.com | blog | @ooyala
>> _______________________________________________
>> 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



-- 
--
Omar Baqueiro Espinosa
Software Engineer |
baqueiro at ooyala.com | +52 (33) 3817-0861
www.ooyala.com | blog | @ooyala


More information about the rules-users mailing list