Search in sources :

Example 6 with WorkItemExecutionError

use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.

the class RuleSetNodeInstance method internalTrigger.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void internalTrigger(final NodeInstance from, String type) {
    try {
        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 RuleSetNode only accepts default incoming connections!");
        }
        RuleSetNode ruleSetNode = getRuleSetNode();
        Map<String, Object> inputs = evaluateParameters(ruleSetNode);
        RuleSetNode.RuleType ruleType = ruleSetNode.getRuleType();
        if (ruleType.isDecision()) {
            RuleSetNode.RuleType.Decision decisionModel = (RuleSetNode.RuleType.Decision) ruleType;
            String dName = resolveVariable(decisionModel.getDecision());
            DecisionModel modelInstance = getRuleSetNode().getDecisionModel().get();
            Object context = modelInstance.newContext(inputs);
            Object dmnResult = null;
            if (dName == null) {
                dmnResult = modelInstance.evaluateAll(context);
            } else if (decisionModel.isDecisionService()) {
                dmnResult = modelInstance.evaluateDecisionService(context, dName);
            } else {
                dmnResult = modelInstance.evaluateDecisionByName(context, dName);
            }
            if (modelInstance.hasErrors(dmnResult)) {
                throw new WorkItemExecutionError("DecisionEvaluationFailure", modelInstance.buildErrorMessage(dmnResult), modelInstance.getErrorData(dmnResult));
            }
            processOutputs(inputs, modelInstance.getResultData(dmnResult));
            triggerCompleted();
        } else {
            throw new UnsupportedOperationException("Unsupported Rule Type: " + ruleType);
        }
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) DecisionModel(io.automatiko.engine.api.decision.DecisionModel) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

Example 7 with WorkItemExecutionError

use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.

the class RuleSetNodeInstance method handleException.

private void handleException(Throwable e) {
    String exceptionName = e.getClass().getName();
    Object param = e;
    if (e instanceof WorkItemExecutionError) {
        param = ((WorkItemExecutionError) e).getErrorData();
        exceptionName = ((WorkItemExecutionError) e).getErrorCode();
    }
    ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(exceptionName);
    if (exceptionScopeInstance != null) {
        exceptionScopeInstance.handleException(this, exceptionName, param != null ? param : e);
    } else {
        Throwable rootCause = getRootException(e);
        if (rootCause != null) {
            exceptionName = rootCause.getClass().getName();
            param = rootCause;
            if (rootCause instanceof WorkItemExecutionError) {
                param = ((WorkItemExecutionError) rootCause).getErrorData();
                exceptionName = ((WorkItemExecutionError) rootCause).getErrorCode();
            }
            exceptionScopeInstance = getExceptionScopeInstance(exceptionName);
            if (exceptionScopeInstance != null) {
                exceptionScopeInstance.handleException(this, exceptionName, param != null ? param : e);
                return;
            }
        }
        if (e instanceof WorkItemExecutionError) {
            throw (WorkItemExecutionError) e;
        }
        throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
    }
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 8 with WorkItemExecutionError

use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError 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 9 with WorkItemExecutionError

use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError 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 10 with WorkItemExecutionError

use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method internalTrigger.

@Override
public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    WorkItemNode workItemNode = getWorkItemNode();
    createWorkItem(workItemNode);
    if (workItemNode.isWaitForCompletion()) {
        addWorkItemListener();
    }
    ((WorkItemImpl) workItem).setNodeInstanceId(this.getId());
    ((WorkItemImpl) workItem).setNodeId(getNodeId());
    workItem.setNodeInstance(this);
    workItem.setProcessInstance(getProcessInstance());
    setProcessId();
    try {
        ((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
    } catch (WorkItemHandlerNotFoundException wihnfe) {
        getProcessInstance().setState(STATE_ABORTED);
        throw wihnfe;
    } catch (ProcessWorkItemHandlerException handlerException) {
        this.workItemId = workItem.getId();
        removeEventListeners();
        handleWorkItemHandlerException(handlerException, workItem);
    } catch (WorkItemExecutionError e) {
        removeEventListeners();
        handleException(e.getErrorCode(), e);
    } catch (Exception e) {
        removeEventListeners();
        String exceptionName = e.getClass().getName();
        handleException(exceptionName, e);
    }
    if (!workItemNode.isWaitForCompletion()) {
        triggerCompleted();
    }
    this.workItemId = workItem.getId();
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessWorkItemHandlerException(io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException) 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)

Aggregations

WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)14 AssignmentAction (io.automatiko.engine.workflow.base.instance.impl.AssignmentAction)5 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)5 ProcessContext (io.automatiko.engine.workflow.base.core.context.ProcessContext)4 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)4 DateTimeParseException (java.time.format.DateTimeParseException)3 Model (io.automatiko.engine.api.Model)2 ProcessWorkItemHandlerException (io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException)2 ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)2 WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)2 HashMap (java.util.HashMap)2 Application (io.automatiko.engine.api.Application)1 DecisionModel (io.automatiko.engine.api.decision.DecisionModel)1 Connection (io.automatiko.engine.api.definition.process.Connection)1 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)1 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)1 NodeInstanceContainer (io.automatiko.engine.api.runtime.process.NodeInstanceContainer)1 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)1 ExecutionsErrorInfo (io.automatiko.engine.api.workflow.ExecutionsErrorInfo)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1