public class

OSWorkflowManager

extends Object
implements WorkflowManager
java.lang.Object
   ↳ com.atlassian.jira.workflow.OSWorkflowManager

Summary

Public Constructors
OSWorkflowManager(Configuration configuration, DraftWorkflowStore draftWorkflowStore, EventPublisher eventPublisher, WorkflowsRepository workflowsRepository, WorkflowCopyNameFactory workflowCopyNameFactory, JiraAuthenticationContext context)
Public Methods
void copyAndDeleteDraftWorkflows(User user, Set<JiraWorkflow> workflows)
Provided a set of workflows, this method will check, if the passed in inactive workflows have any drafts linked to them.
void copyAndDeleteDraftsForInactiveWorkflowsIn(User user, Iterable<JiraWorkflow> workflows)
Provided a set of workflows, this method will check, if the passed in inactive workflows have any drafts linked to them.
JiraWorkflow copyWorkflow(String username, String clonedWorkflowName, String clonedWorkflowDescription, JiraWorkflow workflowToClone)
Clones a workflow by creating a deep copy of the workflow provided.
JiraWorkflow copyWorkflow(ApplicationUser user, String clonedWorkflowName, String clonedWorkflowDescription, JiraWorkflow workflowToClone)
Clones a workflow by creating a deep copy of the workflow provided.
JiraWorkflow createDraftWorkflow(String username, String parentWorkflowName)
This will create an draft workflow of the named active workflow.
JiraWorkflow createDraftWorkflow(ApplicationUser user, String parentWorkflowName)
This will create an draft workflow of the named active workflow.
GenericValue createIssue(String remoteUserName, Map<StringObject> fields)
Create an issue in the database.
void createWorkflow(ApplicationUser user, JiraWorkflow workflow)
void createWorkflow(String username, JiraWorkflow workflow)
void createWorkflow(User creator, JiraWorkflow workflow)
boolean deleteDraftWorkflow(String parentWorkflowName)
Deletes all draft workflows (there should every be only one) for a given parent workflow.
void deleteWorkflow(JiraWorkflow workflow)
void doWorkflowAction(WorkflowProgressAware from)
ActionDescriptor getActionDescriptor(WorkflowProgressAware workflowProgressAware)
Collection<JiraWorkflow> getActiveWorkflows()
Retrieve all currently active workflows.
JiraWorkflow getDefaultWorkflow()
JiraWorkflow getDraftWorkflow(String parentWorkflowName)
Retrieve a single draft workflow by name.
Map<ActionDescriptor, Collection<FunctionDescriptor>> getPostFunctionsForWorkflow(JiraWorkflow workflow)
Retrieve a map: actions -> post functions for a workflow.
User getRemoteUser(Map transientVars)
Get the remote User
String getStepId(long actionDescriptorId, String workflowName)
Gets the first stepId for the given action and workflow name.
WorkflowStore getStore()
This is used for unit testing so we can return our own 'mock store' instead of the static StoreFactory.getPersistence(ctx);

Also used in the migrateIssueToWorkflow method.

