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);
}
}
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;
}
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");
}
}
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");
}
}
Aggregations