com.atlassian.jira.bc.project
Class DefaultProjectService

java.lang.Object
  extended by com.atlassian.jira.bc.project.DefaultProjectService
All Implemented Interfaces:
ProjectService

public class DefaultProjectService
extends Object
implements ProjectService


Nested Class Summary
protected  class DefaultProjectService.PermissionErrorResult
          A GetProjectResult that indicates the calling user does not have permission to perform an action on a project.
protected  class DefaultProjectService.ProjectNotFoundResult
          A GetProjectResult that indicates a project was not found.
 
Nested classes/interfaces inherited from interface com.atlassian.jira.bc.project.ProjectService
ProjectService.AbstractProjectResult, ProjectService.AbstractProjectValidationResult, ProjectService.CreateProjectResult, ProjectService.CreateProjectValidationResult, ProjectService.DeleteProjectResult, ProjectService.DeleteProjectValidationResult, ProjectService.GetProjectResult, ProjectService.UpdateProjectSchemesValidationResult, ProjectService.UpdateProjectValidationResult
 
Field Summary
 
Fields inherited from interface com.atlassian.jira.bc.project.ProjectService
PROJECT_DESCRIPTION, PROJECT_KEY, PROJECT_LEAD, PROJECT_NAME, PROJECT_URL
 
Constructor Summary
DefaultProjectService(JiraAuthenticationContext jiraAuthenticationContext, ProjectManager projectManager, ApplicationProperties applicationProperties, PermissionManager permissionManager, PermissionSchemeManager permissionSchemeManager, NotificationSchemeManager notificationSchemeManager, IssueSecuritySchemeManager issueSecuritySchemeManager, SchemeFactory schemeFactory, WorkflowSchemeManager workflowSchemeManager, IssueTypeScreenSchemeManager issueTypeScreenSchemeManager, CustomFieldManager customFieldManager, NodeAssociationStore nodeAssociationStore, VersionManager versionManager, ProjectComponentManager projectComponentManager, SharePermissionDeleteUtils sharePermissionDeleteUtils, AvatarManager avatarManager, I18nHelper.BeanFactory i18nFactory)
           
 
Method Summary
 Project createProject(ProjectService.CreateProjectValidationResult result)
          Using the validation result from ProjectService.validateCreateProject(User, String, String, String, String, String, Long) a new project will be created.
 ProjectService.DeleteProjectResult deleteProject(com.atlassian.crowd.embedded.api.User user, ProjectService.DeleteProjectValidationResult result)
          Deletes the project provided by the deleteProjectValidationResult.
 ServiceOutcome<List<Project>> getAllProjects(com.atlassian.crowd.embedded.api.User user)
          Used to retrieve a list of Project objects.
 ServiceOutcome<List<Project>> getAllProjectsForAction(com.atlassian.crowd.embedded.api.User user, ProjectAction action)
          Used to retrieve a list of Project objects.
protected  I18nHelper getI18nBean(com.atlassian.crowd.embedded.api.User user)
           
 ProjectService.GetProjectResult getProjectById(com.atlassian.crowd.embedded.api.User user, Long id)
          Used to retrieve a Project object by id.
 ProjectService.GetProjectResult getProjectByIdForAction(com.atlassian.crowd.embedded.api.User user, Long id, ProjectAction action)
          Used to retrieve a Project object by id providing the user can perform the passed action on the project.
 ProjectService.GetProjectResult getProjectByKey(com.atlassian.crowd.embedded.api.User user, String key)
          Used to retrieve a Project object by key.
 ProjectService.GetProjectResult getProjectByKeyForAction(com.atlassian.crowd.embedded.api.User user, String key, ProjectAction action)
          Used to retrieve a Project object by key providing the user can perform the passed action on the project.
 String getProjectKeyDescription()
          Get the project key description from the properties file.
