Search in sources :

Example 6 with Expression

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);
    }
}
Also used : Task(com.walmartlabs.concord.runtime.v2.sdk.Task) Expression(com.walmartlabs.concord.runtime.v2.model.Expression) Step(com.walmartlabs.concord.runtime.v2.model.Step) CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) MethodNotFoundException(com.walmartlabs.concord.runtime.v2.runner.el.MethodNotFoundException) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor) MethodNotFoundException(com.walmartlabs.concord.runtime.v2.runner.el.MethodNotFoundException)

Example 7 with Expression

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());
    });
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) SynchronizationService(com.walmartlabs.concord.runtime.v2.runner.SynchronizationService) CheckpointService(com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 8 with Expression

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;
}
Also used : StepCommand(com.walmartlabs.concord.runtime.v2.runner.vm.StepCommand) ProcessEventRequest(com.walmartlabs.concord.client.ProcessEventRequest) HashMap(java.util.HashMap) ApiException(com.walmartlabs.concord.ApiException)

Example 9 with Expression

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);
    }
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) Serializable(java.io.Serializable) ExpressionOptions(com.walmartlabs.concord.runtime.v2.model.ExpressionOptions) Expression(com.walmartlabs.concord.runtime.v2.model.Expression) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 10 with Expression

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;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Expression(org.hl7.fhir.r4.model.Expression) Calendar(java.util.Calendar) Measure(org.hl7.fhir.r4.model.Measure) Period(org.hl7.fhir.r4.model.Period) Date(java.util.Date) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

Expression (org.hl7.fhir.r4.model.Expression)8 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 Coding (org.hl7.fhir.r4.model.Coding)4 Extension (org.hl7.fhir.r4.model.Extension)3 Measure (org.hl7.fhir.r4.model.Measure)3 Expression (org.hl7.fhir.r5.model.Expression)3 Expression (com.walmartlabs.concord.runtime.v2.model.Expression)2 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)2 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)2 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 StringType (org.hl7.fhir.dstu2.model.StringType)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 ApiException (com.walmartlabs.concord.ApiException)1 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)1 ExpressionOptions (com.walmartlabs.concord.runtime.v2.model.ExpressionOptions)1 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)1 Step (com.walmartlabs.concord.runtime.v2.model.Step)1 SynchronizationService (com.walmartlabs.concord.runtime.v2.runner.SynchronizationService)1 CheckpointService (com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService)1