Search in sources :

Example 11 with WorkItemExecutionError

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

Example 12 with WorkItemExecutionError

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

the class WorkflowProcessInstanceImpl method setErrorState.

@Override
public String setErrorState(NodeInstance nodeInstanceInError, Exception e) {
    String errorId = UUID.randomUUID().toString();
    this.nodeIdInError = nodeInstanceInError.getNodeDefinitionId();
    Throwable rootException = getRootException(e);
    String errorDetails = null;
    if (e instanceof WorkItemExecutionError) {
        errorDetails = ((WorkItemExecutionError) e).getErrorDetails();
        addTag(errorDetails);
    } else {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        errorDetails = sw.toString();
    }
    errors.add(new ExecutionsErrorInfo(nodeInstanceInError.getNodeDefinitionId(), errorId, rootException.getMessage(), errorDetails));
    setState(STATE_ERROR);
    logger.error("Unexpected error (id {}) while executing node {} in process instance {}", errorId, nodeInstanceInError.getNode().getName(), this.getId(), e);
    // remove node instance that caused an error
    ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) nodeInstanceInError.getNodeInstanceContainer()).removeNodeInstance(nodeInstanceInError);
    return errorId;
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) StringWriter(java.io.StringWriter) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) PrintWriter(java.io.PrintWriter)

Example 13 with WorkItemExecutionError

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

the class LightProcessRuntime method configureTimerInstance.

private ExpirationTime configureTimerInstance(Timer timer) {
    long duration = -1;
    switch(timer.getTimeType()) {
        case Timer.TIME_CYCLE:
            if (CronExpirationTime.isCronExpression(timer.getDelay())) {
                return CronExpirationTime.of(timer.getDelay());
            } else {
                // when using ISO date/time period is not set
                long[] repeatValues = DateTimeUtils.parseRepeatableDateTime(timer.getDelay());
                if (repeatValues.length == 3) {
                    int parsedReapedCount = (int) repeatValues[0];
                    if (parsedReapedCount > -1) {
                        parsedReapedCount = Integer.MAX_VALUE;
                    }
                    return DurationExpirationTime.repeat(repeatValues[1], repeatValues[2]);
                } else {
                    long delay = repeatValues[0];
                    long period = -1;
                    try {
                        period = TimeUtils.parseTimeString(timer.getPeriod());
                    } catch (RuntimeException e) {
                        period = repeatValues[0];
                    }
                    return DurationExpirationTime.repeat(delay, period);
                }
            }
        case Timer.TIME_DURATION:
            duration = DateTimeUtils.parseDuration(timer.getDelay());
            return DurationExpirationTime.repeat(duration);
        case Timer.TIME_DATE:
            try {
                return ExactExpirationTime.of(timer.getDate());
            } catch (DateTimeParseException e) {
                throw new WorkItemExecutionError("Parsing of date and time for timer failed", "DateTimeParseFailure", "Unable to parse '" + timer.getDate() + "' as valid ISO date and time format", e);
            }
        default:
            throw new UnsupportedOperationException("Not supported timer definition");
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

Example 14 with WorkItemExecutionError

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

the class ProcessRuntimeImpl method configureTimerInstance.

private ExpirationTime configureTimerInstance(Timer timer) {
    long duration = -1;
    switch(timer.getTimeType()) {
        case Timer.TIME_CYCLE:
            if (CronExpirationTime.isCronExpression(timer.getDelay())) {
                return CronExpirationTime.of(timer.getDelay());
            } else {
                // when using ISO date/time period is not set
                long[] repeatValues = DateTimeUtils.parseRepeatableDateTime(timer.getDelay());
                if (repeatValues.length == 3) {
                    int parsedReapedCount = (int) repeatValues[0];
                    return DurationExpirationTime.repeat(repeatValues[1], repeatValues[2], parsedReapedCount);
                } else {
                    long delay = repeatValues[0];
                    long period = -1;
                    try {
                        period = TimeUtils.parseTimeString(timer.getPeriod());
                    } catch (RuntimeException e) {
                        period = repeatValues[0];
                    }
                    return DurationExpirationTime.repeat(delay, period);
                }
            }
        case Timer.TIME_DURATION:
            duration = DateTimeUtils.parseDuration(timer.getDelay());
            return DurationExpirationTime.after(duration);
        case Timer.TIME_DATE:
            try {
                return ExactExpirationTime.of(timer.getDate());
            } catch (DateTimeParseException e) {
                throw new WorkItemExecutionError("Parsing of date and time for timer failed", "DateTimeParseFailure", "Unable to parse '" + timer.getDate() + "' as valid ISO date and time format", e);
            }
        default:
            throw new UnsupportedOperationException("Not supported timer definition");
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

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