protected  JiraServiceContext getServiceContext(com.atlassian.crowd.embedded.api.User user, ErrorCollection errorCollection)
           
 boolean isValidAllProjectData(JiraServiceContext serviceContext, String name, String key, String lead, String url, Long assigneeType)
          Will validate all project fields setting the appropriate errors in the JiraServiceContext if any errors occur.
 boolean isValidAllProjectData(JiraServiceContext serviceContext, String name, String key, String lead, String url, Long assigneeType, Long avatarId)
          Will validate all project fields setting the appropriate errors in the JiraServiceContext if any errors occur.
 boolean isValidRequiredProjectData(JiraServiceContext serviceContext, String name, String key, String lead)
          Will validate the fields required for creating a project and setting the appropriate validation errors in the JiraServiceContext if any errors occur.
protected  ErrorCollection makeErrorCollection(com.atlassian.crowd.embedded.api.User user, String i18nKey, ErrorCollection.Reason reason, String... params)
          Creates a new ErrorCollection instance for a single error message.
 Project updateProject(ProjectService.UpdateProjectValidationResult result)
          Using the validation result from ProjectService.validateUpdateProject(User, String, String, String, String, String, Long) this method performs the actual update on the project.
 void updateProjectSchemes(ProjectService.UpdateProjectSchemesValidationResult result, Project project)
          Updates the project schemes for a particular project, given a validation result and project to update.
 ProjectService.CreateProjectValidationResult validateCreateProject(com.atlassian.crowd.embedded.api.User user, String name, String key, String description, String lead, String url, Long assigneeType)
          This method needs to be called before creating a project to ensure all parameters are correct.
 ProjectService.CreateProjectValidationResult validateCreateProject(com.atlassian.crowd.embedded.api.User user, String name, String key, String description, String lead, String url, Long assigneeType, Long avatarId)
          This method needs to be called before creating a project to ensure all parameters are correct.
 ProjectService.DeleteProjectValidationResult validateDeleteProject(com.atlassian.crowd.embedded.api.User user, String key)
          Validation to delete a project is quite straightforward.
 ServiceResult validateUpdateProject(com.atlassian.crowd.embedded.api.User user, String key)
          Validates that the given user is authorised to update a project.
 ProjectService.UpdateProjectValidationResult validateUpdateProject(com.atlassian.crowd.embedded.api.User user, String name, String key, String description, String lead, String url, Long assigneeType)
          Validates updating a project's details.
 ProjectService.UpdateProjectValidationResult validateUpdateProject(com.atlassian.crowd.embedded.api.User user, String name, String key, String description, String lead, String url, Long assigneeType, Long avatarId)
          Validates updating a project's details.
 ProjectService.UpdateProjectSchemesValidationResult validateUpdateProjectSchemes(com.atlassian.crowd.embedded.api.User user, Long permissionSchemeId, Long notificationSchemeId, Long issueSecuritySchemeId)
          If the scheme ids are not null or -1 (-1 is often used to reset schemes), then an attempt will be made to retrieve the scheme.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultProjectService

public DefaultProjectService(JiraAuthenticationContext jiraAuthenticationContext,
                             ProjectManager projectManager,
                             ApplicationProperties applicationProperties,
                             PermissionManager permissionManager,
                             PermissionSchemeManager permissionSchemeManager,
                             NotificationSchemeManager notificationSchemeManager,
                             IssueSecuritySchemeManager issueSecuritySchemeManager,
                             SchemeFactory schemeFactory,
                             WorkflowSchemeManager workflowSchemeManager,
                             IssueTypeScreenSchemeManager issueTypeScreenSchemeManager,
                             CustomFieldManager customFieldManager,
                             NodeAssociationStore nodeAssociationStore,
                             VersionManager versionManager,
                             ProjectComponentManager projectComponentManager,
                             SharePermissionDeleteUtils sharePermissionDeleteUtils,
                             AvatarManager avatarManager,
                             I18nHelper.BeanFactory i18nFactory)
Method Detail

validateCreateProject

public ProjectService.CreateProjectValidationResult validateCreateProject(com.atlassian.crowd.embedded.api.User user,
                                                                          String name,
                                                                          String key,
                                                                          String description,
                                                                          String lead,
                                                                          String url,
                                                                          Long assigneeType)
