use of io.automatiko.engine.workflow.process.core.node.SubProcessFactory 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());
}
}
use of io.automatiko.engine.workflow.process.core.node.SubProcessFactory 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();
}
}
Aggregations