JiraWorkflow getWorkflow(String name)
Retrieve a single workflow by name.
JiraWorkflow getWorkflow(Long projectId, String issueTypeId)
Retrieve the workflow for a given project - issue type pair.
JiraWorkflow getWorkflow(GenericValue issue)
Retrieve the workflow for a given issue.
JiraWorkflow getWorkflow(Issue issue)
Retrieve the workflow for a given issue.
JiraWorkflow getWorkflowClone(String name)
This method returns a JiraWorkflow, that contains a com.opensymphony.workflow.loader.WorkflowDescriptor that is mutable.
JiraWorkflow getWorkflowFromScheme(GenericValue scheme, String issueTypeId)
Return the workflow in a particular scheme for a given issue type.
JiraWorkflow getWorkflowFromScheme(WorkflowScheme scheme, String issueTypeId)
Return the workflow in a particular scheme for a given issue type.
Collection<JiraWorkflow> getWorkflows()
Retrieve all of the workflows in the system
Iterable<JiraWorkflow> getWorkflowsFromScheme(Scheme workflowScheme)
Returns all workflows for a given scheme.
Collection<JiraWorkflow> getWorkflowsFromScheme(GenericValue scheme)
Returns all workflows for a given scheme.
List<JiraWorkflow> getWorkflowsIncludingDrafts()
Retrieve all of the workflows in the system including drafts.
boolean isActive(JiraWorkflow workflow)
Determine whether or not a given workflow is active in the system.
boolean isEditable(Issue issue)
boolean isSystemWorkflow(JiraWorkflow workflow)
Determine whether or not a given workflow is a system workflow.
Workflow makeWorkflow(User user)
Prepares Workflow object with given user as caller
Workflow makeWorkflow(String userName)
Prepares Workflow object with given username as caller
Workflow makeWorkflow(ApplicationUser applicationUser)
Prepares Workflow object with given user as caller
Workflow makeWorkflowWithUserKey(String userKey)
Workflow makeWorkflowWithUserName(String userName)
void migrateIssueToWorkflow(MutableIssue issue, JiraWorkflow newWorkflow, Status status)
Migrates given issue to new workflow and sets new status on it.
void migrateIssueToWorkflow(GenericValue issue, JiraWorkflow newWorkflow, GenericValue newStatus)
Migrates given issue to new workflow and sets new status on it.
boolean migrateIssueToWorkflowNoReindex(GenericValue issue, JiraWorkflow newWorkflow, GenericValue newStatus)
Migrates given issue to new workflow and sets new status on it.
void overwriteActiveWorkflow(String username, String workflowName)
Saves the draft workflow into the active workflow.
void overwriteActiveWorkflow(ApplicationUser user, String workflowName)
Saves the draft workflow into the active workflow.
void removeWorkflowEntries(GenericValue issue)
void saveWorkflowWithoutAudit(JiraWorkflow workflow)
This method will save the workflow and it will not affect the updatedDate and updatedAuthorName meta attributes of the workflow.
void updateWorkflow(ApplicationUser user, JiraWorkflow workflow)
Saves the given JiraWorkflow, which may be either a "live" or "draft" version.
void updateWorkflow(String username, JiraWorkflow workflow)
Saves the given JiraWorkflow, which may be either a "live" or "draft" version.
void updateWorkflowNameAndDescription(String username, JiraWorkflow currentWorkflow, String newName, String newDescription)
Used to change the name and description of an existing worfklow with the given name.
void updateWorkflowNameAndDescription(ApplicationUser user, JiraWorkflow currentWorkflow, String newName, String newDescription)
Used to change the name and description of an existing worfklow with the given name.
boolean workflowExists(String name)
Protected Methods
Configuration getConfiguration()
String getWorkflowName(Long projectId, String issueType)
This method returns the (unique) name of the workflow which should be used for the provided projectId and issueType
WorkflowSchemeManager getWorkflowSchemeManager()
boolean updateIssueStatusAndUpdatedDate(GenericValue issue, GenericValue newStatus)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.workflow.WorkflowManager

Public Constructors

public OSWorkflowManager (Configuration configuration, DraftWorkflowStore draftWorkflowStore, EventPublisher eventPublisher, WorkflowsRepository workflowsRepository, WorkflowCopyNameFactory workflowCopyNameFactory, JiraAuthenticationContext context)

Public Methods

public void copyAndDeleteDraftWorkflows (User user, Set<JiraWorkflow> workflows)

Provided a set of workflows, this method will check, if the passed in inactive workflows have any drafts linked to them. If they do, it will copy the draft into a new inactive workflow, and then delete the draft.

Parameters
user The user performing the operation
workflows A set of parent JiraWorkflows

public void copyAndDeleteDraftsForInactiveWorkflowsIn (User user, Iterable<JiraWorkflow> workflows)

Provided a set of workflows, this method will check, if the passed in inactive workflows have any drafts linked to them. If they do, it will copy the draft into a new inactive workflow, and then delete the draft. This method is only meant to be used internally in JIRA. External developers should not call this method directly.

Parameters
user The user performing the operation
workflows A set of parent JiraWorkflows

public JiraWorkflow copyWorkflow (String username, String clonedWorkflowName, String clonedWorkflowDescription, JiraWorkflow workflowToClone)

