com.opensymphony.workflow
Class AbstractWorkflow

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

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 Summary
protected  WorkflowContext context
           
 
Fields inherited from interface com.opensymphony.workflow.Workflow
BSF_COL, BSF_LANGUAGE, BSF_ROW, BSF_SCRIPT, BSF_SOURCE, BSH_SCRIPT, CLASS_NAME, EJB_LOCATION, JNDI_LOCATION
 
Constructor Summary
AbstractWorkflow()
           
 
Method Summary
 boolean canInitialize(String workflowName, int initialAction)
          Check if the calling user has enough permissions to initialise the specified workflow.
 boolean canInitialize(String workflowName, int initialAction, Map inputs)
          Determine if a particular workflow can be initialized.
 boolean canModifyEntryState(long id, int newState)
          Check if the state of the specified workflow instance can be changed to the new specified one.
 void changeEntryState(long id, int newState)
          Modify the state of the specified workflow instance.
protected  void checkImplicitFinish(ActionDescriptor action, long id)
           
protected  void completeEntry(ActionDescriptor action, long id, Collection currentSteps, int state)
          Mark the specified entry as completed, and move all current steps to history.
 void doAction(long id, int actionId, Map inputs)
          Perform an action on the specified workflow instance.
protected  void executeFunction(FunctionDescriptor function, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps)
          Executes a function.
 void executeTriggerFunction(long id, int triggerId)
          Executes a special trigger-function using the context of the given workflow instance id.
 int[] getAvailableActions(long id)
          Deprecated. use getAvailableActions(long, Map) with an empty Map instead.
 int[] getAvailableActions(long id, Map inputs)
          Get the available actions for the specified workflow instance.
protected  List getAvailableActionsForStep(WorkflowDescriptor wf, Step step, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps)
           
protected  int[] getAvailableAutoActions(long id, Map inputs)
           
protected  List getAvailableAutoActionsForStep(WorkflowDescriptor wf, Step step, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps)
          Get just auto action availables for a step
 Configuration getConfiguration()
          Get the configuration for this workflow.
 List getCurrentSteps(long id)
          Returns a Collection of Step objects that are the current steps of the specified workflow instance.
 int getEntryState(long id)
          Return the state of the specified workflow instance id.
 List getHistorySteps(long id)
          Returns a list of all steps that are completed for the given workflow instance id.
protected  WorkflowStore getPersistence()
           
 Properties getPersistenceProperties()
           
 com.opensymphony.module.propertyset.PropertySet getPropertySet(long id)
          Get the PropertySet for the specified workflow ID
 TypeResolver getResolver()
           
 List getSecurityPermissions(long id)
          Get a collection (Strings) of currently defined permissions for the specified workflow instance.
 List getSecurityPermissions(long id, Map inputs)
          Get a collection (Strings) of currently defined permissions for the specified workflow instance.
 WorkflowDescriptor getWorkflowDescriptor(String workflowName)
          Returns a workflow definition object associated with the given name.
 String getWorkflowName(long id)
          Get the name of the specified workflow instance.
 String[] getWorkflowNames()
          Get a list of workflow names available
 long initialize(String workflowName, int initialAction, Map inputs)
          Initializes a workflow so that it can begin processing.
protected  boolean passesCondition(ConditionDescriptor conditionDesc, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int currentStepId)
           
protected  boolean passesConditions(ConditionsDescriptor descriptor, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int currentStepId)
           
protected  boolean passesConditions(String conditionType, List conditions, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps, int currentStepId)
           
protected  void populateTransientMap(WorkflowEntry entry, Map transientVars, List registers, Integer actionId, Collection currentSteps, com.opensymphony.module.propertyset.PropertySet ps)
           
 List query(WorkflowExpressionQuery query)
          Query the workflow store for matching instances
 List query(WorkflowQuery query)
          Query the workflow store for matching instances
 boolean removeWorkflowDescriptor(String workflowName)
          Remove the specified workflow descriptor.
 boolean saveWorkflowDescriptor(String workflowName, WorkflowDescriptor descriptor, boolean replace)
          Add a new workflow descriptor
 void setConfiguration(Configuration configuration)
          Set the configuration for this workflow.
 void setResolver(TypeResolver resolver)
           
protected  boolean transitionWorkflow(WorkflowEntry entry, List currentSteps, WorkflowStore store, WorkflowDescriptor wf, ActionDescriptor action, Map transientVars, Map inputs, com.opensymphony.module.propertyset.PropertySet ps)
           
protected  void verifyInputs(WorkflowEntry entry, List validators, Map transientVars, com.opensymphony.module.propertyset.PropertySet ps)
          Validates input against a list of ValidatorDescriptor objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected WorkflowContext context
Constructor Detail

AbstractWorkflow

public AbstractWorkflow()
Method Detail

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:
Step

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 com.opensymphony.workflow.spi.WorkflowEntry.KILLED or 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:
InvalidInputException - if a validator is specified and an input is invalid.
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.

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

getPersistence

protected WorkflowStore getPersistence()
                                throws StoreException
Throws:
StoreException

checkImplicitFinish

protected void checkImplicitFinish(ActionDescriptor action,
                                   long id)
                            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

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

OpenSymphony Workflow Project Page