org.apache.wiki.workflow
Class WorkflowManager

java.lang.Object
  extended by org.apache.wiki.workflow.WorkflowManager
All Implemented Interfaces:
EventListener, WikiEventListener

public class WorkflowManager
extends Object
implements WikiEventListener

Monitor class that tracks running Workflows. The WorkflowManager also keeps track of the names of users or groups expected to approve particular Workflows.


Field Summary
protected static String PROPERTY_APPROVER_PREFIX
          The prefix to use for looking up jspwiki.properties approval roles.
 
Constructor Summary
WorkflowManager()
          Constructs a new WorkflowManager, with an empty workflow cache.
 
Method Summary
 void actionPerformed(WikiEvent event)
          Listens for WorkflowEvent objects emitted by Workflows.
protected  void add(Workflow workflow)
          Protected helper method that adds a newly created Workflow to the cache, and sets its workflowManager and Id properties if not set.
 Principal getApprover(String messageKey)
          Looks up and resolves the actor who approves a Decision for a particular Workflow, based on the Workflow's message key.
 List getCompletedWorkflows()
          Returns a collection of finished workflows; that is, those that have aborted or completed.
 DecisionQueue getDecisionQueue()
          Returns the DecisionQueue associated with this WorkflowManager
protected  WikiEngine getEngine()
          Protected helper method that returns the associated WikiEngine
 Collection getOwnerWorkflows(WikiSession session)
          Returns the current workflows a wiki session owns.
 Collection getWorkflows()
          Returns a collection of the currently active workflows.
 void initialize(WikiEngine engine, Properties props)
          Initializes the WorkflowManager using a specfied WikiEngine and properties.
protected  void remove(Workflow workflow)
          Protected helper method that removes a specified Workflow from the cache, and moves it to the workflow history list.
 boolean requiresApproval(String messageKey)
          Returns true if a workflow matching a particular key contains an approval step.
 void start(Workflow workflow)
          Adds a new workflow to the set of workflows and starts it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_APPROVER_PREFIX

protected static final String PROPERTY_APPROVER_PREFIX
The prefix to use for looking up jspwiki.properties approval roles.

See Also:
Constant Field Values
Constructor Detail

WorkflowManager

public WorkflowManager()
Constructs a new WorkflowManager, with an empty workflow cache. New Workflows are automatically assigned unique identifiers, starting with 1.

Method Detail

start

public void start(Workflow workflow)
           throws WikiException
Adds a new workflow to the set of workflows and starts it. The new workflow is automatically assigned a unique ID. If another workflow with the same ID already exists, this method throws a WikIException.

Parameters:
workflow - the workflow to start
Throws:
WikiException - if a workflow the automatically assigned ID already exist; this should not happen normally

getWorkflows

public Collection getWorkflows()
Returns a collection of the currently active workflows.

Returns:
the current workflows

getCompletedWorkflows

public List getCompletedWorkflows()
Returns a collection of finished workflows; that is, those that have aborted or completed.

Returns:
the finished workflows

initialize

public void initialize(WikiEngine engine,
                       Properties props)
Initializes the WorkflowManager using a specfied WikiEngine and properties. Any properties that begin with PROPERTY_APPROVER_PREFIX will be assumed to be Decisions that require approval. For a given property key, everything after the prefix denotes the Decision's message key. The property value indicates the Principal (Role, GroupPrincipal, WikiPrincipal) that must approve the Decision. For example, if the property key/value pair is jspwiki.approver.workflow.saveWikiPage=Admin, the Decision's message key is workflow.saveWikiPage. The Principal Admin will be resolved via AuthorizationManager.resolvePrincipal(String).

Parameters:
engine - the wiki engine to associate with this WorkflowManager
props - the wiki engine's properties

requiresApproval

public boolean requiresApproval(String messageKey)
Returns true if a workflow matching a particular key contains an approval step.

Parameters:
messageKey - the name of the workflow; corresponds to the value returned by Workflow.getMessageKey().
Returns:
the result

getApprover

public Principal getApprover(String messageKey)
                      throws WikiException
Looks up and resolves the actor who approves a Decision for a particular Workflow, based on the Workflow's message key. If not found, or if Principal is Unresolved, throws WikiException. This particular implementation always returns the GroupPrincipal Admin

Parameters:
messageKey - the Decision's message key
Returns:
the actor who approves Decisions
Throws:
WikiException - if the message key was not found, or the Principal value corresponding to the key could not be resolved

getEngine

protected WikiEngine getEngine()
Protected helper method that returns the associated WikiEngine

Returns:
the wiki engine

getDecisionQueue

public DecisionQueue getDecisionQueue()
Returns the DecisionQueue associated with this WorkflowManager

Returns:
the decision queue

getOwnerWorkflows

public Collection getOwnerWorkflows(WikiSession session)
Returns the current workflows a wiki session owns. These are workflows whose Workflow.getOwner() method returns a Principal also possessed by the wiki session (see WikiSession.getPrincipals()). If the wiki session is not authenticated, this method returns an empty Collection.

Parameters:
session - the wiki session
Returns:
the collection workflows the wiki session owns, which may be empty

actionPerformed

public void actionPerformed(WikiEvent event)
Listens for WorkflowEvent objects emitted by Workflows. In particular, this method listens for WorkflowEvent.CREATED, WorkflowEvent.ABORTED and WorkflowEvent.COMPLETED events. If a workflow is created, it is automatically added to the cache. If one is aborted or completed, it is automatically removed.

Specified by:
actionPerformed in interface WikiEventListener
Parameters:
event - the event passed to this listener

add

protected void add(Workflow workflow)
Protected helper method that adds a newly created Workflow to the cache, and sets its workflowManager and Id properties if not set.

Parameters:
workflow - the workflow to add

remove

protected void remove(Workflow workflow)
Protected helper method that removes a specified Workflow from the cache, and moves it to the workflow history list. This method defensively checks to see if the workflow has not yet been removed.

Parameters:
workflow - the workflow to remove


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.