Class WorkflowExecutionContext
- java.lang.Object
-
- de.xima.fc.workflow.processor.logic.execution.WorkflowExecutionContext
-
- All Implemented Interfaces:
IBaseWorkflowExecutionContext
,IWorkflowExecutionContext
,Closeable
,AutoCloseable
public final class WorkflowExecutionContext extends Object implements IWorkflowExecutionContext
Default implementation ofIWorkflowExecutionContext
that is used by theWorkflowTaskRunner
. Contains the state that needs to be kept during workflow execution.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description WorkflowExecutionContext(IWorkflowTaskRunnerParams params, IWorkflowRunTasksForEventParams runTasksParams)
Creates a new execution context for executing the given task queue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beforeTaskStart(Object triggerData, IWorkflowEventData eventData, WorkflowTask task, WorkflowTrigger trigger)
Invoked internally before a task is about to be executed.void
close()
WorkflowTaskExecutionException
createExecutionException(String message, com.google.common.collect.ImmutableList<Long> tasks, Exception cause, boolean handled)
Should be called after the task was executed completely and threw an exception.ITaskExecutionSuccessResult
createExecutionSuccessResult(com.google.common.collect.ImmutableList<Long> tasks)
Should be called after the task was executed completely.ITaskExecutionResult
createFinalResult(List<ITaskExecutionResult> individualResults)
Internal method called after the list of tasks were executed.protected IWorkflowNodeResult
doExecute(WorkflowNode node)
IWorkflowExecutionEnvironmentData
env()
IWorkflowEventData
event()
IWorkflowExecutor
executor()
Grants access to the executor that can be used to execute children, or to trigger events.IWorkflowFileHandler
file()
IWorkflowFormHandler
form()
EWorkflowStateType
getDefaultSystemState()
de.xima.fc.workflow.processor.logic.execution.WorkflowExecutionEnvironmentData
getEnvironmentData()
de.xima.fc.workflow.processor.logic.execution.WorkflowFileHandler
getFileHandler()
de.xima.fc.workflow.processor.logic.execution.WorkflowFormHandler
getFormHandler()
de.xima.fc.workflow.processor.logic.execution.WorkflowHttpHandler
getHttpHandler()
de.xima.fc.workflow.processor.logic.execution.WorkflowLimitsHandler
getLimitsHandler()
de.xima.fc.workflow.processor.logic.execution.WorkflowLoggingHandler
getLoggingHandler()
de.xima.fc.workflow.processor.logic.execution.WorkflowNodeLocator
getNodeLocator()
de.xima.fc.workflow.processor.logic.execution.WorkflowPlaceholderHandler
getPlaceholderHandler()
TaskQueue
getTaskQueue()
de.xima.fc.workflow.processor.logic.execution.WorkflowVariableHandler
getVariableHandler()
IWorkflowHttpHandler
http()
boolean
isWasFormRecordDeleted()
IWorkflowLoggingHandler
logging()
boolean
markErrorEventTriggered()
Sets theerrorEventTriggered
flag totrue
and returns the previous value of the flag.IWorkflowNodeLocator
node()
IWorkflowPlaceholderHandler
placeholder()
long
processId()
void
setCurrentEvent(IWorkflowEventData eventData)
void
setCurrentTask(WorkflowTask task)
WorkflowTask
task()
IWorkflowVariableHandler
variable()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.xima.fc.interfaces.workflow.execution.IWorkflowExecutionContext
event
-
-
-
-
Constructor Detail
-
WorkflowExecutionContext
public WorkflowExecutionContext(IWorkflowTaskRunnerParams params, IWorkflowRunTasksForEventParams runTasksParams) throws CouldNotLockFormRecordException
Creates a new execution context for executing the given task queue.- Parameters:
params
- Parameters from the task runner.runTasksParams
- The tasks that are to be executed, and optionally an entity context to use.- Throws:
CouldNotLockFormRecordException
- When the form record could not be locked for execution.
-
-
Method Detail
-
beforeTaskStart
public void beforeTaskStart(Object triggerData, IWorkflowEventData eventData, WorkflowTask task, WorkflowTrigger trigger)
Invoked internally before a task is about to be executed.- Parameters:
triggerData
- Data made available by the trigger.eventData
- Event data that was triggered.task
- Task about to be executed.trigger
- Trigger that was triggered.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
createExecutionException
public WorkflowTaskExecutionException createExecutionException(String message, com.google.common.collect.ImmutableList<Long> tasks, Exception cause, boolean handled)
Should be called after the task was executed completely and threw an exception. Returns the exception that should be rethrown.- Parameters:
message
- Message for the exception.tasks
- List of tasks that were executed when the exception was obtained.cause
- Exception that caused the task to fail.handled
- Whether the error is or was handled in some way.- Returns:
- The exception for the task's execution.
-
createExecutionSuccessResult
public ITaskExecutionSuccessResult createExecutionSuccessResult(com.google.common.collect.ImmutableList<Long> tasks) throws WorkflowTaskExecutionException
Should be called after the task was executed completely. Returns the result of the task's execution.- Parameters:
tasks
- A list of tasks that were executed for this result.- Returns:
- The result of the task's execution.
- Throws:
WorkflowTaskExecutionException
- When the result could not be created.
-
createFinalResult
public ITaskExecutionResult createFinalResult(List<ITaskExecutionResult> individualResults)
Internal method called after the list of tasks were executed. Creates the main result of the execution (i.e. combines all individual results).- Parameters:
individualResults
- Individual results of each task.- Returns:
- The main combined result for the task list execution.
-
env
public IWorkflowExecutionEnvironmentData env()
- Specified by:
env
in interfaceIBaseWorkflowExecutionContext
- Specified by:
env
in interfaceIWorkflowExecutionContext
- Returns:
- Data from the current workflow execution, such as the form for which the workflow is executed, and the current client.
-
event
public IWorkflowEventData event()
- Specified by:
event
in interfaceIWorkflowExecutionContext
- Returns:
- The data of the event that triggered the task being executed, i.e. the event to which the task's trigger reacted.
-
executor
public IWorkflowExecutor executor()
Description copied from interface:IWorkflowExecutionContext
Grants access to the executor that can be used to execute children, or to trigger events.- Specified by:
executor
in interfaceIWorkflowExecutionContext
- Returns:
- The executor handler associated with this execution context.
-
file
public IWorkflowFileHandler file()
- Specified by:
file
in interfaceIWorkflowExecutionContext
- Returns:
- The file handler for interacting with files and the file system. Use this to create temporary files, to read files created by other workflow elements, or to attach files to the form record.
-
form
public IWorkflowFormHandler form()
- Specified by:
form
in interfaceIWorkflowExecutionContext
- Returns:
- The file handler for interacting with the form and its data.
-
getDefaultSystemState
public EWorkflowStateType getDefaultSystemState()
- Returns:
- The default system state to set, for internal use.
-
getEnvironmentData
public de.xima.fc.workflow.processor.logic.execution.WorkflowExecutionEnvironmentData getEnvironmentData()
- Returns:
- The environment data implementation for internal use.
-
getFileHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowFileHandler getFileHandler()
- Returns:
- The file handler implementation for internal use.
-
getFormHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowFormHandler getFormHandler()
- Returns:
- The form handler implementation for internal use.
-
getHttpHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowHttpHandler getHttpHandler()
- Returns:
- The HTTP handler implementation for internal use.
-
getLimitsHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowLimitsHandler getLimitsHandler()
- Returns:
- The limits handler implementation for internal use.
-
getLoggingHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowLoggingHandler getLoggingHandler()
- Returns:
- The logging handler implementation for internal use.
-
getNodeLocator
public de.xima.fc.workflow.processor.logic.execution.WorkflowNodeLocator getNodeLocator()
- Returns:
- The node locator implementation for internal use.
-
getPlaceholderHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowPlaceholderHandler getPlaceholderHandler()
- Returns:
- The placeholder handler implementation for internal use.
-
getTaskQueue
public TaskQueue getTaskQueue()
- Returns:
- All tasks that are scheduled to be executed. The last task in this queue
Deque.pollLast()
is the task that should be run next.
-
getVariableHandler
public de.xima.fc.workflow.processor.logic.execution.WorkflowVariableHandler getVariableHandler()
- Returns:
- The variable handler implementation for internal use.
-
http
public IWorkflowHttpHandler http()
- Specified by:
http
in interfaceIWorkflowExecutionContext
- Returns:
- The handler for interacting with the current HTTP request. It can be used, for example, to initiate redirects or read/write session parameters. If no HTTP request is currently active, this returns a dummy instance that takes no action.
-
isWasFormRecordDeleted
public boolean isWasFormRecordDeleted()
- Returns:
- Whether the form record was deleted or not
-
logging
public IWorkflowLoggingHandler logging()
- Specified by:
logging
in interfaceIWorkflowExecutionContext
- Returns:
- The handler for interacting with the logging system. Lets you create protocol entries.
-
markErrorEventTriggered
public boolean markErrorEventTriggered()
Sets theerrorEventTriggered
flag totrue
and returns the previous value of the flag.Internal method that keeps track of whether an error event was already triggered. When a task throws an unhandled exception, an error event is triggered that lets the user handle that exception globally by adding an error trigger to the workflow. When the task for that error trigger throws an unhandled exception, we end the workflow execution to prevent infinite loops.
- Returns:
- The previous value of the
errorEventTriggered
flag.
-
node
public IWorkflowNodeLocator node()
- Specified by:
node
in interfaceIWorkflowExecutionContext
- Returns:
- A handler for locating nodes by their name, ID, or UUID. Also lets you access the node currently being executed.
-
placeholder
public IWorkflowPlaceholderHandler placeholder()
- Specified by:
placeholder
in interfaceIBaseWorkflowExecutionContext
- Specified by:
placeholder
in interfaceIWorkflowExecutionContext
- Returns:
- A handler for replacing placeholders in strings, using the current workflow execution context. This is a shortcut for the methods provided by {code de.xima.fc.placeholder.PlaceholderReplacer} that supplies the required parameters automatically.
-
processId
public long processId()
- Specified by:
processId
in interfaceIWorkflowExecutionContext
- Returns:
- ID of the
WorkflowProcess
of the task being executed.
-
setCurrentEvent
public void setCurrentEvent(IWorkflowEventData eventData)
- Parameters:
eventData
- The event data of the task that is currently being executed. Internal-use only.
-
setCurrentTask
public void setCurrentTask(WorkflowTask task)
- Parameters:
task
- The task that is currently being executed. Internal-use only.
-
task
public WorkflowTask task()
- Specified by:
task
in interfaceIWorkflowExecutionContext
- Returns:
- The task that is being executed.
-
variable
public IWorkflowVariableHandler variable()
- Specified by:
variable
in interfaceIWorkflowExecutionContext
- Returns:
- The handler for retrieving results of previous workflow actions, or adding new results.
-
doExecute
protected IWorkflowNodeResult doExecute(WorkflowNode node) throws ExecutionAbortedException
- Throws:
ExecutionAbortedException
-
-