use of io.automatiko.engine.workflow.base.instance.ProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method handleWorkItemHandlerException.
/*
* Work item handler exception handling
*/
private void handleWorkItemHandlerException(ProcessWorkItemHandlerException handlerException, WorkItem workItem) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("ProcessInstanceId", workItem.getProcessInstanceId());
parameters.put("WorkItemId", workItem.getId());
parameters.put("NodeInstanceId", this.getId());
parameters.put("ErrorMessage", handlerException.getMessage());
parameters.put("Error", handlerException);
// add all parameters of the work item to the newly started process instance
parameters.putAll(workItem.getParameters());
ProcessInstance processInstance = (ProcessInstance) getProcessInstance().getProcessRuntime().createProcessInstance(handlerException.getProcessId(), parameters);
this.exceptionHandlingProcessInstanceId = processInstance.getId();
((ProcessInstanceImpl) processInstance).setMetaData("ParentProcessInstanceId", getProcessInstance().getId());
((ProcessInstanceImpl) processInstance).setMetaData("ParentNodeInstanceId", getUniqueId());
processInstance.setParentProcessInstanceId(getProcessInstance().getId());
processInstance.setSignalCompletion(true);
getProcessInstance().getProcessRuntime().startProcessInstance(processInstance.getId());
if (processInstance.getState() == STATE_COMPLETED || processInstance.getState() == STATE_ABORTED) {
exceptionHandlingCompleted(processInstance, handlerException);
} else {
addExceptionProcessListener();
}
}
use of io.automatiko.engine.workflow.base.instance.ProcessInstance in project automatiko-engine by automatiko-io.
the class LambdaSubProcessNodeInstance method getContextInstance.
@Override
public ContextInstance getContextInstance(Context context) {
ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
if (conf == null) {
throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
}
ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
if (contextInstance == null) {
throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
}
return contextInstance;
}
use of io.automatiko.engine.workflow.base.instance.ProcessInstance in project automatiko-engine by automatiko-io.
the class EventSubProcessNodeInstance method nodeInstanceCompleted.
@Override
public void nodeInstanceCompleted(io.automatiko.engine.workflow.process.instance.NodeInstance nodeInstance, String outType) {
if (nodeInstance instanceof EndNodeInstance) {
if (getCompositeNode().isKeepActive()) {
StartNode startNode = getCompositeNode().findStartNode();
triggerCompleted(true);
if (startNode.isInterrupting()) {
String faultName = getProcessInstance().getOutcome() == null ? "" : getProcessInstance().getOutcome();
if (startNode.getMetaData("FaultCode") != null) {
faultName = (String) startNode.getMetaData("FaultCode");
}
if (getNodeInstanceContainer() instanceof ProcessInstance) {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_ABORTED);
// to allow top level process instance in case there are no more active nodes
((NodeInstanceContainer) ((ProcessInstance) getProcessInstance())).nodeInstanceCompleted(this, null);
}
}
}
} else {
throw new IllegalArgumentException("Completing a node instance that has no outgoing connection not supported.");
}
}
use of io.automatiko.engine.workflow.base.instance.ProcessInstance in project automatiko-engine by automatiko-io.
the class FaultNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A FaultNode only accepts default incoming connections!");
}
triggerTime = new Date();
if (getProcessInstance().isFunctionFlow(this) && getNodeInstanceContainer() instanceof ProcessInstance) {
// only when running as function flow and node is in the top level node container meaning process instance
// and not subprocesses
getProcessInstance().getMetaData().compute("ATK_FUNC_FLOW_NEXT", (k, v) -> {
if (v == null) {
v = new ArrayList<String>();
}
Process process = getProcessInstance().getProcess();
String version = "";
if (process.getVersion() != null && !process.getVersion().trim().isEmpty()) {
version = ".v" + process.getVersion().replaceAll("\\.", "_");
}
String defaultNextNode = process.getPackageName() + "." + process.getId() + version + "." + getNodeName().toLowerCase();
((List<String>) v).add((String) getNode().getMetaData().getOrDefault("functionType", defaultNextNode));
return v;
});
}
String faultName = getFaultName();
ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(faultName);
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
nodeInstanceContainer.removeNodeInstance(this);
boolean exceptionHandled = false;
if (getFaultNode().isTerminateParent()) {
// events
if (exceptionScopeInstance != null) {
exceptionHandled = true;
handleException(faultName, exceptionScopeInstance);
}
if (nodeInstanceContainer instanceof CompositeNodeInstance) {
((CompositeNodeInstance) nodeInstanceContainer).cancel();
} else if (nodeInstanceContainer instanceof WorkflowProcessInstance) {
Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstance) nodeInstanceContainer).getNodeInstances();
for (NodeInstance nodeInstance : nodeInstances) {
((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).cancel();
}
}
}
String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
if (uniqueId == null) {
uniqueId = ((NodeImpl) getNode()).getUniqueId();
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
if (exceptionScopeInstance != null) {
if (!exceptionHandled) {
handleException(faultName, exceptionScopeInstance);
}
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
if (!hidden) {
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
if (!hidden) {
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} else {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName, getFaultData());
}
}
use of io.automatiko.engine.workflow.base.instance.ProcessInstance in project automatiko-engine by automatiko-io.
the class SubProcessNodeInstance method cancel.
@Override
public void cancel() {
super.cancel();
if (getSubProcessNode() == null || !getSubProcessNode().isIndependent()) {
ProcessInstance processInstance = null;
InternalProcessRuntime kruntime = ((ProcessInstance) getProcessInstance()).getProcessRuntime();
processInstance = (ProcessInstance) kruntime.getProcessInstance(processInstanceId);
if (processInstance != null) {
processInstance.setState(ProcessInstance.STATE_ABORTED);
}
}
}
Aggregations