Description copied from interface: ProjectService
This method needs to be called before creating a project to ensure all parameters are correct. There are a number of required parameters, such as a project name, key and lead. The validation will also check if a project with the name or key provided already exists and throw an appropriate error. The project key will be validated that it matches the allowed key pattern, and it is not a reserved word. A validation error will also be added if no user exists for the lead username provided.

The default avatar will be used for the created project.

Optional validation will be done for the url and assigneetype parameters. The url needs to be a valid URL, and the assigneeType needs to be either AssigneeTypes.PROJECT_LEAD or AssigneeTypes.UNASSIGNED. UNASSIGNED will also only be valid, if unassigned issues are enabled in the General Configuration.

The method will return a ProjectService.CreateProjectValidationResult which contains an ErrorCollection with any potential errors and all the project's details.

Specified by:
validateCreateProject in interface ProjectService
Parameters:
user - The user trying to create a project
name - The name of the new project
key - The project key of the new project
description - An optional description for the project
lead - The lead developer for the project
url - An optional URL for the new project
assigneeType - The default assignee for issues created in this project. May be either project lead, or unassigned if unassigned issues are enabled.
Returns:
A validation result containing any errors and all project details

validateCreateProject

public ProjectService.CreateProjectValidationResult validateCreateProject(com.atlassian.crowd.embedded.api.User user,
                                                                          String name,
                                                                          String key,
                                                                          String description,
                                                                          String lead,
                                                                          String url,
                                                                          Long assigneeType,
                                                                          Long avatarId)
Description copied from interface: ProjectService
This method needs to be called before creating a project to ensure all parameters are correct. There are a number of required parameters, such as a project name, key and lead. The validation will also check if a project with the name or key provided already exists and throw an appropriate error. The project key will be validated that it matches the allowed key pattern, and it is not a reserved word. A validation error will also be added if no user exists for the lead username provided.

Optional validation will be done for the url, assigneetype and avatarId parameters. The url needs to be a valid URL and the assigneeType needs to be either AssigneeTypes.PROJECT_LEAD or AssigneeTypes.UNASSIGNED. UNASSIGNED will also only be valid, if unassigned issues are enabled in the General Configuration.

The method will return a ProjectService.CreateProjectValidationResult which contains an ErrorCollection with any potential errors and all the project's details.

Specified by:
validateCreateProject in interface ProjectService
Parameters:
user - The user trying to create a project
name - The name of the new project
key - The project key of the new project
description - An optional description for the project
lead - The lead developer for the project
url - An optional URL for the new project
assigneeType - The default assignee for issues created in this project. May be either project lead, or unassigned if unassigned issues are enabled.
avatarId - the id of an avatar.
Returns:
A validation result containing any errors and all project details

getServiceContext

protected JiraServiceContext getServiceContext(com.atlassian.crowd.embedded.api.User user,
                                               ErrorCollection errorCollection)

createProject

public Project createProject(ProjectService.CreateProjectValidationResult result)
Description copied from interface: ProjectService
Using the validation result from ProjectService.validateCreateProject(User, String, String, String, String, String, Long) a new project will be created. This method will throw an IllegalStateException if the validation result contains any errors.

Project creation involves creating the project itself and setting some defaults for workflow schemes and issue type screen schemes.

Specified by:
createProject in interface ProjectService
Parameters:
result - Result from the validation, which also contains all the project's details.
Returns:
The new project

validateUpdateProject

public ProjectService.UpdateProjectValidationResult validateUpdateProject(com.atlassian.crowd.embedded.api.User user,
                                                                          String name,
                                                                          String key,
                                                                          String description,
                                                                          String lead,
                                                                          String url,
                                                                          Long assigneeType)
Description copied from interface: ProjectService
Validates updating a project's details. The project is looked up by the key provided. If no project with the key provided can be found, an appropriate error will be added to the result.

Validation performed will be the same as for the ProjectService.validateCreateProject(User, String, String, String, String, String, Long) method. The only difference is that the project key will obviously not be validated.

A project can be updated by any user with the global admin permission or project admin permission for the project in question.

Specified by:
validateUpdateProject in interface ProjectService
Parameters:
user - The user trying to update a project
name - The name of the new project
key - The project key of the project to update.
description - An optional description for the project
lead - The lead developer for the project
url - An optional URL for the project
assigneeType - The default assignee for issues created in this project. May be either project lead, or unassigned if unassigned issues are enabled.
Returns:
A validation result containing any errors and all project details

