use of com.walmartlabs.concord.runtime.v2.model.Expression in project concord by walmartlabs.
the class TaskMethodResolver method invoke.
@Override
public Object invoke(ELContext elContext, Object base, Object method, Class<?>[] paramTypes, Object[] params) {
Step step = context.execution().currentStep();
if (!(step instanceof Expression) || !(base instanceof Task) || !(method instanceof String)) {
return null;
}
String taskName = getName(base);
if (taskName == null) {
return null;
}
CallContext callContext = TaskCallInterceptor.CallContext.builder().taskName(taskName).correlationId(context.execution().correlationId()).currentStep(step).processDefinition(context.execution().processDefinition()).build();
TaskCallInterceptor interceptor = context.execution().runtime().getService(TaskCallInterceptor.class);
try {
return interceptor.invoke(callContext, Method.of(base, (String) method, Arrays.asList(params)), () -> super.invoke(elContext, base, method, paramTypes, params));
} catch (javax.el.MethodNotFoundException e) {
throw new MethodNotFoundException(base, method, paramTypes);
} catch (javax.el.ELException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.walmartlabs.concord.runtime.v2.model.Expression 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.model.Expression in project concord by walmartlabs.
the class EventRecordingExecutionListener method afterCommand.
@Override
public Result afterCommand(Runtime runtime, VM vm, State state, ThreadId threadId, Command cmd) {
if (!eventConfiguration.recordEvents()) {
return Result.CONTINUE;
}
if (!(cmd instanceof StepCommand)) {
return Result.CONTINUE;
}
StepCommand<?> s = (StepCommand<?>) cmd;
if (s.getStep() instanceof TaskCall || s.getStep() instanceof Expression) {
return Result.CONTINUE;
}
ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
Location loc = s.getStep().getLocation();
Map<String, Object> m = new HashMap<>();
m.put("processDefinitionId", ProcessDefinitionUtils.getCurrentFlowName(pd, s.getStep()));
m.put("fileName", loc.fileName());
m.put("line", loc.lineNum());
m.put("column", loc.column());
m.put("description", getDescription(s.getStep()));
m.put("correlationId", s.getCorrelationId());
ProcessEventRequest req = new ProcessEventRequest();
// TODO constants
req.setEventType("ELEMENT");
req.setData(m);
req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
try {
eventsApi.event(processInstanceId.getValue(), req);
} catch (ApiException e) {
log.warn("afterCommand [{}] -> error while sending an event to the server: {}", cmd, e.getMessage());
}
return Result.CONTINUE;
}
use of com.walmartlabs.concord.runtime.v2.model.Expression in project concord by walmartlabs.
the class ExpressionCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
state.peekFrame(threadId).pop();
Context ctx = runtime.getService(Context.class);
Expression step = getStep();
String expr = step.getExpr();
ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
Object result = ee.eval(EvalContextFactory.global(ctx), expr, Object.class);
ExpressionOptions opts = Objects.requireNonNull(step.getOptions());
if (!opts.outExpr().isEmpty()) {
ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
Map<String, Object> vars = Collections.singletonMap("result", result);
Map<String, Serializable> out = expressionEvaluator.evalAsMap(EvalContextFactory.global(ctx, vars), opts.outExpr());
out.forEach((k, v) -> ctx.variables().set(k, v));
} else if (opts.out() != null) {
ctx.variables().set(opts.out(), result);
}
}
use of com.walmartlabs.concord.runtime.v2.model.Expression in project quality-measure-and-cohort-service by Alvearie.
the class TestHelper method getTemplateMeasure.
public static Measure getTemplateMeasure(Library library) {
Calendar c = Calendar.getInstance();
c.set(2019, 07, 04, 0, 0, 0);
Date startDate = c.getTime();
c.add(Calendar.YEAR, +1);
Date endDate = c.getTime();
Measure measure = new Measure();
measure.setId("measureId");
measure.setName("test_measure");
measure.setVersion("1.0.0");
measure.setUrl("http://ibm.com/health/Measure/test_measure");
measure.setScoring(new CodeableConcept().addCoding(new Coding().setCode(MeasureScoring.COHORT.toCode())));
measure.setEffectivePeriod(new Period().setStart(startDate).setEnd(endDate));
measure.addLibrary(CanonicalHelper.toCanonicalUrl(library.getUrl(), library.getVersion()));
measure.addGroup().addPopulation().setCode(new CodeableConcept().addCoding(new Coding().setSystem("http://hl7.org/fhir/measure-population").setCode("initial-population"))).setCriteria(new Expression().setExpression("Adult"));
return measure;
}
Aggregations