Package com.yworkflow.instance.model
Interface WorkflowInstance
public interface WorkflowInstance
Represents a running workflow instance. A workflow instance is a single execution of a workflow
definition, with its own state, data (attributes), and execution history.
Each workflow instance progresses through various states by executing transitions. The instance maintains its current state, available transitions, and persistent attributes that survive across workflow invocations.
Workflow instances support role-based access control through the actAs(WorkflowCaller) method, allowing different users to interact with the same instance with
different permissions and capabilities.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionactAs(WorkflowCaller caller) Creates a new WorkflowInstance view that operates as the specified caller.Returns the mutable attributes of this workflow instance.booleancanModifyStatus(WorkflowInstanceStatus newStatus) Checks if the workflow instance status can be modified to the specified status.voidchangeStatus(WorkflowInstanceStatus newStatus) Changes the status of this workflow instance to the specified status.voidexecuteTriggerFunction(String triggerId) Executes a trigger function with the specified ID.default List<TransitionId>Returns the list of transitions that are currently available for execution.getAvailableTransitions(Attributes inputs) Returns the list of transitions that are currently available for execution with the given input attributes.Returns the capabilities available to this workflow instance.getCapabilities(Attributes inputs) Returns the capabilities available to this workflow instance with the given inputs.Returns the execution history of this workflow instance.getId()Returns the unique identifier of this workflow instance.Returns the list of currently active state instances.Returns the current status of this workflow instance.Returns the tenant ID associated with this workflow instance.Returns the ID of the workflow definition that this instance is based on.default voidtransition(TransitionId transitionId) Executes a transition with the specified ID using empty inputs.voidtransition(TransitionId transitionId, Attributes inputs) Executes a transition with the specified ID and input attributes.
-
Method Details
-
getTenantId
TenantId getTenantId()Returns the tenant ID associated with this workflow instance.- Returns:
- the tenant ID
-
getId
WorkflowInstanceId getId()Returns the unique identifier of this workflow instance.- Returns:
- the workflow instance ID
-
getWorkflowDefinitionId
WorkflowDefinitionId getWorkflowDefinitionId()Returns the ID of the workflow definition that this instance is based on.- Returns:
- the workflow definition ID
-
getStatusInfo
WorkflowInstanceStatusInfo getStatusInfo()Returns the current status of this workflow instance.- Returns:
- the workflow instance status information
-
getStateInstances
List<StateInstance> getStateInstances()Returns the list of currently active state instances.- Returns:
- the list of active state instances
-
getHistory
List<StateInstance> getHistory()Returns the execution history of this workflow instance.- Returns:
- the list of historical state instances
-
attributes
MutableAttributes attributes()Returns the mutable attributes of this workflow instance. These attributes persist across workflow invocations.- Returns:
- the mutable attributes
-
getCapabilities
Returns the capabilities available to this workflow instance. This is a convenience method that uses empty inputs.- Returns:
- the list of available capabilities
- Throws:
WorkflowException- if an error occurs while retrieving capabilities
-
getCapabilities
Returns the capabilities available to this workflow instance with the given inputs.- Parameters:
inputs- the input attributes to consider when determining capabilities- Returns:
- the list of available capabilities
- Throws:
WorkflowException- if an error occurs while retrieving capabilities
-
canModifyStatus
Checks if the workflow instance status can be modified to the specified status.- Parameters:
newStatus- the new status to check- Returns:
- true if the status can be modified, false otherwise
-
changeStatus
Changes the status of this workflow instance to the specified status.- Parameters:
newStatus- the new status to set- Throws:
WorkflowException- if the status change is not allowed or an error occurs
-
transition
Executes a transition with the specified ID and input attributes.- Parameters:
transitionId- the ID of the transition to executeinputs- the input attributes for the transition- Throws:
WorkflowException- if the transition cannot be executed or an error occurs
-
transition
Executes a transition with the specified ID using empty inputs. This is a convenience method.- Parameters:
transitionId- the ID of the transition to execute- Throws:
WorkflowException- if the transition cannot be executed or an error occurs
-
executeTriggerFunction
Executes a trigger function with the specified ID.- Parameters:
triggerId- the ID of the trigger function to execute- Throws:
WorkflowException- if the trigger function cannot be executed or an error occurs
-
getAvailableTransitions
Returns the list of transitions that are currently available for execution with the given input attributes.- Parameters:
inputs- the input attributes to consider when determining available transitions- Returns:
- the list of available transition IDs
- Throws:
WorkflowException- if an error occurs while determining available transitions
-
getAvailableTransitions
Returns the list of transitions that are currently available for execution. This is a convenience method that uses empty inputs.- Returns:
- the list of available transition IDs
- Throws:
WorkflowException- if an error occurs while determining available transitions
-
actAs
Creates a new WorkflowInstance view that operates as the specified caller. This allows for role-based access control and different permissions.- Parameters:
caller- the caller to act as- Returns:
- a new WorkflowInstance view with the specified caller context
-