Package org.apache.wiki.workflow

## Class DefaultWorkflowManager

- java.lang.Object
- - org.apache.wiki.workflow.DefaultWorkflowManager

All Implemented Interfaces:
  `java.io.Serializable`, `java.util.EventListener`, `Initializable`, `WikiEventListener`, `WorkflowManager`

    public class DefaultWorkflowManager
    extends java.lang.Object
    implements WorkflowManager, java.io.Serializable

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

See Also:
  Serialized Form

### Field Summary

### Fields inherited from interface org.apache.wiki.workflow.WorkflowManager

`PROPERTY_APPROVER_PREFIX, WF_UP_CREATE_SAVE_APPROVER, WF_UP_CREATE_SAVE_ATTR_SAVED_PROFILE, WF_UP_CREATE_SAVE_DECISION_MESSAGE_KEY, WF_UP_CREATE_SAVE_FACT_PREFS_EMAIL, WF_UP_CREATE_SAVE_FACT_PREFS_FULL_NAME, WF_UP_CREATE_SAVE_FACT_PREFS_LOGIN_NAME, WF_UP_CREATE_SAVE_FACT_SUBMITTER, WF_WP_SAVE_APPROVER, WF_WP_SAVE_DECISION_MESSAGE_KEY, WF_WP_SAVE_FACT_CURRENT_TEXT, WF_WP_SAVE_FACT_DIFF_TEXT, WF_WP_SAVE_FACT_IS_AUTHENTICATED, WF_WP_SAVE_FACT_PAGE_NAME, WF_WP_SAVE_FACT_PROPOSED_TEXT, WF_WP_SAVE_REJECT_MESSAGE_KEY`

### Constructor Summary

Constructors
`DefaultWorkflowManager()` Constructs a new WorkflowManager, with an empty workflow cache.

### Method Summary

All Methods Instance Methods Concrete Methods
`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.
`protected void` `addToDecisionQueue​(Decision decision)`
`java.security.Principal` `getApprover​(java.lang.String messageKey)` Looks up and resolves the actor who approves a Decision for a particular Workflow, based on the Workflow's message key.
`java.util.List<Workflow>` `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 Engine` `getEngine()` Protected helper method that returns the associated Engine
`java.util.List<Workflow>` `getOwnerWorkflows​(Session session)` Returns the current workflows a wiki session owns.
`java.util.Set<Workflow>` `getWorkflows()` Returns a collection of the currently active workflows.
`java.util.Map<java.lang.Integer,​Workflow>` `getWorkflowsAsMap()` Returns a map of the currently active workflows.
`void` `initialize​(Engine engine, java.util.Properties props)` Any properties that begin with `WorkflowManager.PROPERTY_APPROVER_PREFIX` will be assumed to be Decisions that require approval.
`protected void` `remove​(Workflow workflow)` Protected helper method that removes a specified Workflow from the cache, and moves it to the workflow history list.
`protected void` `removeFromDecisionQueue​(Decision decision, Context context)`
`boolean` `requiresApproval​(java.lang.String messageKey)` Returns `true` if a workflow matching a particular key contains an approval step.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DefaultWorkflowManager

    public DefaultWorkflowManager()

Constructs a new WorkflowManager, with an empty workflow cache.

### Method Detail

#### getWorkflows

    public java.util.Set<Workflow> getWorkflows()

Returns a collection of the currently active workflows.

Specified by:
  `getWorkflows` in interface `WorkflowManager`
Returns:
  the current workflows

#### getWorkflowsAsMap

    public java.util.Map<java.lang.Integer,​Workflow> getWorkflowsAsMap()

Returns a map of the currently active workflows.

Specified by:
  `getWorkflowsAsMap` in interface `WorkflowManager`
Returns:
  the current workflows as workflowId -> workflow tuples

#### getCompletedWorkflows

    public java.util.List<Workflow> getCompletedWorkflows()

Returns a collection of finished workflows; that is, those that have aborted or completed.

Specified by:
  `getCompletedWorkflows` in interface `WorkflowManager`
Returns:
  the finished workflows

#### initialize

    public void initialize​(Engine engine,
                           java.util.Properties props)

Any properties that begin with `WorkflowManager.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)`.

Specified by:
  `initialize` in interface `Initializable`

#### requiresApproval

    public boolean requiresApproval​(java.lang.String messageKey)

Returns `true` if a workflow matching a particular key contains an approval step.

Specified by:
  `requiresApproval` in interface `WorkflowManager`
Parameters:
  `messageKey` - the name of the workflow; corresponds to the value returned by `Workflow.getMessageKey()`.
Returns:
  the result

#### getApprover

    public java.security.Principal getApprover​(java.lang.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`

Specified by:
  `getApprover` in interface `WorkflowManager`
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 Engine getEngine()

Protected helper method that returns the associated Engine

Returns:
  the wiki engine

#### getDecisionQueue

    public DecisionQueue getDecisionQueue()

Returns the DecisionQueue associated with this WorkflowManager

Specified by:
  `getDecisionQueue` in interface `WorkflowManager`
Returns:
  the decision queue

#### getOwnerWorkflows

    public java.util.List<Workflow> getOwnerWorkflows​(Session 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 `Session.getPrincipals()`). If the wiki session is not authenticated, this method returns an empty Collection.

Specified by:
  `getOwnerWorkflows` in interface `WorkflowManager`
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`, `WorkflowEvent.COMPLETED` and `WorkflowEvent.DQ_REMOVAL` events. If a workflow is created, it is automatically added to the cache. If one is aborted or completed, it is automatically removed. If a removal from decision queue is issued, the current step from workflow, which is assumed to be a `Decision`, is removed from the `DecisionQueue`.

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

#### removeFromDecisionQueue

    protected void removeFromDecisionQueue​(Decision decision,
                                           Context context)

#### addToDecisionQueue

    protected void addToDecisionQueue​(Decision decision)