Class AbstractWorkflow

java.lang.Object
com.opensymphony.workflow.AbstractWorkflow
All Implemented Interfaces:
Workflow
Direct Known Subclasses:
BasicWorkflow, OfbizWorkflow

public class AbstractWorkflow extends Object implements Workflow
Abstract workflow instance that serves as the base for specific implementations, such as EJB or SOAP.
Author:
Pat Lightbody, Hani Suleiman
  • Field Details

    • log

      protected final org.apache.commons.logging.Log log
    • configuration

      protected Configuration configuration
    • stateCache

      protected ThreadLocal stateCache
    • context

      protected WorkflowContext context
  • Constructor Details

    • AbstractWorkflow

      public AbstractWorkflow()
  • Method Details

    • getAvailableActions

      public int[] getAvailableActions(long id)
      Deprecated.
      use getAvailableActions(long, Map) with an empty Map instead.
      Specified by:
      getAvailableActions in interface Workflow
    • getAvailableActions

      public int[] getAvailableActions(long id, Map inputs)
      Get the available actions for the specified workflow instance.
      Specified by:
      getAvailableActions in interface Workflow
      Parameters:
      id - The workflow instance id.
      inputs - The inputs map to pass on to conditions
      Returns:
      An array of action id's that can be performed on the specified entry.
      Throws:
      IllegalArgumentException - if the specified id does not exist, or if its workflow descriptor is no longer available or has become invalid.
    • setConfiguration

      public void setConfiguration(Configuration configuration)
      Description copied from interface: Workflow
      Set the configuration for this workflow. If not set, then the workflow will use the default configuration static instance.
      Specified by:
      setConfiguration in interface Workflow
      Parameters:
      configuration - a workflow configuration
    • getConfiguration

      public Configuration getConfiguration()
      Get the configuration for this workflow. This method also checks if the configuration has been initialized, and if not, initializes it.
      Returns:
      The configuration that was set. If no configuration was set, then the default (static) configuration is returned.
    • getCurrentSteps

      public List getCurrentSteps(long id)
      Description copied from interface: Workflow
      Returns a Collection of Step objects that are the current steps of the specified workflow instance.
      Specified by:
      getCurrentSteps in interface Workflow
      Parameters:
      id - The workflow instance id.
      Returns:
      The steps that the workflow instance is currently in.
    • getEntryState

      public int getEntryState(long id)
      Description copied from interface: Workflow
      Return the state of the specified workflow instance id.
      Specified by:
      getEntryState in interface Workflow
      Parameters:
      id - The workflow instance id.
      Returns:
      int The state id of the specified workflow
    • getHistorySteps

      public List getHistorySteps(long id)
      Description copied from interface: Workflow
      Returns a list of all steps that are completed for the given workflow instance id.
      Specified by:
      getHistorySteps in interface Workflow
      Parameters:
      id - The workflow instance id.
      Returns:
      a List of Steps
      See Also:
    • getPersistenceProperties

      public Properties getPersistenceProperties()
    • getPropertySet

      public com.opensymphony.module.propertyset.PropertySet getPropertySet(long id)
      Get the PropertySet for the specified workflow ID
      Specified by:
      getPropertySet in interface Workflow
      Parameters:
      id - The workflow ID
    • setResolver

      public void setResolver(TypeResolver resolver)
    • getResolver

      public TypeResolver getResolver()
    • getSecurityPermissions

      public List getSecurityPermissions(long id)
      Description copied from interface: Workflow
      Get a collection (Strings) of currently defined permissions for the specified workflow instance.
      Specified by:
      getSecurityPermissions in interface Workflow
      Parameters:
      id - the workflow instance id.
      Returns:
      A List of permissions specified currently (a permission is a string name).
    • getSecurityPermissions

      public List getSecurityPermissions(long id, Map inputs)
      Description copied from interface: Workflow
      Get a collection (Strings) of currently defined permissions for the specified workflow instance.
      Specified by:
      getSecurityPermissions in interface Workflow
      Parameters:
      id - id the workflow instance id.
      inputs - inputs The inputs to the workflow instance.
      Returns:
      A List of permissions specified currently (a permission is a string name).
    • getWorkflowDescriptor

      public WorkflowDescriptor getWorkflowDescriptor(String workflowName)
      Returns a workflow definition object associated with the given name.
      Specified by:
      getWorkflowDescriptor in interface Workflow
      Parameters:
      workflowName - the name of the workflow
      Returns:
      the object graph that represents a workflow definition
    • getWorkflowName

      public String getWorkflowName(long id)
      Description copied from interface: Workflow
      Get the name of the specified workflow instance.
      Specified by:
      getWorkflowName in interface Workflow
      Parameters:
      id - the workflow instance id.
    • getWorkflowNames

      public String[] getWorkflowNames()
      Get a list of workflow names available
      Specified by:
      getWorkflowNames in interface Workflow
      Returns:
      String[] an array of workflow names.
    • canInitialize

      public boolean canInitialize(String workflowName, int initialAction)
      Description copied from interface: Workflow
      Check if the calling user has enough permissions to initialise the specified workflow.
      Specified by:
      canInitialize in interface Workflow
      Parameters:
      workflowName - The name of the workflow to check.
      initialAction - The id of the initial state to check.
      Returns:
      true if the user can successfully call initialize, false otherwise.
    • canInitialize

      public boolean canInitialize(String workflowName, int initialAction, Map inputs)
      Description copied from interface: Workflow
      Determine if a particular workflow can be initialized.
      Specified by:
      canInitialize in interface Workflow
      Parameters:
      workflowName - the name of the workflow to check
      initialAction - The initial action to check
      inputs - the inputs map
      Returns:
      true if the workflow can be initialized
    • canModifyEntryState

      public boolean canModifyEntryState(long id, int newState)
      Description copied from interface: Workflow
      Check if the state of the specified workflow instance can be changed to the new specified one.
      Specified by:
      canModifyEntryState in interface Workflow
      Parameters:
      id - The workflow instance id.
      newState - The new state id.
      Returns:
      true if the state of the workflow can be modified, false otherwise.
    • changeEntryState

      public void changeEntryState(long id, int newState) throws WorkflowException
      Description copied from interface: Workflow
      Modify the state of the specified workflow instance.
      Specified by:
      changeEntryState in interface Workflow
      Parameters:
      id - The workflow instance id.
      newState - the new state to change the workflow instance to. If the new state is
      invalid reference
      com.opensymphony.workflow.spi.WorkflowEntry.KILLED
      or
      invalid reference
      com.opensymphony.workflow.spi.WorkflowEntry.COMPLETED
      then all current steps are moved to history steps. If the new state is
      Throws:
      WorkflowException
    • doAction

      public void doAction(long id, int actionId, Map inputs) throws WorkflowException
      Description copied from interface: Workflow
      Perform an action on the specified workflow instance.
      Specified by:
      doAction in interface Workflow
      Parameters:
      id - The workflow instance id.
      actionId - The action id to perform (action id's are listed in the workflow descriptor).
      inputs - The inputs to the workflow instance.
      Throws:
      WorkflowException
    • executeTriggerFunction

      public void executeTriggerFunction(long id, int triggerId) throws WorkflowException
      Description copied from interface: Workflow
      Executes a special trigger-function using the context of the given workflow instance id. Note that this method is exposed for Quartz trigger jobs, user code should never call it.
      Specified by:
      executeTriggerFunction in interface Workflow
      Parameters:
      id - The workflow instance id
      triggerId - The id of the speciail trigger-function
      Throws:
      WorkflowException
    • initialize

      public long initialize(String workflowName, int initialAction, Map inputs) throws InvalidRoleException, InvalidInputException, WorkflowException
      Description copied from interface: Workflow
      Initializes a workflow so that it can begin processing. A workflow must be initialized before it can begin any sort of activity. It can only be initialized once.
      Specified by:
      initialize in interface Workflow
      Parameters:
      workflowName - The workflow name to create and initialize an instance for
      initialAction - The initial step to start the workflow
      inputs - The inputs entered by the end-user
      Throws:
      InvalidRoleException - if the user can't start this function
      InvalidInputException - if a validator is specified and an input is invalid.
      WorkflowException
    • query

      public List query(WorkflowQuery query) throws StoreException
      Description copied from interface: Workflow
      Query the workflow store for matching instances
      Specified by:
      query in interface Workflow
      Throws:
      StoreException
    • query

      public List query(WorkflowExpressionQuery query) throws WorkflowException
      Description copied from interface: Workflow
      Query the workflow store for matching instances
      Specified by:
      query in interface Workflow
      Throws:
      WorkflowException
    • removeWorkflowDescriptor

      public boolean removeWorkflowDescriptor(String workflowName) throws FactoryException
      Description copied from interface: Workflow
      Remove the specified workflow descriptor.
      Specified by:
      removeWorkflowDescriptor in interface Workflow
      Parameters:
      workflowName - The workflow name of the workflow to remove.
      Returns:
      true if the workflow was removed, false otherwise.
      Throws:
      FactoryException - If the underlying workflow factory has an error removing the workflow, or if it does not support the removal of workflows.
    • saveWorkflowDescriptor

      public boolean saveWorkflowDescriptor(String workflowName, WorkflowDescriptor descriptor, boolean replace) throws FactoryException
      Description copied from interface: Workflow
      Add a new workflow descriptor
      Specified by:
      saveWorkflowDescriptor in interface Workflow
      Parameters:
      workflowName - The workflow name of the workflow to add
      descriptor - The workflow descriptor to add
      replace - true, if an existing descriptor should be overwritten
      Returns:
      true if the workflow was added, fales otherwise
      Throws:
      FactoryException - If the underlying workflow factory has an error adding the workflow, or if it does not support adding workflows.
    • isActionAvailable

      protected boolean isActionAvailable(ActionDescriptor action, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int stepId) throws WorkflowException
      check if an action is available or not
      Parameters:
      action - The action descriptor
      Returns:
      true if the action is available
      Throws:
      WorkflowException
    • getAvailableActionsForStep

      protected List getAvailableActionsForStep(WorkflowDescriptor wf, Step step, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Throws:
      WorkflowException
    • getAvailableAutoActions

      protected int[] getAvailableAutoActions(long id, Map inputs)
    • getAvailableAutoActionsForStep

      protected List getAvailableAutoActionsForStep(WorkflowDescriptor wf, Step step, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Get just auto action availables for a step
      Throws:
      WorkflowException
    • getCurrentStep

      protected Step getCurrentStep(WorkflowDescriptor wfDesc, int actionId, List currentSteps, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Throws:
      WorkflowException
    • getPersistence

      protected WorkflowStore getPersistence() throws StoreException
      Throws:
      StoreException
    • canInitialize

      protected boolean canInitialize(String workflowName, int initialAction, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Throws:
      WorkflowException
    • completeEntry

      protected void completeEntry(ActionDescriptor action, long id, Collection currentSteps, int state) throws StoreException
      Mark the specified entry as completed, and move all current steps to history.
      Throws:
      StoreException
    • createNewCurrentStep

      protected Step createNewCurrentStep(ResultDescriptor theResult, WorkflowEntry entry, WorkflowStore store, int actionId, Step currentStep, long[] previousIds, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Throws:
      WorkflowException
    • executeFunction

      protected void executeFunction(FunctionDescriptor function, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Executes a function.
      Parameters:
      function - the function to execute
      transientVars - the transientVars given by the end-user
      ps - the persistence variables
      Throws:
      WorkflowException
    • passesCondition

      protected boolean passesCondition(ConditionDescriptor conditionDesc, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int currentStepId) throws WorkflowException
      Throws:
      WorkflowException
    • passesConditions

      protected boolean passesConditions(String conditionType, List conditions, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int currentStepId) throws WorkflowException
      Throws:
      WorkflowException
    • passesConditions

      protected boolean passesConditions(ConditionsDescriptor descriptor, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int currentStepId) throws WorkflowException
      Throws:
      WorkflowException
    • populateTransientMap

      protected void populateTransientMap(WorkflowEntry entry, Map transientVars, List registers, Integer actionId, Collection currentSteps, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Throws:
      WorkflowException
    • transitionWorkflow

      protected boolean transitionWorkflow(WorkflowEntry entry, List currentSteps, WorkflowStore store, WorkflowDescriptor wf, ActionDescriptor action, Map transientVars, Map inputs, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Returns:
      true if the instance has been explicitly completed is this transition, false otherwise
      Throws:
      WorkflowException
    • verifyInputs

      protected void verifyInputs(WorkflowEntry entry, List validators, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps) throws WorkflowException
      Validates input against a list of ValidatorDescriptor objects.
      Parameters:
      entry - the workflow instance
      validators - the list of ValidatorDescriptors
      transientVars - the transientVars
      ps - the persistence variables
      Throws:
      InvalidInputException - if the input is deemed invalid by any validator
      WorkflowException