Search in sources :

Example 6 with ProcessInstance

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();
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance)

Example 7 with ProcessInstance

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;
}
Also used : ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory)

Example 8 with ProcessInstance

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.");
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance)

Example 9 with ProcessInstance

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());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Process(io.automatiko.engine.api.definition.process.Process) Date(java.util.Date) Collection(java.util.Collection) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 10 with ProcessInstance

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);
        }
    }
}
Also used : ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)

Aggregations

ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)13 Process (io.automatiko.engine.api.definition.process.Process)4 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)4 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)4 ArrayList (java.util.ArrayList)4 ContextInstance (io.automatiko.engine.workflow.base.instance.ContextInstance)3 ContextInstanceFactory (io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory)3 ProcessInstanceImpl (io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl)3 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)3 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)3 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)2 CorrelationKey (io.automatiko.engine.services.correlation.CorrelationKey)2 StringCorrelationKey (io.automatiko.engine.services.correlation.StringCorrelationKey)2 ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)2 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)1 DurationExpirationTime (io.automatiko.engine.api.jobs.DurationExpirationTime)1