use of org.apache.commons.jexl3.JexlExpression in project hl7v2-fhir-converter by LinuxForHealth.
the class JexlEngineUtil method evaluate.
public Object evaluate(String jexlExp, Map<String, Object> context) {
Preconditions.checkArgument(StringUtils.isNotBlank(jexlExp), "jexlExp cannot be blank");
Preconditions.checkArgument(context != null, "context cannot be null");
String trimedJexlExp = StringUtils.trim(jexlExp);
// ensure that expression
validateExpression(trimedJexlExp);
LOGGER.debug("Evaluating expression : {}", trimedJexlExp);
Map<String, Object> localContext = new HashMap<>(functions);
localContext.putAll(context);
JexlExpression exp = exprCache.get(trimedJexlExp);
if (exp == null) {
exp = jexl.createExpression(trimedJexlExp);
exprCache.put(trimedJexlExp, exp);
}
JexlContext jc = new MapContext();
localContext.entrySet().forEach(e -> jc.set(e.getKey(), e.getValue()));
// Now evaluate the expression, getting the result
try {
Object obj = exp.evaluate(jc);
LOGGER.debug("Evaluated expression : {}, returning object {}", trimedJexlExp, obj);
return obj;
} catch (JexlException e) {
throw new DataExtractionException("Exception encountered during JEXL expression evaluation", e);
}
}
use of org.apache.commons.jexl3.JexlExpression in project jxls by jxlsteam.
the class JexlExpressionEvaluator method evaluate.
@Override
public Object evaluate(String expression, Map<String, Object> context) {
JexlContext jexlContext = new MapContext(context);
try {
Map<String, JexlExpression> expressionMap = expressionMapThreadLocal.get();
JexlExpression jexlExpression = expressionMap.get(expression);
if (jexlExpression == null) {
jexlExpression = getJexlEngine().createExpression(expression);
expressionMap.put(expression, jexlExpression);
}
return jexlExpression.evaluate(jexlContext);
} catch (Exception e) {
throw new EvaluationException("An error occurred when evaluating expression " + expression, e);
}
}
use of org.apache.commons.jexl3.JexlExpression in project jxls by jxlsteam.
the class JexlExpressionEvaluatorNoThreadLocal method evaluate.
@Override
public Object evaluate(String expression, Map<String, Object> context) {
JexlContext jexlContext = new MapContext(context);
try {
JexlExpression jexlExpression = expressionMap.get(expression);
if (jexlExpression == null) {
jexlExpression = jexl.createExpression(expression);
expressionMap.put(expression, jexlExpression);
}
return jexlExpression.evaluate(jexlContext);
} catch (Exception e) {
throw new EvaluationException("An error occurred when evaluating expression " + expression, e);
}
}
use of org.apache.commons.jexl3.JexlExpression in project conga by wcm-io-devops.
the class JexlResolver method resolve.
public Object resolve(String expressionString, Map<String, Object> variables) {
Map<String, Object> resolvedVariables = resolveMapWithoutCycles(variables);
try {
JexlExpression expression = jexl.createExpression(expressionString);
JexlContext context = new MapContext(resolvedVariables);
return expression.evaluate(context);
} catch (JexlException ex) {
throw new GeneratorException("Unable to parse expression: ${" + expressionString + "}: " + ex.getMessage(), ex);
}
}
use of org.apache.commons.jexl3.JexlExpression in project waltz by finos.
the class ReferenceBuilderNamespaceTest method evalTest.
@Test
public void evalTest() {
JexlBuilder builder = new JexlBuilder();
JexlEngine jexl = builder.create();
JexlExpression expr = jexl.createExpression("x == 'IN_SCOPE' && y == 10");
MapContext ctx1 = new MapContext();
ctx1.set("x", "IN_SCOPE");
ctx1.set("y", 10);
MapContext ctx2 = new MapContext();
ctx2.set("x", "IN_SCOPE");
ctx2.set("y", 12);
System.out.printf("Result1: [%s]\n", expr.evaluate(ctx1));
System.out.printf("Result2: [%s]\n", expr.evaluate(ctx2));
}
Aggregations