Class WorkflowDefinition
java.lang.Object
io.nflow.engine.model.ModelObject
io.nflow.engine.workflow.definition.WorkflowDefinition
- Direct Known Subclasses:
BulkWorkflow,CronWorkflow,StoredWorkflowDefinitionWrapper
The base class for all workflow definitions. Extending workflow definition classes should register all their states using at
least one of the following ways:
- Using them as initialState or errorState parameter when calling the super constructor
- Using them as one of the parameters when registering allowed state transfers using
permit()method - Defining them as public static fields in the workflow definition class
- Registering them using
registerState()method - Passing them to super constructor in
statesparameter
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState) Create a workflow definition with default settings and automatically scanned state methods.protectedWorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings) Create a workflow definition with given settings and automatically scanned state methods.protectedWorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings, Map<String, WorkflowStateMethod> stateMethods) Create a workflow definition with given settings and state methods.protectedWorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings, Map<String, WorkflowStateMethod> stateMethods, Collection<WorkflowState> states) Create a workflow definition with given settings, state methods and states.protectedWorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings, Map<String, WorkflowStateMethod> stateMethods, Collection<WorkflowState> states, boolean verifyStateMethodValidity) Create a workflow definition with given settings, state methods and states. -
Method Summary
Modifier and TypeMethodDescriptionReturn allowed transitions between the states of the workflow.Return the description of the workflow.Return the generic error state of the workflow.Return transitions from states to failure states.Return the initial state of the workflow.getMethod(WorkflowState state) Returns the workflow state method for the given state.Returns the workflow state method for the given state name.getName()Return the name of the workflow.Return the workflow settings.Returns the workflow state for the given state name.Return all possible states of the workflow.Return signals supported by this workflow.getType()Return the type of the workflow.booleanisAllowedNextAction(WorkflowInstance instance, NextAction nextAction) Return true if the given nextAction is permitted for given instance.booleanisStartState(String state) Check if the given state is a valid start state.protected WorkflowDefinitionpermit(WorkflowState originState, WorkflowState targetState) Register a state transition to the allowed transitions.protected WorkflowDefinitionpermit(WorkflowState originState, WorkflowState targetState, WorkflowState failureState) Register a state and failure state transitions to the allowed transitions.final voidregisterState(WorkflowState state) Register a state as one of the allowed states in this workflow.voidsetDescription(String description) Set the description of the workflow.voidSet the name of the workflow.Methods inherited from class io.nflow.engine.model.ModelObject
equals, hashCode, toString
-
Field Details
-
allowedTransitions
-
failureTransitions
-
-
Constructor Details
-
WorkflowDefinition
Create a workflow definition with default settings and automatically scanned state methods.- Parameters:
type- The unique identifier of this workflow definition.initialState- The default start state of the workflow. The state is automatically registered as one of the allowed states in this workflow.errorState- The default error state of the workflow. The state is automatically registered as one of the allowed states in this workflow.
-
WorkflowDefinition
protected WorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings) Create a workflow definition with given settings and automatically scanned state methods.- Parameters:
type- The unique identifier of this workflow definition.initialState- The default start state of the workflow. The state is automatically registered as one of the allowed states in this workflow.errorState- The default error state of the workflow. The state is automatically registered as one of the allowed states in this workflow.settings- The configuration for the workflow instances of this workflow type.
-
WorkflowDefinition
protected WorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings, Map<String, WorkflowStateMethod> stateMethods) Create a workflow definition with given settings and state methods.- Parameters:
type- The unique identifier of this workflow definition.initialState- The default start state of the workflow. The state is automatically registered as one of the allowed states in this workflow.errorState- The default error state of the workflow. The state is automatically registered as one of the allowed states in this workflow.settings- The configuration for the workflow instances of this workflow type.stateMethods- The state methods to be used for the states of this workflow type. If null, the methods will be scanned.
-
WorkflowDefinition
protected WorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings, Map<String, WorkflowStateMethod> stateMethods, Collection<WorkflowState> states) Create a workflow definition with given settings, state methods and states.- Parameters:
type- The unique identifier of this workflow definition.initialState- The default start state of the workflow. The state is automatically registered as one of the allowed states in this workflow.errorState- The default error state of the workflow. The state is automatically registered as one of the allowed states in this workflow.settings- The configuration for the workflow instances of this workflow type.stateMethods- The state methods to be used for the states of this workflow type. If null, the methods will be scanned.states- The states to be registered for the workflow. If null, the states will be scanned.
-
WorkflowDefinition
protected WorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState, WorkflowSettings settings, Map<String, WorkflowStateMethod> stateMethods, Collection<WorkflowState> states, boolean verifyStateMethodValidity) Create a workflow definition with given settings, state methods and states.- Parameters:
type- The unique identifier of this workflow definition.initialState- The default start state of the workflow. The state is automatically registered as one of the allowed states in this workflow.errorState- The default error state of the workflow. The state is automatically registered as one of the allowed states in this workflow.settings- The configuration for the workflow instances of this workflow type.stateMethods- The state methods to be used for the states of this workflow type. If null, the methods will be scanned.states- The states to be registered for the workflow. If null, the states will be scanned.verifyStateMethodValidity- True to search and verify the implementation of registered state methods to ensure they comply with expectations.
-
-
Method Details
-
getName
Return the name of the workflow.- Returns:
- The name.
-
setName
Set the name of the workflow.- Parameters:
name- The name.
-
getDescription
Return the description of the workflow.- Returns:
- The description.
-
setDescription
Set the description of the workflow.- Parameters:
description- The description.
-
getType
Return the type of the workflow.- Returns:
- The type.
-
getInitialState
Return the initial state of the workflow.- Returns:
- Workflow state.
-
getErrorState
Return the generic error state of the workflow.- Returns:
- Workflow state.
-
getStates
Return all possible states of the workflow.- Returns:
- Set of workflow states.
-
registerState
Register a state as one of the allowed states in this workflow.- Parameters:
state- The state to be registered.
-
getAllowedTransitions
Return allowed transitions between the states of the workflow.- Returns:
- Map from origin states to a list of target states.
-
getFailureTransitions
Return transitions from states to failure states.- Returns:
- Map from origin state to failure state.
-
permit
Register a state transition to the allowed transitions.- Parameters:
originState- The origin state. The state is automatically registered as one of the allowed states in this workflow.targetState- The target state. The state is automatically registered as one of the allowed states in this workflow.- Returns:
- This.
-
permit
protected WorkflowDefinition permit(WorkflowState originState, WorkflowState targetState, WorkflowState failureState) Register a state and failure state transitions to the allowed transitions.- Parameters:
originState- The origin state. The state is automatically registered as one of the allowed states in this workflow.targetState- The target state. The state is automatically registered as one of the allowed states in this workflow.failureState- The failure state. The state is automatically registered as one of the allowed states in this workflow.- Returns:
- This.
-
getSettings
Return the workflow settings.- Returns:
- Workflow settings.
-
getMethod
Returns the workflow state method for the given state name.- Parameters:
stateName- The name of the workflow state.- Returns:
- The workflow state method, or null if not found.
-
getMethod
Returns the workflow state method for the given state.- Parameters:
state- The workflow state.- Returns:
- The workflow state method, or null if not found.
-
getState
Returns the workflow state for the given state name.- Parameters:
state- The name of the workflow state.- Returns:
- The workflos state matching the state name.
- Throws:
IllegalArgumentException- when a matching state can not be found.
-
isStartState
Check if the given state is a valid start state.- Parameters:
state- The name of the workflow state.- Returns:
- True if the given state is a valid start date, false otherwise.
- Throws:
IllegalArgumentException- if the given state name does not match any state.
-
isAllowedNextAction
Return true if the given nextAction is permitted for given instance.- Parameters:
instance- The workflow instance for which the action is checked.nextAction- The action to be checked.- Returns:
- True if the nextAction is permitted, false otherwise.
-
getSupportedSignals
Return signals supported by this workflow. Default implementation returns empty map, override this in your workflow definition that supports signals.- Returns:
- Signals and their descriptions.
-