validateUpdateProject

public ServiceResult validateUpdateProject(com.atlassian.crowd.embedded.api.User user,
                                           String key)
Description copied from interface: ProjectService
Validates that the given user is authorised to update a project. A project can be updated by any user with the global admin permission or project admin permission for the project in question.

Specified by:
validateUpdateProject in interface ProjectService
Parameters:
user - The user trying to update a project
key - The project key of the project to update.
Returns:
a ServiceResult, which will contain errors if the user is not authorised to update the project

validateUpdateProject

public ProjectService.UpdateProjectValidationResult validateUpdateProject(com.atlassian.crowd.embedded.api.User user,
                                                                          String name,
                                                                          String key,
                                                                          String description,
                                                                          String lead,
                                                                          String url,
                                                                          Long assigneeType,
                                                                          Long avatarId)
Description copied from interface: ProjectService
Validates updating a project's details. The project is looked up by the key provided. If no project with the key provided can be found, an appropriate error will be added to the result.

Validation performed will be the same as for the ProjectService.validateCreateProject(User, String, String, String, String, String, Long) method. The only difference is that the project key will obviously not be validated.

A project can be updated by any user with the global admin permission or project admin permission for the project in question.

Specified by:
validateUpdateProject in interface ProjectService
Parameters:
user - The user trying to update a project
name - The name of the new project
key - The project key of the project to update.
description - An optional description for the project
lead - The lead developer for the project
url - An optional URL for the project
assigneeType - The default assignee for issues created in this project. May be either project lead, or unassigned if unassigned issues are enabled.
avatarId - the id of an existing avatar.
Returns:
A validation result containing any errors and all project details

updateProject

public Project updateProject(ProjectService.UpdateProjectValidationResult result)
Description copied from interface: ProjectService
Using the validation result from ProjectService.validateUpdateProject(User, String, String, String, String, String, Long) this method performs the actual update on the project.

Specified by:
updateProject in interface ProjectService
Parameters:
result - Result from the validation, which also contains all the project's details.
Returns:
The updated project

validateUpdateProjectSchemes

public ProjectService.UpdateProjectSchemesValidationResult validateUpdateProjectSchemes(com.atlassian.crowd.embedded.api.User user,
                                                                                        Long permissionSchemeId,
                                                                                        Long notificationSchemeId,
                                                                                        Long issueSecuritySchemeId)
Description copied from interface: ProjectService
If the scheme ids are not null or -1 (-1 is often used to reset schemes), then an attempt will be made to retrieve the scheme. If this attempt fails an error will be added. IssueSecuritySchemes will only be validated in enterprise edition.

Specified by:
validateUpdateProjectSchemes in interface ProjectService
permissionSchemeId - The permission scheme that the new project should use
notificationSchemeId - The notification scheme that the new project should use. Optional.
issueSecuritySchemeId - The issue security scheme that the new project should use. Optional.
Returns:
A validation result containing any errors and all scheme ids

updateProjectSchemes

public void updateProjectSchemes(ProjectService.UpdateProjectSchemesValidationResult result,
                                 Project project)
Description copied from interface: ProjectService
Updates the project schemes for a particular project, given a validation result and project to update.

Specified by:
updateProjectSchemes in interface ProjectService
Parameters:
result - Result from the validation, which also contains all the schemes details.
project - The project which will have its schemes updated.

isValidAllProjectData

public boolean isValidAllProjectData(JiraServiceContext serviceContext,
                                     String name,
                                     String key,
                                     String lead,
                                     String url,
                                     Long assigneeType)
Description copied from interface: ProjectService
Will validate all project fields setting the appropriate errors in the JiraServiceContext if any errors occur.

Specified by:
isValidAllProjectData in interface ProjectService
Parameters:
serviceContext - containing the errorCollection that will be populated with any validation errors that are encountered
name - the name of the project @NotNull
key - the key of the project @NotNull
lead - the project lead @NotNull
url - the project URL (optional)
assigneeType - the default assignee type (optional - only appears on some forms)
Returns:
true if project data is valid, false otherwise

