Search in sources :

Example 1 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project jmeter by apache.

the class Jexl3Function method getJexlEngine.

/**
     * Get JexlEngine from ThreadLocal
     * @return JexlEngine
     */
private static JexlEngine getJexlEngine() {
    JexlEngine engine = threadLocalJexl.get();
    if (engine == null) {
        engine = new JexlBuilder().cache(512).silent(true).strict(true).debug(false).create();
        threadLocalJexl.set(engine);
    }
    return engine;
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder)

Example 2 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project dbeaver by serge-rider.

the class DBVUtils method parseExpression.

public static JexlExpression parseExpression(String expression) {
    Map<String, Object> nsList = getExpressionNamespaces();
    JexlBuilder jexlBuilder = new JexlBuilder();
    jexlBuilder.cache(100);
    jexlBuilder.namespaces(nsList);
    JexlEngine jexlEngine = jexlBuilder.create();
    return jexlEngine.createExpression(expression);
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder)

Example 3 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.

the class PredicateEvaluatorTest method evaluate.

@Test
public void evaluate() {
    ImmutableAssessmentContextValue assessmentValue = ImmutableAssessmentContextValue.builder().ratingCode("A").ratingName("aRating").ratingExternalId("A_RATING").ratingComment("a rating description").build();
    ImmutableSurveyQuestionResponseContextValue surveyValue = ImmutableSurveyQuestionResponseContextValue.builder().value("yes").comment("a survey comment").build();
    ImmutableContextVariable<Object> assessmentVar = ImmutableContextVariable.builder().name("assessmentVar").value(assessmentValue).entityRef(EntityReference.mkRef(EntityKind.APPLICATION, 1L)).build();
    ImmutableContextVariable<Object> surveyVar = ImmutableContextVariable.builder().name("surveyVar").value(surveyValue).entityRef(EntityReference.mkRef(EntityKind.APPLICATION, 1L)).build();
    Set<ContextVariable<?>> contextVariables = asSet(assessmentVar, surveyVar);
    JexlBuilder builder = new JexlBuilder();
    JexlEngine jexl = builder.create();
    JexlExpression pred1Expr = jexl.createExpression("assessmentVar.ratingCode == 'A'");
    JexlExpression pred2Expr = jexl.createExpression("assessmentVar.ratingCode == 'C' || surveyVar.value == 'yes'");
    JexlExpression pred3Expr = jexl.createExpression("assessmentVar.ratingCode == 'C'");
    JexlExpression invalidExpr = jexl.createExpression("foo?.bar");
    MapContext ctx = createContext(contextVariables);
    assertTrue(evaluatePredicate(pred1Expr, ctx), "pred1Expr should evaluate true, rating equals A");
    assertTrue(evaluatePredicate(pred2Expr, ctx), "pred2Expr should evaluate true, survey value equals 'yes");
    assertFalse(evaluatePredicate(pred3Expr, ctx), "pred3Expr should evaluate false, rating equals A");
    assertFalse(evaluatePredicate(invalidExpr, ctx), "Invalid expressions should return false");
    Object evaluate = invalidExpr.evaluate(ctx);
    System.out.println(evaluate);
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder) JexlExpression(org.apache.commons.jexl3.JexlExpression) MapContext(org.apache.commons.jexl3.MapContext) Test(org.junit.jupiter.api.Test)

Example 4 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.

the class TransitionDefinitionCompiler method compile.

public static List<CompiledTransitionDefinition> compile(List<TransitionDefinition> defns) {
    JexlBuilder builder = new JexlBuilder();
    JexlEngine jexl = builder.create();
    return map(defns, d -> d.compile(jexl));
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder)

Example 5 with JexlBuilder

use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.

the class SideEffectTest method canMakeAssessmentRefs.

@Test
public void canMakeAssessmentRefs() {
    JexlBuilder builder = new JexlBuilder();
    TestSideEffectNamespace testNamespace = new TestSideEffectNamespace();
    JexlEngine jexl = builder.namespaces(newHashMap("assessment", new AssessmentSideEffectNamespace(), "test", testNamespace)).create();
    MapContext ctx = new MapContext();
    String messageString = "I have updated something!";
    ctx.set("message", messageString);
    JexlExpression sideEffectExpression = jexl.createExpression("assessment:update('ARCH_REVIEW', 'YES')");
    JexlExpression messageExpression = jexl.createExpression("test:sendMessage(message)");
    messageExpression.evaluate(ctx);
    assertEquals(messageString, testNamespace.lastMessage, "Should be able to use context as part of expression");
    assertEquals(AssessmentSideEffectNamespace.update("ARCH_REVIEW", "YES"), sideEffectExpression.evaluate(ctx), "Should be able to parse survey templateExtId and ratingExtId from update()");
}
Also used : JexlEngine(org.apache.commons.jexl3.JexlEngine) JexlBuilder(org.apache.commons.jexl3.JexlBuilder) MapContext(org.apache.commons.jexl3.MapContext) JexlExpression(org.apache.commons.jexl3.JexlExpression) Test(org.junit.jupiter.api.Test)

Aggregations

JexlBuilder (org.apache.commons.jexl3.JexlBuilder)9 JexlEngine (org.apache.commons.jexl3.JexlEngine)8 MapContext (org.apache.commons.jexl3.MapContext)4 JexlExpression (org.apache.commons.jexl3.JexlExpression)3 Test (org.junit.jupiter.api.Test)3 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 StopWatch (org.apache.nifi.util.StopWatch)1