use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class FormCallCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
String eventRef = UUID.randomUUID().toString();
Context ctx = runtime.getService(Context.class);
ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
EvalContext evalContext = EvalContextFactory.global(ctx);
FormCall call = getStep();
String formName = expressionEvaluator.eval(evalContext, call.getName(), String.class);
ProcessDefinition processDefinition = runtime.getService(ProcessDefinition.class);
ProcessConfiguration processConfiguration = runtime.getService(ProcessConfiguration.class);
List<FormField> fields = assertFormFields(expressionEvaluator, evalContext, processConfiguration, processDefinition, formName, call);
Form form = Form.builder().name(formName).eventName(eventRef).options(buildFormOptions(expressionEvaluator, evalContext, call)).fields(buildFormFields(expressionEvaluator, evalContext, fields, Objects.requireNonNull(call.getOptions()).values())).build();
FormService formService = runtime.getService(FormService.class);
formService.save(form);
state.peekFrame(threadId).pop();
state.setEventRef(threadId, eventRef);
state.setStatus(threadId, ThreadStatus.SUSPENDED);
}
use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class OutVariablesProcessor method afterProcessEnds.
@Override
public void afterProcessEnds(Runtime runtime, State state, Frame lastFrame) {
if (outVariables.isEmpty() || lastFrame == null) {
return;
}
Map<String, Object> vars = Collections.unmodifiableMap(lastFrame.getLocals());
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
EvalContext evalContext = DefaultEvalContext.builder().from(EvalContextFactory.strict(vars)).undefinedVariableAsNull(true).build();
Map<String, Object> outValues = new HashMap<>();
for (String out : outVariables) {
// TODO sanitize
Object v = ee.eval(evalContext, "${" + out + "}", Object.class);
if (v == null) {
continue;
}
outValues.put(out, v);
}
if (outValues.isEmpty()) {
return;
}
persistenceService.persistFile(Constants.Files.OUT_VALUES_FILE_NAME, out -> objectMapper.writeValue(out, outValues));
}
use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testStrict.
@Test
public void testStrict() {
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
Map<String, Object> vars = Collections.singletonMap("name", "Concord");
Map<String, Object> strict = Collections.singletonMap("name", "Concord!!!");
EvalContext ctx = EvalContextFactory.strict(new SingleFrameContext(vars), strict);
// ---
String str = ee.eval(ctx, "Hello ${name}", String.class);
assertEquals("Hello Concord!!!", str);
}
use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class LazyExpressionEvaluator method createResolver.
/**
* Based on the original code from {@link StandardELContext#getELResolver()}.
* Creates a {@link ELResolver} instance with "sub-resolvers" in the original order.
*/
private ELResolver createResolver(LazyEvalContext evalContext, ExpressionFactory expressionFactory) {
CompositeELResolver r = new CompositeELResolver();
if (evalContext.scope() != null) {
r.add(new VariableResolver(evalContext.scope()));
}
r.add(new VariableResolver(evalContext.variables()));
if (evalContext.context() != null) {
r.add(new TaskResolver(evalContext.context(), taskProviders));
}
r.add(expressionFactory.getStreamELResolver());
r.add(new StaticFieldELResolver());
r.add(new MapELResolver());
r.add(new MethodAccessorResolver());
r.add(new ResourceBundleELResolver());
r.add(new ListELResolver());
r.add(new ArrayELResolver());
if (evalContext.context() != null) {
r.add(new TaskMethodResolver(evalContext.context()));
}
r.add(new BeanELResolver());
return r;
}
use of com.walmartlabs.concord.runtime.v2.runner.el.EvalContext in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testStrictUndef.
@Test
public void testStrictUndef() {
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
Map<String, Object> vars = Collections.singletonMap("name", "Concord");
Map<String, Object> strict = Collections.emptyMap();
EvalContext ctx = EvalContextFactory.strict(new SingleFrameContext(vars), strict);
// ---
try {
ee.eval(ctx, "Hello ${name}", String.class);
fail("exception expected");
} catch (RuntimeException e) {
assertThat(e.getMessage(), containsString("variable in 'Hello ${name}'"));
}
// undef as null
// ---
String str = ee.eval(undefAsNull(ctx), "Hello ${name}", String.class);
assertNull(str);
}
Aggregations