use of io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class DynamicUtils method executeSubProcess.
private static String executeSubProcess(InternalProcessRuntime runtime, String processId, Map<String, Object> parameters, ProcessInstance processInstance, SubProcessNodeInstance subProcessNodeInstance) {
Process process = runtime.getProcess(processId);
if (process == null) {
logger.error("Could not find process {}", processId);
throw new IllegalArgumentException("No process definition found with id: " + processId);
} else {
ProcessEventSupport eventSupport = runtime.getProcessEventSupport();
eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, runtime);
ProcessInstance subProcessInstance = null;
if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) {
List<String> businessKeys = new ArrayList<>();
businessKeys.add(((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey());
businessKeys.add(processId);
businessKeys.add(String.valueOf(System.currentTimeMillis()));
CorrelationKey subProcessCorrelationKey = new StringCorrelationKey(businessKeys.stream().collect(Collectors.joining(":")));
subProcessInstance = (ProcessInstance) runtime.createProcessInstance(processId, subProcessCorrelationKey, parameters);
} else {
subProcessInstance = (ProcessInstance) runtime.createProcessInstance(processId, parameters);
}
((ProcessInstanceImpl) subProcessInstance).setMetaData("ParentProcessInstanceId", processInstance.getId());
((ProcessInstanceImpl) subProcessInstance).setParentProcessInstanceId(processInstance.getId());
subProcessInstance = (ProcessInstance) runtime.startProcessInstance(subProcessInstance.getId());
subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstance.getId());
eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, runtime);
if (subProcessInstance.getState() == io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED) {
subProcessNodeInstance.triggerCompleted();
} else {
subProcessNodeInstance.addEventListeners();
}
return subProcessInstance.getId();
}
}
use of io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class SubProcessNodeInstance method processInstanceCompleted.
public void processInstanceCompleted(ProcessInstance processInstance) {
removeEventListeners();
((ProcessInstanceImpl) getProcessInstance()).removeChild(processInstance.getProcessId(), processInstance.getId());
handleOutMappings(processInstance);
if (processInstance.getState() == ProcessInstance.STATE_ABORTED) {
String faultName = processInstance.getOutcome() == null ? "" : processInstance.getOutcome();
// handle exception as sub process failed with error code
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
if (exceptionScopeInstance != null) {
exceptionScopeInstance.handleException(this, faultName, processInstance.getFaultData());
if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
cancel();
}
return;
} else if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
return;
}
}
// handle dynamic subprocess
if (getNode() == null) {
setMetaData("NodeType", "SubProcessNode");
}
// if there were no exception proceed normally
triggerCompleted();
}
use of io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class VariableScopeInstance method getVariable.
@SuppressWarnings("unchecked")
public Object getVariable(String name) {
String defaultValue = null;
if (name.contains(":")) {
String[] items = name.split(":");
name = items[0];
defaultValue = items[1];
}
if (name.contains(VariableScope.VERSION_SEPARATOR) && !name.startsWith(VariableScope.VERSION_SEPARATOR)) {
String[] items = name.split("\\" + VariableScope.VERSION_SEPARATOR);
Variable var = getVariableScope().findVariable(items[0]);
if (var.hasTag(Variable.VERSIONED_TAG)) {
Map<String, List<Object>> versions = (Map<String, List<Object>>) variables.computeIfAbsent(VariableScope.VERSIONED_VARIABLES, key -> new ConcurrentHashMap<>());
List<Object> varVersions = (List<Object>) versions.getOrDefault(items[0], Collections.emptyList());
if (items.length == 1) {
return varVersions;
}
try {
int version = Integer.parseInt(items[1]);
if (version < 0) {
// negative position means last item
return varVersions.get(varVersions.size() - 1);
}
// otherwise return version with given number
return varVersions.get(version);
} catch (IndexOutOfBoundsException e) {
// in case position/version points at not existing version return null
return null;
}
}
}
Object value = internalGetVariable(name);
if (value != null) {
return value;
}
// support for processInstanceId and parentProcessInstanceId
if ("processInstanceId".equals(name) && getProcessInstance() != null) {
return getProcessInstance().getId();
} else if ("parentProcessInstanceId".equals(name) && getProcessInstance() != null) {
return getProcessInstance().getParentProcessInstanceId();
} else if (("correlationKey".equals(name) || "businessKey".equals(name)) && getProcessInstance() != null) {
return getProcessInstance().getCorrelationKey();
} else if ("rootProcessInstanceId".equals(name) && getProcessInstance() != null) {
return getProcessInstance().getRootProcessInstanceId();
} else if ("rootProcessId".equals(name) && getProcessInstance() != null) {
return getProcessInstance().getRootProcessId();
} else if ("processId".equals(name) && getProcessInstance() != null) {
return getProcessInstance().getProcessId();
} else if ("processName".equals(name) && getProcessInstance() != null) {
return getProcessInstance().getProcessName();
} else if ("processInstanceName".equals(name) && getProcessInstance() != null) {
return ((ProcessInstanceImpl) getProcessInstance()).getDescription();
}
return systemOrEnvironmentVariable(name, defaultValue);
}
Aggregations