Search in sources :

Example 1 with ProcessContext

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

the class ReturnValueConstraintEvaluator method evaluate.

public boolean evaluate(NodeInstance instance, Connection connection, Constraint constraint) {
    Object value;
    try {
        ProcessContext context = new ProcessContext(((ProcessInstance) instance.getProcessInstance()).getProcessRuntime());
        context.setNodeInstance(instance);
        value = this.evaluator.evaluate(context);
    } catch (Exception e) {
        LOGGER.warn("Constraints evaluation for expression {} failed", constraint, e);
        return false;
    }
    if (!(value instanceof Boolean)) {
        LOGGER.warn("Constraints must return boolean values: " + value + " for expression " + constraint);
        return false;
    }
    return ((Boolean) value).booleanValue();
}
Also used : ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

Example 2 with ProcessContext

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

the class DefaultExceptionScopeInstance method handleException.

public void handleException(io.automatiko.engine.api.runtime.process.NodeInstance nodeInstance, ExceptionHandler handler, String exception, Object params) {
    if (handler instanceof ActionExceptionHandler) {
        ActionExceptionHandler exceptionHandler = (ActionExceptionHandler) handler;
        if (retryAvailable(nodeInstance, exceptionHandler)) {
            Integer retryAttempts = ((NodeInstanceImpl) nodeInstance).getRetryAttempts();
            if (retryAttempts == null) {
                retryAttempts = 1;
            } else {
                retryAttempts = retryAttempts + 1;
            }
            long delay = calculateDelay(exceptionHandler.getRetryAfter().longValue(), retryAttempts, exceptionHandler.getRetryIncrement(), exceptionHandler.getRetryIncrementMultiplier());
            DurationExpirationTime expirationTime = DurationExpirationTime.after(delay);
            JobsService jobService = getProcessInstance().getProcessRuntime().getJobsService();
            String jobId = jobService.scheduleProcessInstanceJob(ProcessInstanceJobDescription.of(nodeInstance.getNodeId(), "retry:" + nodeInstance.getId(), expirationTime, ((NodeInstanceImpl) nodeInstance).getProcessInstanceIdWithParent(), getProcessInstance().getRootProcessInstanceId(), getProcessInstance().getProcessId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getRootProcessId()));
            ((NodeInstanceImpl) nodeInstance).internalSetRetryJobId(jobId);
            ((NodeInstanceImpl) nodeInstance).internalSetRetryAttempts(retryAttempts);
            ((NodeInstanceImpl) nodeInstance).registerRetryEventListener();
            if (nodeInstance instanceof WorkItemNodeInstance) {
                ((WorkItemImpl) ((WorkItemNodeInstance) nodeInstance).getWorkItem()).setState(WorkItem.RETRYING);
            }
        } else {
            Action action = (Action) exceptionHandler.getAction().getMetaData("Action");
            try {
                ProcessInstance processInstance = getProcessInstance();
                ProcessContext processContext = new ProcessContext(processInstance.getProcessRuntime());
                ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer();
                if (contextInstanceContainer instanceof NodeInstance) {
                    processContext.setNodeInstance((NodeInstance) contextInstanceContainer);
                } else {
                    processContext.setProcessInstance(processInstance);
                }
                String faultVariable = exceptionHandler.getFaultVariable();
                if (faultVariable != null) {
                    processContext.setVariable(faultVariable, params);
                }
                action.execute(processContext);
            } catch (Exception e) {
                throw new RuntimeException("unable to execute Action", e);
            }
        }
    } else {
        throw new IllegalArgumentException("Unknown exception handler " + handler);
    }
}
Also used : NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) Action(io.automatiko.engine.workflow.base.instance.impl.Action) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) JobsService(io.automatiko.engine.api.jobs.JobsService) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) DurationExpirationTime(io.automatiko.engine.api.jobs.DurationExpirationTime) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance)

Example 3 with ProcessContext

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

the class ActionNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    triggerTime = new Date();
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
    }
    Action action = (Action) getActionNode().getAction().getMetaData("Action");
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        executeAction(action);
    } catch (WorkflowRuntimeException wre) {
        throw wre;
    } catch (Exception e) {
        // - or context.setNodeInstance(this)
        throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
    }
    triggerCompleted();
}
Also used : Action(io.automatiko.engine.workflow.base.instance.impl.Action) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) Date(java.util.Date) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)

Example 4 with ProcessContext

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

the class WorkItemNodeInstance method handleAssignment.

private void handleAssignment(Assignment assignment) {
    AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        action.execute(getWorkItem(), context);
    } catch (WorkItemExecutionError e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("unable to execute Assignment", e);
    }
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) 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) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessWorkItemHandlerException(io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)

Example 5 with ProcessContext

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

the class LambdaSubProcessNodeInstance method handleOutMappings.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void handleOutMappings(ProcessInstance processInstance) {
    SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
    ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
    context.setNodeInstance(this);
    context.setProcessInstance(getProcessInstance());
    io.automatiko.engine.api.workflow.ProcessInstance<?> pi = ((io.automatiko.engine.api.workflow.ProcessInstance<?>) processInstance.getMetaData().get("AutomatikProcessInstance"));
    if (pi != null) {
        subProcessFactory.unbind(context, pi.variables());
    }
}
Also used : SubProcessFactory(io.automatiko.engine.workflow.process.core.node.SubProcessFactory) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext)

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