Re: struggling with ternary operator on simple expression

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: struggling with ternary operator on simple expression

Claus Ibsen-2
Hi

There is no support for elvis or ternary operators.
You can use camel-groovy and groovy language for such kind

The docs on the website has the details what is supported
https://camel.apache.org/components/latest/languages/simple-language.html



On Thu, Oct 15, 2020 at 2:24 PM nomit babraa <[hidden email]> wrote:

>
> Hi
>
> Using the ternary operator logic as described here
> http://www.davsclaus.com/2011/09/camel-29-much-improved-simple-language.html
>
> I am trying to set a exchange property like so where
> exchangeProperty.StatusMsg = 'abc'
>
> .setProperty("StatusMsg2")
> .simple("${exchangeProperty.StatusMsg} == null ? 'ee2e2e2' : 'fffffff'")
>
> That sets StatusMsg2 to the the string
>
> abc == null ? 'ee2e2e2' : 'fffffff'
>
> as the value, rather than evaluating the expression.
>
> I am using camel 2.29 and have checked my spaces are correct
>
> if I replace with
>
> .simple("true ? 'ee2e2e2' : 'fffffff'")
>
> I get the string
>
> true ? 'ee2e2e2' : 'fffffff'
>
> If I do
>
> simple(true ? "ee2e2e2" : "fffffff")
>
> I then get the string
>
> ee2e2e2
>
> If I try
>
> .simple("${exchangeProperty.StatusMsg} == null" ? "ee2e2e2" : "fffffff")
>
> I get a "Type mismatch: cannot convert from String to boolean" compilation error
>
> How do I get the first part of my ternary expression to be recognised
> as an expression itself?
>
> Thanks for any advice
>
>
> n



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: struggling with ternary operator on simple expression

Claus Ibsen-2
Hi

Btw working on compiled simple language (experiment now) but at first
working on a new camel-joor language that uses java code, so you can
then use javas ternary operator:
camel.apache.org/components/latest/languages/joor-language.html

On Thu, Oct 15, 2020 at 2:31 PM Claus Ibsen <[hidden email]> wrote:

>
> Hi
>
> There is no support for elvis or ternary operators.
> You can use camel-groovy and groovy language for such kind
>
> The docs on the website has the details what is supported
> https://camel.apache.org/components/latest/languages/simple-language.html
>
>
>
> On Thu, Oct 15, 2020 at 2:24 PM nomit babraa <[hidden email]> wrote:
> >
> > Hi
> >
> > Using the ternary operator logic as described here
> > http://www.davsclaus.com/2011/09/camel-29-much-improved-simple-language.html
> >
> > I am trying to set a exchange property like so where
> > exchangeProperty.StatusMsg = 'abc'
> >
> > .setProperty("StatusMsg2")
> > .simple("${exchangeProperty.StatusMsg} == null ? 'ee2e2e2' : 'fffffff'")
> >
> > That sets StatusMsg2 to the the string
> >
> > abc == null ? 'ee2e2e2' : 'fffffff'
> >
> > as the value, rather than evaluating the expression.
> >
> > I am using camel 2.29 and have checked my spaces are correct
> >
> > if I replace with
> >
> > .simple("true ? 'ee2e2e2' : 'fffffff'")
> >
> > I get the string
> >
> > true ? 'ee2e2e2' : 'fffffff'
> >
> > If I do
> >
> > simple(true ? "ee2e2e2" : "fffffff")
> >
> > I then get the string
> >
> > ee2e2e2
> >
> > If I try
> >
> > .simple("${exchangeProperty.StatusMsg} == null" ? "ee2e2e2" : "fffffff")
> >
> > I get a "Type mismatch: cannot convert from String to boolean" compilation error
> >
> > How do I get the first part of my ternary expression to be recognised
> > as an expression itself?
> >
> > Thanks for any advice
> >
> >
> > n
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2