Search in sources :

Example 11 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class StateBasedNodeInstance method resolveVariable.

protected String resolveVariable(String s) {
    if (s == null) {
        return null;
    }
    ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
    context.setNodeInstance(this);
    context.setProcessInstance(getProcessInstance());
    String v = ((Node) getNode()).getVariableExpression().evaluate(s, context);
    logger.debug("Expression {} was evaluated to {}", s, v);
    return v;
}
Also used : ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 12 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class StateBasedNodeInstance method internalTrigger.

@Override
public void internalTrigger(NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    addCompletionListeners();
    // activate timers
    Map<Timer, ProcessAction> timers = getEventBasedNode().getTimers();
    if (timers != null) {
        addTimerListener();
        timerInstances = new ArrayList<>(timers.size());
        JobsService jobService = getProcessInstance().getProcessRuntime().getJobsService();
        for (Timer timer : timers.keySet()) {
            ExpirationTime expirationTime = createTimerInstance(timer);
            String jobId = jobService.scheduleProcessInstanceJob(ProcessInstanceJobDescription.of(timer.getId(), expirationTime, getProcessInstanceIdWithParent(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getRootProcessId()));
            timerInstances.add(jobId);
        }
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addActivatingNodeId((String) getNode().getMetaData().get("UniqueId"));
    if (getExtendedNode().hasCondition()) {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setProcessInstance(getProcessInstance());
        if (getExtendedNode().getMetaData("ConditionEventType") != null && getExtendedNode().isMet(context)) {
            getProcessInstance().signalEvent((String) getExtendedNode().getMetaData("ConditionEventType"), null);
        } else {
            getProcessInstance().addEventListener("variableChanged", this, false);
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) JobsService(io.automatiko.engine.api.jobs.JobsService) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ExactExpirationTime(io.automatiko.engine.api.jobs.ExactExpirationTime) ExpirationTime(io.automatiko.engine.api.jobs.ExpirationTime) DurationExpirationTime(io.automatiko.engine.api.jobs.DurationExpirationTime) CronExpirationTime(io.automatiko.engine.workflow.base.core.timer.CronExpirationTime) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 13 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class StateNodeInstance method isCompleted.

private boolean isCompleted() {
    if (getProcessInstance() instanceof ExecutableProcessInstance) {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setProcessInstance(getProcessInstance());
        context.setNodeInstance(this);
        return getStateNode().isMet(context);
    } else {
        if (((Node) getNode()).getCompletionCheck().isPresent()) {
            if (((Node) getNode()).getCompletionCheck().get().isValid(getProcessInstance().getVariables())) {
                return true;
            }
        }
        return false;
    }
}
Also used : StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) Node(io.automatiko.engine.workflow.process.core.Node) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 14 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method executeAction.

/**
 * This method is used in both instances of the {@link ExtendedNodeInstanceImpl}
 * and {@link ActionNodeInstance} instances in order to handle exceptions thrown
 * when executing actions.
 *
 * @param action An {@link Action} instance.
 */
protected void executeAction(Action action) {
    ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
    context.setNodeInstance(this);
    context.setProcessInstance(getProcessInstance());
    try {
        action.execute(context);
    } catch (Exception e) {
        String exceptionName = e.getClass().getName();
        ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
        if (exceptionScopeInstance == null) {
            throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
        }
        exceptionScopeInstance.handleException(this, exceptionName, e);
        cancel();
    }
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Aggregations

ProcessContext (io.automatiko.engine.workflow.base.core.context.ProcessContext)14 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)4 AssignmentAction (io.automatiko.engine.workflow.base.instance.impl.AssignmentAction)4 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)3 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)3 DurationExpirationTime (io.automatiko.engine.api.jobs.DurationExpirationTime)2 JobsService (io.automatiko.engine.api.jobs.JobsService)2 Action (io.automatiko.engine.workflow.base.instance.impl.Action)2 SubProcessFactory (io.automatiko.engine.workflow.process.core.node.SubProcessFactory)2 Date (java.util.Date)2 ExactExpirationTime (io.automatiko.engine.api.jobs.ExactExpirationTime)1 ExpirationTime (io.automatiko.engine.api.jobs.ExpirationTime)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 ProcessWorkItemHandlerException (io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 ActionExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)1 CronExpirationTime (io.automatiko.engine.workflow.base.core.timer.CronExpirationTime)1 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)1 ContextInstanceContainer (io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)1 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)1