Mule Expression Language AND OPERATOR - java

I want to use the Mule Expression Language to send two input parameters to an API (ex: CodePostal and LibelleVoie).
I do that :
[payload[1].getAdresseNonNormalisee().getObjetAttributs().getCodePostal()] && #[payload[1].getAdresseNonNormalisee().getObjetAttributs().getLibelleVoie()]]
But it does not work, it returns me a String
have you an idea please ?

You have to write everything in one MEL expression:
#[payload[1].getAdresseNonNormalisee().getObjetAttributs().getCodePostal() &&
payload[1].getAdresseNonNormalisee().getObjetAttributs().getLibelleVoie()]]
You used two expressions with some String in between: " && "

Related

Evaluate an expression stored in variable in jmeter using beanshell

I've pulled an expression from SQL db and that expression is stored as String in jmeter beanshell assertion.
Now I would like to use that expression to evaluate different values
String LeftTank_conv = vars.get("Conv_formula_5") + ""; LeftTank_conv = "{x*100*245/345;}"(something like this)
how can I use this string as an expression to evaluate for different x values
TIA
If you really need the possibility to evaluate arbitrary arithmetic formulae you could use JEXL engine which is being used in JMeter's __jexl3() function
Since JMeter 3.1 it's recommended to use Groovy for scripting so I'll provide the example solution using Groovy syntax:
def context = new org.apache.commons.jexl3.MapContext()
context.set('x', 1)
def engine = new org.apache.commons.jexl3.JexlBuilder().create()
def e = engine.createExpression(vars.get('Conv_formula_5'))
def result = e.evaluate(context)
log.info('Execution result: ' + result as String)
Demo:

Filter column based on two conditions spark and Java

I am trying to add a filter on my dataframe, for some reason the || condition is not working in Java, it works perfectly in Scala. The code doesn't even compile. How do we use || operator in filter condition in java
The message says
The operator || is undefined for the argument type(s) org.apache.spark.sql.Column, org.apache.spark.sql.Column
df.filter((df.col("eventNumbers").contains("2") )|| (df.col("eventNumbers").contains("45")))
First, you have to:
import static org.apache.spark.sql.functions.*;
And that scala code in java would be:
df.filter((df.col("eventNumbers").contains("2") ).or(df.col("eventNumbers").contains("45")))
In Java 8, you can use String conditionExpr to filter.
Dataset<Row> df = spark.sqlContext().read()
.option("multiLine", true)
.json(dnsRecordFile)
.filter("type=='A'") // <--- filter by ConditionExpr Str
.select("name", "value");

Regular expression in Drools

I keep getting compile errors when I try to write my rules.
I am trying to translate this condition into drools
if(model.type.series != null && model.type.series.name.mathes(".*FANR.*") ||
model.type.series.name.matches(".*SANA.*"))
//do something....
This is what I have...
rule "Rule 01" salience 0
when
m : model(type.series != null,
type.series.name.matches(".*FANR.*") ||
type.series.name.matches(".*SANA.*")
a : Result(state == Result.GOOD )
then
a.setState(RESULT.BAD);
....
end
What I was trying to do is to use regular expression to match the part of the string where the 'name' is String type. As I am fair new to drools I don't see where it can cause problems, any help would be appreciated
Use correct Drools syntax, according to the matches operator, as described in the Drools manual.
rule FANRorSANA
when
$n: model($v: type.series.name matches ".*(FANR|SANA).*")
then
And you can use the power of regular expressions for testing alternatives.

Unable to parse full javascript if statement from within Java using javascript

So I posted this question
Putting a simple expression language into java
and got a great answer about using ScriptEngine to allow the user to write javascript which I did and it seemed to work
But whilst an expression like
(artist.length>0 ? artist + '-' :'') + (album.length>0 ? album + '-' :'')
works using a full if statement does not
if(artist.length>0) {artist + ':-'} + (album.length>0 ? album + '-' :'')
You might ask why Im doing this, well I was hoping I could use an if:else if:else statement and this was a step towards that
That simply isn't valid javascript. The
<cond> ? <iftrue> : <iffalse>
is the 'expression' form of if-else, and returns the value which can be used.
if {
} else {
}
is the 'statement' version, and is used to execute code, and does NOT return a value.

Struts Regex Validation

I am using struts 1.2.
I need to design a validation that reject characters %,/,?,<,>.
As you can identify last two characters need to be escaped but I am unable to find any specific rules of regex in struts.
String str; //the string to check - load it up with the value from the form
....
if(str.contains("%") || str.contains("/") || str.contains("?") || str.contains("<") || str.contains(">")){
//string contains invalid chars
}else{
//string contains vaild chars
}
No regex involved, and no need to escape chars :) - although there may be better ways of doing it.
This might help you
<constant>
<!--All characters except < > " ' & % ; | and ~-->
<constant-name>allchars</constant-name>
<constant-value>^[^<>"&apos;&%;|~]*$</constant-value>
</constant>

Categories