Search in sources :

Example 16 with ContextInstance

use of io.automatiko.engine.workflow.base.instance.ContextInstance in project automatiko-engine by automatiko-io.

the class WorkflowReuseContextInstanceFactory method getContextInstance.

public ContextInstance getContextInstance(Context context, ContextInstanceContainer contextInstanceContainer, ProcessInstance processInstance) {
    ContextInstance result = contextInstanceContainer.getContextInstance(context.getType(), context.getId());
    if (result != null) {
        return result;
    }
    try {
        AbstractContextInstance contextInstance = (AbstractContextInstance) cls.newInstance();
        contextInstance.setContextId(context.getId());
        contextInstance.setContextInstanceContainer(contextInstanceContainer);
        contextInstance.setProcessInstance(processInstance);
        contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
        NodeInstanceContainer nodeInstanceContainer = null;
        if (contextInstanceContainer instanceof NodeInstanceContainer) {
            nodeInstanceContainer = (NodeInstanceContainer) contextInstanceContainer;
        } else if (contextInstanceContainer instanceof ContextInstance) {
            ContextInstanceContainer parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
            while (parent != null) {
                if (parent instanceof NodeInstanceContainer) {
                    nodeInstanceContainer = (NodeInstanceContainer) parent;
                } else if (contextInstanceContainer instanceof ContextInstance) {
                    parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
                } else {
                    parent = null;
                }
            }
        }
        ((WorkflowContextInstance) contextInstance).setNodeInstanceContainer(nodeInstanceContainer);
        return contextInstance;
    } catch (Exception e) {
        throw new RuntimeException("Unable to instantiate context '" + this.cls.getName() + "': " + e.getMessage());
    }
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)

Aggregations

ContextInstance (io.automatiko.engine.workflow.base.instance.ContextInstance)16 ContextInstanceFactory (io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory)5 AbstractContextInstance (io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance)4 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)3 SwimlaneContextInstance (io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)3 HashMap (java.util.HashMap)3 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)2 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)2 Context (io.automatiko.engine.workflow.base.core.Context)2 ExclusiveGroupInstance (io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance)2 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)2 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)2 DynamicNodeInstance (io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance)2 EventNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)2 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)2 ForEachNodeInstance (io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance)2 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)2 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)2 MilestoneNodeInstance (io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance)2