use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.
the class CheckpointCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
state.peekFrame(threadId).pop();
// eval the name in case it contains an expression
Context ctx = runtime.getService(Context.class);
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
String name = ee.eval(EvalContextFactory.global(ctx), getStep().getName(), String.class);
runtime.getService(SynchronizationService.class).point(() -> {
CheckpointService checkpointService = runtime.getService(CheckpointService.class);
ProcessDefinition processDefinition = runtime.getService(ProcessDefinition.class);
// cleanup the internal state to reduce the serialized data size
state.gc();
// TODO validate checkpoint name
checkpointService.create(threadId, getCorrelationId(), name, runtime, ProcessSnapshot.builder().vmState(state).processDefinition(processDefinition).build());
});
}
use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator 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.ExpressionEvaluator 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.ExpressionEvaluator 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.ExpressionEvaluator in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testAllVariables.
@Test
public void testAllVariables() {
String str = "${allVariables()}";
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
// ---
Map<String, Object> vars = new HashMap<>();
vars.put("a", Collections.singletonList("b"));
vars.put("b", "bb");
Map<String, Object> result = ee.evalAsMap(global(vars), str);
assertEquals(vars, result);
}
Aggregations