isValidAllProjectData

public boolean isValidAllProjectData(JiraServiceContext serviceContext,
                                     String name,
                                     String key,
                                     String lead,
                                     String url,
                                     Long assigneeType,
                                     Long avatarId)
Description copied from interface: ProjectService
Will validate all project fields setting the appropriate errors in the JiraServiceContext if any errors occur.

Specified by:
isValidAllProjectData in interface ProjectService
Parameters:
serviceContext - containing the errorCollection that will be populated with any validation errors that are encountered
name - the name of the project @NotNull
key - the key of the project @NotNull
lead - the project lead @NotNull
url - the project URL (optional)
assigneeType - the default assignee type (optional - only appears on some forms)
avatarId - the id of the avatar (null indicates default avatar)
Returns:
true if project data is valid, false otherwise

isValidRequiredProjectData

public boolean isValidRequiredProjectData(JiraServiceContext serviceContext,
                                          String name,
                                          String key,
                                          String lead)
Description copied from interface: ProjectService
Will validate the fields required for creating a project and setting the appropriate validation errors in the JiraServiceContext if any errors occur.

Specified by:
isValidRequiredProjectData in interface ProjectService
Parameters:
serviceContext - containing the errorCollection that will be populated with any validation errors that are encountered
name - the name of the project @NotNull
key - the key of the project @NotNull
lead - the project lead @NotNull
Returns:
true if project data is valid, false otherwise

getProjectKeyDescription

public String getProjectKeyDescription()
Description copied from interface: ProjectService
Get the project key description from the properties file. If the user has specified a custom regex that project keys must conform to and a description for that regex, this method should return the description.

If the user has not specified a custom regex, this method will return the default project key description:

"Usually the key is just 3 letters - i.e. if your project name is Foo Bar Raz, a key of FBR would make sense.
The key must contain only uppercase alphabetic characters, and be at least 2 characters in length.
It is recommended to use only ASCII characters, as other characters may not work."

Specified by:
getProjectKeyDescription in interface ProjectService
Returns:
a String description of the project key format

getProjectByIdForAction

public ProjectService.GetProjectResult getProjectByIdForAction(com.atlassian.crowd.embedded.api.User user,
                                                               Long id,
                                                               ProjectAction action)
Description copied from interface: ProjectService
Used to retrieve a Project object by id providing the user can perform the passed action on the project. This method returns a ProjectService.GetProjectResult. The project will be null if no project for the id specified can be found, or if the user making the request cannot perform the passed action on the project. In both of these cases, the errorCollection in the result object will contain an appropriate error message.

Specified by:
getProjectByIdForAction in interface ProjectService
Parameters:
user - The user retrieving the project.
id - The id of the project.
action - the action the user must be able to perform on the project.
Returns:
A ProjectResult object

getProjectById

public ProjectService.GetProjectResult getProjectById(com.atlassian.crowd.embedded.api.User user,
                                                      Long id)
Description copied from interface: ProjectService
Used to retrieve a Project object by id. This method returns a ProjectService.GetProjectResult. The project will be null if no project for the id specified can be found, or if the user making the request does not have the BROWSE project permission for the project. In both of these cases, the errorCollection in the result object will contain an appropriate error message.

Specified by:
getProjectById in interface ProjectService
Parameters:
user - The user retrieving the project.
id - The id of the project.
Returns:
A ProjectResult object

getProjectByKey

public ProjectService.GetProjectResult getProjectByKey(com.atlassian.crowd.embedded.api.User user,
                                                       String key)
Description copied from interface: ProjectService
Used to retrieve a Project object by key. This method returns a ProjectService.GetProjectResult. The project will be null if no project for the key specified can be found, or if the user making the request does not have the BROWSE project permission for the project. In both of these cases, the errorCollection in the result object will contain an appropriate error message.

Specified by:
getProjectByKey in interface ProjectService
Parameters:
user - The user retrieving the project.
key - The key of the project.
Returns:
A GetProjectResult object

getProjectByKeyForAction

