Search in sources :

Example 6 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class EventNodeInstance method handleAssignment.

private void handleAssignment(Assignment assignment, Object result) {
    AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
    if (action == null) {
        return;
    }
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        WorkItemImpl workItem = new WorkItemImpl();
        workItem.setResult("workflowdata", result);
        workItem.setResult("event", result);
        action.execute(workItem, context);
    } catch (WorkItemExecutionError e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("unable to execute Assignment", e);
    }
}
Also used : AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

Example 7 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class EventSubProcessNodeInstance method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    if (triggerTime == null) {
        // started by signal
        triggerTime = new Date();
    }
    if ("variableChanged".equals(type)) {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setProcessInstance(getProcessInstance());
        context.setNodeInstance(this);
        StartNode startNode = getCompositeNode().findStartNode();
        if (startNode.hasCondition()) {
            if (startNode.isMet(context)) {
                signalEvent(getCompositeNode().getEvents().get(0), null);
            } else {
                removeNodeInstance(this);
                return;
            }
        }
    }
    if (getNodeInstanceContainer().getNodeInstances().contains(this) || type.startsWith("Error-") || type.equals("timerTriggered")) {
        // instances
        if (this.getNodeInstances().isEmpty()) {
            StartNode startNode = getCompositeNode().findStartNode();
            if (resolveVariables(((EventSubProcessNode) getEventBasedNode()).getEvents()).contains(type) || type.equals("timerTriggered")) {
                NodeInstance nodeInstance = getNodeInstance(startNode);
                ((StartNodeInstance) nodeInstance).signalEvent(type, event);
                return;
            }
        }
    }
    super.signalEvent(type, event);
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Date(java.util.Date) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 8 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method handleAssignment.

private void handleAssignment(Assignment assignment, VariableScopeInstance compositeVariableScopeInstance) {
    AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        action.execute(null, context);
    } catch (WorkItemExecutionError e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("unable to execute Assignment", e);
    }
}
Also used : AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

Example 9 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class LambdaSubProcessNodeInstance method internalTrigger.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A SubProcess node only accepts default incoming connections!");
    }
    ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
    context.setNodeInstance(this);
    context.setProcessInstance(getProcessInstance());
    SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
    Object o = subProcessFactory.bind(context);
    io.automatiko.engine.api.workflow.ProcessInstance<?> processInstance = subProcessFactory.createInstance(o);
    io.automatiko.engine.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
    String parentInstanceId = getProcessInstance().getId();
    if (getProcessInstance().getParentProcessInstanceId() != null && !getProcessInstance().getParentProcessInstanceId().isEmpty()) {
        parentInstanceId = getProcessInstance().getParentProcessInstanceId() + ":" + parentInstanceId;
    }
    ((ProcessInstanceImpl) pi).setMetaData("ParentProcessInstanceId", parentInstanceId);
    ((ProcessInstanceImpl) pi).setMetaData("ParentNodeInstanceId", getUniqueId());
    ((ProcessInstanceImpl) pi).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId());
    ((ProcessInstanceImpl) pi).setParentProcessInstanceId(parentInstanceId);
    ((ProcessInstanceImpl) pi).setRootProcessInstanceId(StringUtils.isEmpty(getProcessInstance().getRootProcessInstanceId()) ? getProcessInstance().getId() : getProcessInstance().getRootProcessInstanceId());
    ((ProcessInstanceImpl) pi).setRootProcessId(StringUtils.isEmpty(getProcessInstance().getRootProcessId()) ? getProcessInstance().getProcessId() : getProcessInstance().getRootProcessId());
    ((ProcessInstanceImpl) pi).setSignalCompletion(getSubProcessNode().isWaitForCompletion());
    ((ProcessInstanceImpl) pi).setReferenceFromRoot(getProcessInstance().getReferenceFromRoot());
    processInstance.start();
    this.processInstanceId = processInstance.id();
    this.processInstanceName = processInstance.description();
    subProcessFactory.unbind(context, processInstance.variables());
    if (!getSubProcessNode().isWaitForCompletion()) {
        triggerCompleted();
    } else if (processInstance.status() == ProcessInstance.STATE_COMPLETED || processInstance.status() == ProcessInstance.STATE_ABORTED) {
        triggerCompleted();
    } else {
        String subprocessInstanceId = parentInstanceId + ":" + processInstance.id();
        ((ProcessInstanceImpl) getProcessInstance()).addChild(processInstance.process().id(), subprocessInstanceId);
        addProcessListener();
    }
}
Also used : AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) SubProcessFactory(io.automatiko.engine.workflow.process.core.node.SubProcessFactory) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 10 with ProcessContext

use of io.automatiko.engine.workflow.base.core.context.ProcessContext in project automatiko-engine by automatiko-io.

the class StartNodeInstance method handleAssignment.

private void handleAssignment(Assignment assignment, Object result) {
    AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
    if (action == null) {
        return;
    }
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        WorkItemImpl workItem = new WorkItemImpl();
        workItem.setResult("workflowdata", result);
        workItem.setResult("event", result);
        action.execute(workItem, context);
    } catch (WorkItemExecutionError e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("unable to execute Assignment", e);
    }
}
Also used : AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

Aggregations

ProcessContext (io.automatiko.engine.workflow.base.core.context.ProcessContext)14 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)4 AssignmentAction (io.automatiko.engine.workflow.base.instance.impl.AssignmentAction)4 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)3 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)3 DurationExpirationTime (io.automatiko.engine.api.jobs.DurationExpirationTime)2 JobsService (io.automatiko.engine.api.jobs.JobsService)2 Action (io.automatiko.engine.workflow.base.instance.impl.Action)2 SubProcessFactory (io.automatiko.engine.workflow.process.core.node.SubProcessFactory)2 Date (java.util.Date)2 ExactExpirationTime (io.automatiko.engine.api.jobs.ExactExpirationTime)1 ExpirationTime (io.automatiko.engine.api.jobs.ExpirationTime)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 ProcessWorkItemHandlerException (io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 ActionExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)1 CronExpirationTime (io.automatiko.engine.workflow.base.core.timer.CronExpirationTime)1 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)1 ContextInstanceContainer (io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)1 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)1