Search in sources :

Example 1 with AbstractContextInstance

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

the class ReuseContextInstanceFactory 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.setProcessInstance(processInstance);
        contextInstance.setContextId(context.getId());
        contextInstance.setContextInstanceContainer(contextInstanceContainer);
        contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
        return contextInstance;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Unable to instantiate context '" + this.cls.getName() + "': " + e.getMessage(), e);
    }
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance)

Example 2 with AbstractContextInstance

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

the class JsonVariableContextInstanceFactory method getContextInstance.

@Override
public ContextInstance getContextInstance(Context context, ContextInstanceContainer contextInstanceContainer, ProcessInstance processInstance) {
    ContextInstance result = contextInstanceContainer.getContextInstance(context.getType(), context.getId());
    if (result != null) {
        return result;
    }
    AbstractContextInstance contextInstance = new JsonVariableScopeInstance();
    contextInstance.setProcessInstance(processInstance);
    contextInstance.setContextId(context.getId());
    contextInstance.setContextInstanceContainer(contextInstanceContainer);
    contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
    return contextInstance;
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance)

Example 3 with AbstractContextInstance

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

the class ContextInstanceFactoryRegistry method getContextInstance.

private static ContextInstance getContextInstance(Supplier<? extends ContextInstance> supplier, Context context, ContextInstanceContainer contextInstanceContainer, ProcessInstance processInstance) {
    ContextInstance result = contextInstanceContainer.getContextInstance(context.getType(), context.getId());
    if (result != null) {
        return result;
    }
    AbstractContextInstance contextInstance = (AbstractContextInstance) supplier.get();
    contextInstance.setProcessInstance(processInstance);
    contextInstance.setContextId(context.getId());
    contextInstance.setContextInstanceContainer(contextInstanceContainer);
    contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
    return contextInstance;
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance)

Example 4 with AbstractContextInstance

use of io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance 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)4 AbstractContextInstance (io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance)4 ContextInstanceContainer (io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)1 SwimlaneContextInstance (io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)1 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)1