public ProjectService.GetProjectResult getProjectByKeyForAction(com.atlassian.crowd.embedded.api.User user,
                                                                String key,
                                                                ProjectAction action)
Description copied from interface: ProjectService
Used to retrieve a Project object by key providing the user can perform the passed action on the project. This method returns a ProjectService.GetProjectResult. The project will be null if no project for the key specified can be found, or if the user making the request cannot perform the passed action on the project. In both of these cases, the errorCollection in the result object will contain an appropriate error message.

Specified by:
getProjectByKeyForAction in interface ProjectService
Parameters:
user - The user retrieving the project.
key - The key of the project.
action - the action the user must be able to perform on the project.
Returns:
A GetProjectResult object

getAllProjects

public ServiceOutcome<List<Project>> getAllProjects(com.atlassian.crowd.embedded.api.User user)
Description copied from interface: ProjectService
Used to retrieve a list of Project objects. This method returns a ServiceOutcome containing a list of projects. The list will be empty, if the user does not have the BROWSE project permission for any project or no projects are visible when using anonymous access.

Specified by:
getAllProjects in interface ProjectService
Parameters:
user - The user retrieving the list of projects or NULL when using anonymous access.
Returns:
A ServiceOutcome containing a list of projects

getAllProjectsForAction

public ServiceOutcome<List<Project>> getAllProjectsForAction(com.atlassian.crowd.embedded.api.User user,
                                                             ProjectAction action)
Description copied from interface: ProjectService
Used to retrieve a list of Project objects. This method returns a ServiceOutcome containing a list of projects that the user can perform the passed action on. The list will be empty if no projects match the passed action.

Specified by:
getAllProjectsForAction in interface ProjectService
Parameters:
user - The user retrieving the list of projects or NULL when using anonymous access.
action - the action the user must be able to perform on the returned projects.
Returns:
A ServiceOutcome containing a list of projects the user can perform the passed action on.

validateDeleteProject

public ProjectService.DeleteProjectValidationResult validateDeleteProject(com.atlassian.crowd.embedded.api.User user,
                                                                          String key)
Description copied from interface: ProjectService
Validation to delete a project is quite straightforward. The user must have global admin rights and the project about to be deleted needs to exist.

Specified by:
validateDeleteProject in interface ProjectService
Parameters:
user - The user trying to delete a project
key - The key of the project to delete
Returns:
A validation result containing any errors and all project details

deleteProject

public ProjectService.DeleteProjectResult deleteProject(com.atlassian.crowd.embedded.api.User user,
                                                        ProjectService.DeleteProjectValidationResult result)
Description copied from interface: ProjectService
Deletes the project provided by the deleteProjectValidationResult. There's a number of steps involved in deleting a project, which are carried out in the following order:
  • Delete all the issues in the project
  • Remove any custom field associations for the project
  • Remove the IssueTypeScreenSchemeAssocation for the project
  • Remove any other associations of this project (to permission schemes, notification schemes...)
  • Remove any versions in this project
  • Remove any components in this project
  • Delete all portlets that rely on this project (either directly or via filters)
  • Delete all the filters for this project
  • Delete the project itself in the database
  • Flushing the issue, project and workflow scheme caches

Specified by:
deleteProject in interface ProjectService
Parameters:
user - The user trying to delete a project
result - Result from the validation, which also contains all the project's details.
Returns:
A result containing any errors. Users of this method should check the result.

getI18nBean

protected final I18nHelper getI18nBean(com.atlassian.crowd.embedded.api.User user)

makeErrorCollection

protected final ErrorCollection makeErrorCollection(com.atlassian.crowd.embedded.api.User user,
                                                    String i18nKey,
                                                    ErrorCollection.Reason reason,
                                                    String... params)
Creates a new ErrorCollection instance for a single error message. If the reason "forbidden" and the user is null, this method adds an additional error message along the lines of "You are not logged in, please log in".

Parameters:
user - the User for whom the message will be i18n'ed
i18nKey - a String containing an i18n key
reason - a Reason code
params - a String array containing the i18n params @return a new ErrorCollection
Returns:
a new ErrorCollection


Copyright © 2002-2012 Atlassian. All Rights Reserved.