Clones a workflow by creating a deep copy of the workflow provided.

Parameters
username The user performing the operation
clonedWorkflowName The name to store the new workflow with.
clonedWorkflowDescription The description to store with the cloned workflow. Can be null.
workflowToClone The workflow to copy.
Returns
  • A cloned copy of the original workflow.

public JiraWorkflow copyWorkflow (ApplicationUser user, String clonedWorkflowName, String clonedWorkflowDescription, JiraWorkflow workflowToClone)

Clones a workflow by creating a deep copy of the workflow provided.

Parameters
user The user performing the operation
clonedWorkflowName The name to store the new workflow with.
clonedWorkflowDescription The description to store with the cloned workflow. Can be null.
workflowToClone The workflow to copy.
Returns
  • A cloned copy of the original workflow.

public JiraWorkflow createDraftWorkflow (String username, String parentWorkflowName)

This will create an draft workflow of the named active workflow. This draft workflow can be used to edit active workflows without overwriting the active workflow immediately.
This method will not allow you to create an draft workflow if the parent workflow is not active, the method will throw an IllegalStateException in this case.

Parameters
username identifies the user performing the action so that we can keep an audit trail of who has last saved the workflow. Empty string for anonymous user. If null an IllegalArgumentException will be thrown
parentWorkflowName identifies the parent workflow that should be used as the template for creating the draft workflow.
Returns
  • An instance of JiraWorkflow that represents a copy of the parent that can be edited without overwriting the active workflow immediately.

public JiraWorkflow createDraftWorkflow (ApplicationUser user, String parentWorkflowName)

This will create an draft workflow of the named active workflow. This draft workflow can be used to edit active workflows without overwriting the active workflow immediately.
This method will not allow you to create an draft workflow if the parent workflow is not active, the method will throw an IllegalStateException in this case.

Parameters
user identifies the user performing the action so that we can keep an audit trail of who has last saved the workflow. Empty string for anonymous user. If null an IllegalArgumentException will be thrown
parentWorkflowName identifies the parent workflow that should be used as the template for creating the draft workflow.
Returns
  • An instance of JiraWorkflow that represents a copy of the parent that can be edited without overwriting the active workflow immediately.

public GenericValue createIssue (String remoteUserName, Map<StringObject> fields)

Create an issue in the database.

Parameters
remoteUserName Issue creator
fields Map of fields. The key is the name of the field, and the type of the value depends on the key. Must include a key "issue", which contains MutableIssue object (holding values, not yet persisted to disk). May include other fields (eg "pkey"->String key of project, "originalissueobject"->Issue object) passed onto the workflow engine.
Returns
  • The created issue GenericValue

public void createWorkflow (ApplicationUser user, JiraWorkflow workflow)

public void createWorkflow (String username, JiraWorkflow workflow)

public void createWorkflow (User creator, JiraWorkflow workflow)

public boolean deleteDraftWorkflow (String parentWorkflowName)

Deletes all draft workflows (there should every be only one) for a given parent workflow.

Parameters
parentWorkflowName The parentworkflow for which the draft workflow needs to be deleted.
Returns
  • true if a draft workflow as deleted, false otherwise.

public void deleteWorkflow (JiraWorkflow workflow)

public void doWorkflowAction (WorkflowProgressAware from)

public ActionDescriptor getActionDescriptor (WorkflowProgressAware workflowProgressAware)

Throws
Exception

public Collection<JiraWorkflow> getActiveWorkflows ()

Retrieve all currently active workflows.

Returns
  • Collection of JiraWorkflow objects.

public JiraWorkflow getDefaultWorkflow ()

public JiraWorkflow getDraftWorkflow (String parentWorkflowName)

Retrieve a single draft workflow by name. If there is not an draft workflow associated with the name this will return null.

Parameters
parentWorkflowName is the name of the Saved workflow which identifies then paritally edited draft workflow to retrieve.
Returns
  • a JiraWorkflow that represents an draft edited workflow.

public Map<ActionDescriptor, Collection<FunctionDescriptor>> getPostFunctionsForWorkflow (JiraWorkflow workflow)

Retrieve a map: actions -> post functions for a workflow.

Parameters
workflow The Workflow
Returns
  • Map of actions-> post functions

