use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class ReturnValueConstraintEvaluator method evaluate.
public boolean evaluate(NodeInstance instance, Connection connection, Constraint constraint) {
Object value;
try {
ProcessContext context = new ProcessContext(((ProcessInstance) instance.getProcessInstance()).getProcessRuntime());
context.setNodeInstance(instance);
value = this.evaluator.evaluate(context);
} catch (Exception e) {
LOGGER.warn("Constraints evaluation for expression {} failed", constraint, e);
return false;
}
if (!(value instanceof Boolean)) {
LOGGER.warn("Constraints must return boolean values: " + value + " for expression " + constraint);
return false;
}
return ((Boolean) value).booleanValue();
}
use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class DefaultExceptionScopeInstance method handleException.
public void handleException(io.automatiko.engine.api.runtime.process.NodeInstance nodeInstance, ExceptionHandler handler, String exception, Object params) {
if (handler instanceof ActionExceptionHandler) {
ActionExceptionHandler exceptionHandler = (ActionExceptionHandler) handler;
if (retryAvailable(nodeInstance, exceptionHandler)) {
Integer retryAttempts = ((NodeInstanceImpl) nodeInstance).getRetryAttempts();
if (retryAttempts == null) {
retryAttempts = 1;
} else {
retryAttempts = retryAttempts + 1;
}
long delay = calculateDelay(exceptionHandler.getRetryAfter().longValue(), retryAttempts, exceptionHandler.getRetryIncrement(), exceptionHandler.getRetryIncrementMultiplier());
DurationExpirationTime expirationTime = DurationExpirationTime.after(delay);
JobsService jobService = getProcessInstance().getProcessRuntime().getJobsService();
String jobId = jobService.scheduleProcessInstanceJob(ProcessInstanceJobDescription.of(nodeInstance.getNodeId(), "retry:" + nodeInstance.getId(), expirationTime, ((NodeInstanceImpl) nodeInstance).getProcessInstanceIdWithParent(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getRootProcessId()));
((NodeInstanceImpl) nodeInstance).internalSetRetryJobId(jobId);
((NodeInstanceImpl) nodeInstance).internalSetRetryAttempts(retryAttempts);
((NodeInstanceImpl) nodeInstance).registerRetryEventListener();
if (nodeInstance instanceof WorkItemNodeInstance) {
((WorkItemImpl) ((WorkItemNodeInstance) nodeInstance).getWorkItem()).setState(WorkItem.RETRYING);
}
} else {
Action action = (Action) exceptionHandler.getAction().getMetaData("Action");
try {
ProcessInstance processInstance = getProcessInstance();
ProcessContext processContext = new ProcessContext(processInstance.getProcessRuntime());
ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer();
if (contextInstanceContainer instanceof NodeInstance) {
processContext.setNodeInstance((NodeInstance) contextInstanceContainer);
} else {
processContext.setProcessInstance(processInstance);
}
String faultVariable = exceptionHandler.getFaultVariable();
if (faultVariable != null) {
processContext.setVariable(faultVariable, params);
}
action.execute(processContext);
} catch (Exception e) {
throw new RuntimeException("unable to execute Action", e);
}
}
} else {
throw new IllegalArgumentException("Unknown exception handler " + handler);
}
}
use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class ActionNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
triggerTime = new Date();
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
}
Action action = (Action) getActionNode().getAction().getMetaData("Action");
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
executeAction(action);
} catch (WorkflowRuntimeException wre) {
throw wre;
} catch (Exception e) {
// - or context.setNodeInstance(this)
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
}
triggerCompleted();
}
use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
action.execute(getWorkItem(), context);
} catch (WorkItemExecutionError e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("unable to execute Assignment", e);
}
}
use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class LambdaSubProcessNodeInstance method handleOutMappings.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void handleOutMappings(ProcessInstance processInstance) {
SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
context.setProcessInstance(getProcessInstance());
io.automatiko.engine.api.workflow.ProcessInstance<?> pi = ((io.automatiko.engine.api.workflow.ProcessInstance<?>) processInstance.getMetaData().get("AutomatikProcessInstance"));
if (pi != null) {
subProcessFactory.unbind(context, pi.variables());
}
}
Aggregations