use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class EventNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment, Object result) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
if (action == null) {
return;
}
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setResult("workflowdata", result);
workItem.setResult("event", result);
action.execute(workItem, 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 EventSubProcessNodeInstance method signalEvent.
@Override
public void signalEvent(String type, Object event) {
if (triggerTime == null) {
// started by signal
triggerTime = new Date();
}
if ("variableChanged".equals(type)) {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setProcessInstance(getProcessInstance());
context.setNodeInstance(this);
StartNode startNode = getCompositeNode().findStartNode();
if (startNode.hasCondition()) {
if (startNode.isMet(context)) {
signalEvent(getCompositeNode().getEvents().get(0), null);
} else {
removeNodeInstance(this);
return;
}
}
}
if (getNodeInstanceContainer().getNodeInstances().contains(this) || type.startsWith("Error-") || type.equals("timerTriggered")) {
// instances
if (this.getNodeInstances().isEmpty()) {
StartNode startNode = getCompositeNode().findStartNode();
if (resolveVariables(((EventSubProcessNode) getEventBasedNode()).getEvents()).contains(type) || type.equals("timerTriggered")) {
NodeInstance nodeInstance = getNodeInstance(startNode);
((StartNodeInstance) nodeInstance).signalEvent(type, event);
return;
}
}
}
super.signalEvent(type, event);
}
use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment, VariableScopeInstance compositeVariableScopeInstance) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
action.execute(null, 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 internalTrigger.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A SubProcess node only accepts default incoming connections!");
}
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
context.setProcessInstance(getProcessInstance());
SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
Object o = subProcessFactory.bind(context);
io.automatiko.engine.api.workflow.ProcessInstance<?> processInstance = subProcessFactory.createInstance(o);
io.automatiko.engine.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
String parentInstanceId = getProcessInstance().getId();
if (getProcessInstance().getParentProcessInstanceId() != null && !getProcessInstance().getParentProcessInstanceId().isEmpty()) {
parentInstanceId = getProcessInstance().getParentProcessInstanceId() + ":" + parentInstanceId;
}
((ProcessInstanceImpl) pi).setMetaData("ParentProcessInstanceId", parentInstanceId);
((ProcessInstanceImpl) pi).setMetaData("ParentNodeInstanceId", getUniqueId());
((ProcessInstanceImpl) pi).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId());
((ProcessInstanceImpl) pi).setParentProcessInstanceId(parentInstanceId);
((ProcessInstanceImpl) pi).setRootProcessInstanceId(StringUtils.isEmpty(getProcessInstance().getRootProcessInstanceId()) ? getProcessInstance().getId() : getProcessInstance().getRootProcessInstanceId());
((ProcessInstanceImpl) pi).setRootProcessId(StringUtils.isEmpty(getProcessInstance().getRootProcessId()) ? getProcessInstance().getProcessId() : getProcessInstance().getRootProcessId());
((ProcessInstanceImpl) pi).setSignalCompletion(getSubProcessNode().isWaitForCompletion());
((ProcessInstanceImpl) pi).setReferenceFromRoot(getProcessInstance().getReferenceFromRoot());
processInstance.start();
this.processInstanceId = processInstance.id();
this.processInstanceName = processInstance.description();
subProcessFactory.unbind(context, processInstance.variables());
if (!getSubProcessNode().isWaitForCompletion()) {
triggerCompleted();
} else if (processInstance.status() == ProcessInstance.STATE_COMPLETED || processInstance.status() == ProcessInstance.STATE_ABORTED) {
triggerCompleted();
} else {
String subprocessInstanceId = parentInstanceId + ":" + processInstance.id();
((ProcessInstanceImpl) getProcessInstance()).addChild(processInstance.process().id(), subprocessInstanceId);
addProcessListener();
}
}
use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.
the class StartNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment, Object result) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
if (action == null) {
return;
}
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setResult("workflowdata", result);
workItem.setResult("event", result);
action.execute(workItem, context);
} catch (WorkItemExecutionError e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("unable to execute Assignment", e);
}
}
Aggregations