public User getRemoteUser (Map transientVars)

Get the remote User

Parameters
transientVars ??
Returns
  • Remote user

public String getStepId (long actionDescriptorId, String workflowName)

Gets the first stepId for the given action and workflow name.

Parameters
actionDescriptorId id of the ActionDescriptor
workflowName name of the JiraWorkflow
Returns
  • the first stepId for the given action and workflow name.

public WorkflowStore getStore ()

This is used for unit testing so we can return our own 'mock store' instead of the static StoreFactory.getPersistence(ctx);

Also used in the migrateIssueToWorkflow method.

Throws
StoreException

public JiraWorkflow getWorkflow (String name)

Retrieve a single workflow by name. The returned JiraWorkflow contains a descriptor that by default isn't mutable.

If you need to edit a workflow, please see getWorkflowClone(String).

Parameters
name The workflow name
Returns
  • A JiraWorkflow that wraps an Immutable WorkflowDescriptor or null

public JiraWorkflow getWorkflow (Long projectId, String issueTypeId)

Retrieve the workflow for a given project - issue type pair.

Parameters
projectId the Project
issueTypeId the IssueType ID
Returns
  • the workflow for the given project - issue type pair.

public JiraWorkflow getWorkflow (GenericValue issue)

Retrieve the workflow for a given issue.

Parameters
issue the Issue
Returns
  • the workflow for the given issue.

public JiraWorkflow getWorkflow (Issue issue)

Retrieve the workflow for a given issue.

Parameters
issue the Issue
Returns
  • the workflow for the given issue.

public JiraWorkflow getWorkflowClone (String name)

This method returns a JiraWorkflow, that contains a com.opensymphony.workflow.loader.WorkflowDescriptor that is mutable. This method should be called, if you require to edit the workflow.

If you only need to view a workflow, please use getWorkflow(String) as it will provide better performance. Cloning a workflow is expensive, as it requires de-constructing and re-constructing the underlying com.opensymphony.workflow.loader.WorkflowDescriptor from XML.

Parameters
name The workflow name
Returns

public JiraWorkflow getWorkflowFromScheme (GenericValue scheme, String issueTypeId)

Return the workflow in a particular scheme for a given issue type.

Parameters
scheme the Scheme
issueTypeId the IssueType ID
Returns
  • the workflow for the issue type in the scheme.

public JiraWorkflow getWorkflowFromScheme (WorkflowScheme scheme, String issueTypeId)

Return the workflow in a particular scheme for a given issue type.

Parameters
scheme the Scheme
issueTypeId the IssueType ID
Returns
  • the workflow for the issue type in the scheme.

public Collection<JiraWorkflow> getWorkflows ()

Retrieve all of the workflows in the system

Returns
  • A collection of JiraWorkflow objects.

public Iterable<JiraWorkflow> getWorkflowsFromScheme (Scheme workflowScheme)

Returns all workflows for a given scheme.

Parameters
workflowScheme the Workflow Scheme.
Returns
  • Collection of workflow schemes, empty collection if none exists.

public Collection<JiraWorkflow> getWorkflowsFromScheme (GenericValue scheme)

Returns all workflows for a given scheme.

Parameters
scheme the Workflow Scheme.
Returns
  • Collection of workflow schemes, empty collection if none exists.

public List<JiraWorkflow> getWorkflowsIncludingDrafts ()

Retrieve all of the workflows in the system including drafts. We return a list as we want to keep workflows and associated drafts are adjacent.

Returns

public boolean isActive (JiraWorkflow workflow)

Determine whether or not a given workflow is active in the system.

Active workflows are those currently assigned to schemes and associated with projects - they cannot be edited but can be used.

Parameters
workflow the JiraWorkflow to check
Returns
  • true if the given workflow is active

public boolean isEditable (Issue issue)

public boolean isSystemWorkflow (JiraWorkflow workflow)

Determine whether or not a given workflow is a system workflow.

Check for a system or XML based workflow - can not be edited.

Parameters
workflow the JiraWorkflow to check
Returns
  • true if the given workflow is a system workflow

public Workflow makeWorkflow (User user)

Prepares Workflow object with given user as caller

