Class WorkflowDefinition
- java.lang.Object
-
- io.nflow.engine.model.ModelObject
-
- io.nflow.engine.workflow.definition.WorkflowDefinition
-
- Direct Known Subclasses:
BulkWorkflow,CronWorkflow
public abstract class WorkflowDefinition extends ModelObject
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 Modifier and Type Field Description protected Map<String,List<String>>allowedTransitionsprotected Map<String,WorkflowState>failureTransitions
-
Constructor Summary
Constructors Modifier Constructor Description protectedWorkflowDefinition(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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,List<String>>getAllowedTransitions()Return allowed transitions between the states of the workflow.StringgetDescription()Return the description of the workflow.WorkflowStategetErrorState()Return the generic error state of the workflow.Map<String,WorkflowState>getFailureTransitions()Return transitions from states to failure states.WorkflowStategetInitialState()Return the initial state of the workflow.WorkflowStateMethodgetMethod(WorkflowState state)Returns the workflow state method for the given state.WorkflowStateMethodgetMethod(String stateName)Returns the workflow state method for the given state name.StringgetName()Return the name of the workflow.WorkflowSettingsgetSettings()Return the workflow settings.WorkflowStategetState(String state)Returns the workflow state for the given state name.Set<WorkflowState>getStates()Return all possible states of the workflow.Map<Integer,String>getSupportedSignals()Return signals supported by this workflow.StringgetType()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.voidregisterState(WorkflowState state)Register a state as one of the allowed states in this workflow.voidsetDescription(String description)Set the description of the workflow.voidsetName(String name)Set the name of the workflow.-
Methods inherited from class io.nflow.engine.model.ModelObject
equals, hashCode, toString
-
-
-
-
Constructor Detail
-
WorkflowDefinition
protected WorkflowDefinition(String type, WorkflowState initialState, WorkflowState errorState)
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.
-
-
Method Detail
-
getName
public String getName()
Return the name of the workflow.- Returns:
- The name.
-
setName
public void setName(String name)
Set the name of the workflow.- Parameters:
name- The name.
-
getDescription
public String getDescription()
Return the description of the workflow.- Returns:
- The description.
-
setDescription
public void setDescription(String description)
Set the description of the workflow.- Parameters:
description- The description.
-
getType
public String getType()
Return the type of the workflow.- Returns:
- The type.
-
getInitialState
public WorkflowState getInitialState()
Return the initial state of the workflow.- Returns:
- Workflow state.
-
getErrorState
public WorkflowState getErrorState()
Return the generic error state of the workflow.- Returns:
- Workflow state.
-
getStates
public Set<WorkflowState> getStates()
Return all possible states of the workflow.- Returns:
- Set of workflow states.
-
registerState
public final void registerState(WorkflowState state)
Register a state as one of the allowed states in this workflow.- Parameters:
state- The state to be registered.
-
getAllowedTransitions
public Map<String,List<String>> getAllowedTransitions()
Return allowed transitions between the states of the workflow.- Returns:
- Map from origin states to a list of target states.
-
getFailureTransitions
public Map<String,WorkflowState> getFailureTransitions()
Return transitions from states to failure states.- Returns:
- Map from origin state to failure state.
-
permit
protected WorkflowDefinition permit(WorkflowState originState, WorkflowState targetState)
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
public WorkflowSettings getSettings()
Return the workflow settings.- Returns:
- Workflow settings.
-
getMethod
public WorkflowStateMethod getMethod(String stateName)
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
public WorkflowStateMethod getMethod(WorkflowState state)
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
public WorkflowState getState(String state)
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
public boolean isStartState(String state)
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
public boolean isAllowedNextAction(WorkflowInstance instance, NextAction nextAction)
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.
-
-