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;
}
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);
}
}
}
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;
}
}
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();
}
}
Aggregations