Class WorkflowDefinition

java.lang.Object
io.nflow.engine.model.ModelObject
io.nflow.engine.workflow.definition.WorkflowDefinition
Direct Known Subclasses:
BulkWorkflow, CronWorkflow, StoredWorkflowDefinitionWrapper

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 states parameter
  • Field Details

  • Constructor Details

    • 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.
    • 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

      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.
    • getSupportedSignals

      public Map<Integer,String> 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.