Parameters
user caller
Returns
  • created Workflow

public Workflow makeWorkflow (String userName)

Prepares Workflow object with given username as caller

Parameters
userName caller username
Returns
  • created Workflow

public Workflow makeWorkflow (ApplicationUser applicationUser)

Prepares Workflow object with given user as caller

Parameters
applicationUser caller
Returns
  • created Workflow

public Workflow makeWorkflowWithUserKey (String userKey)

public Workflow makeWorkflowWithUserName (String userName)

public void migrateIssueToWorkflow (MutableIssue issue, JiraWorkflow newWorkflow, Status status)

Migrates given issue to new workflow and sets new status on it.

Parameters
issue issue to migrate
newWorkflow new workflow
status new status
Throws
WorkflowException if migration fails

public void migrateIssueToWorkflow (GenericValue issue, JiraWorkflow newWorkflow, GenericValue newStatus)

Migrates given issue to new workflow and sets new status on it.

Parameters
issue issue to migrate
newWorkflow new workflow
newStatus new status

public boolean migrateIssueToWorkflowNoReindex (GenericValue issue, JiraWorkflow newWorkflow, GenericValue newStatus)

Migrates given issue to new workflow and sets new status on it. It returns true iff the issue that was migrated needs a reindex. The passed issue is not reindexed even if necessary.

Parameters
issue issue to migrate
newWorkflow new workflow
newStatus new status
Returns
  • true if the issue

public void overwriteActiveWorkflow (String username, String workflowName)

Saves the draft workflow into the active workflow.

Parameters
username User will be added to the workflows Audit trail
workflowName The workflow to be overwritten

public void overwriteActiveWorkflow (ApplicationUser user, String workflowName)

Saves the draft workflow into the active workflow.

Parameters
user User will be added to the workflows Audit trail
workflowName The workflow to be overwritten

public void removeWorkflowEntries (GenericValue issue)

public void saveWorkflowWithoutAudit (JiraWorkflow workflow)

This method will save the workflow and it will not affect the updatedDate and updatedAuthorName meta attributes of the workflow. This should only ever be invoked by system operations such as upgrade tasks. All other saves should use the method updateWorkflow(String, JiraWorkflow)

Parameters
workflow the workflow to save.

public void updateWorkflow (ApplicationUser user, JiraWorkflow workflow)

Saves the given JiraWorkflow, which may be either a "live" or "draft" version. This method does not save the changes to the active workflow. Instead, this is meant to be used to make persistent changes to your working edit. Once all changes have been made you can over write the active workflow by calling overwriteActiveWorkflow(ApplicationUser, String)

Parameters
user User making the request.
workflow The JiraWorkflow to save.

public void updateWorkflow (String username, JiraWorkflow workflow)

Saves the given JiraWorkflow, which may be either a "live" or "draft" version. This method does not save the changes to the active workflow. Instead, this is meant to be used to make persistent changes to your working edit. Once all changes have been made you can over write the active workflow by calling overwriteActiveWorkflow(String, String)

Parameters
username User making the request.
workflow The JiraWorkflow to save.

public void updateWorkflowNameAndDescription (String username, JiraWorkflow currentWorkflow, String newName, String newDescription)

Used to change the name and description of an existing worfklow with the given name.

Parameters
username The user performing the operation
currentWorkflow The workflow to update.
newName The new name to save with the workflow
newDescription The new description to save with the workflow

public void updateWorkflowNameAndDescription (ApplicationUser user, JiraWorkflow currentWorkflow, String newName, String newDescription)

Used to change the name and description of an existing worfklow with the given name.

Parameters
user The user performing the operation
currentWorkflow The workflow to update.
newName The new name to save with the workflow
newDescription The new description to save with the workflow

public boolean workflowExists (String name)

Protected Methods

protected Configuration getConfiguration ()

protected String getWorkflowName (Long projectId, String issueType)

This method returns the (unique) name of the workflow which should be used for the provided projectId and issueType

Returns
  • the name of the workflow that should be used for the issue

protected WorkflowSchemeManager getWorkflowSchemeManager ()

protected boolean updateIssueStatusAndUpdatedDate (GenericValue issue, GenericValue newStatus)