Search in sources :

Example 6 with ProcessInstanceImpl

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();
    }
}
Also used : ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) StringCorrelationKey(io.automatiko.engine.services.correlation.StringCorrelationKey) CorrelationKey(io.automatiko.engine.services.correlation.CorrelationKey) StringCorrelationKey(io.automatiko.engine.services.correlation.StringCorrelationKey) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ArrayList(java.util.ArrayList) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 7 with ProcessInstanceImpl

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();
}
Also used : WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 8 with ProcessInstanceImpl

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);
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) ArrayList(java.util.ArrayList) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) List(java.util.List) VariableAugmentor(io.automatiko.engine.api.workflow.VariableAugmentor) VariableViolationException(io.automatiko.engine.api.workflow.VariableViolationException) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Collections(java.util.Collections) Node(io.automatiko.engine.workflow.process.core.Node) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ProcessInstanceImpl (io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl)8 Process (io.automatiko.engine.api.definition.process.Process)3 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)3 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)3 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CorrelationKey (io.automatiko.engine.services.correlation.CorrelationKey)2 StringCorrelationKey (io.automatiko.engine.services.correlation.StringCorrelationKey)2 ProcessEventSupport (io.automatiko.engine.workflow.base.core.event.ProcessEventSupport)2 ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)2 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)2 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)2 Map (java.util.Map)2 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)1 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1 ProcessRuntime (io.automatiko.engine.api.runtime.process.ProcessRuntime)1 VariableAugmentor (io.automatiko.engine.api.workflow.VariableAugmentor)1