@PublicApi public interface

CommentService

com.atlassian.jira.bc.issue.comment.CommentService
Known Indirect Subclasses

@PublicApi

This interface is designed for plugins to consume (call its methods).

Clients of @PublicApi can expect that programs compiled against a given version will remain binary compatible with later versions of the @PublicApi as per each product's API policy as long as the client does not implement/extend @PublicApi interfaces or classes (refer to each product's API policy for the exact guarantee---usually binary compatibility is guaranteed at least across minor versions).

Note: since @PublicApi interfaces and classes are not designed to be implemented or extended by clients, we may perform certain types of binary-incompatible changes to these classes and interfaces, but these will not affect well-behaved clients that do not extend/implement these types (in general, only classes and interfaces annotated with @PublicSpi are safe to extend/implement).

Class Overview

This is the business layer component that must be used to access all Comment functionality. This will perform validation before it hands off to the CommentManager. Operations will not be performed if validation fails.

Summary

Public Methods
Comment create(User user, Issue issue, String body, String groupLevel, Long roleLevelId, boolean dispatchEvent, ErrorCollection errorCollection)
Creates and persists a Comment on the given Issue set with current date and time.
Comment create(User user, Issue issue, String body, boolean dispatchEvent, ErrorCollection errorCollection)
Creates and persists a Comment on the given Issue set with current date and time, visible to all - no group level or role level restriction.
Comment create(User user, Issue issue, String body, String groupLevel, Long roleLevelId, Date created, boolean dispatchEvent, ErrorCollection errorCollection)
Creates and persists a Comment on the given Issue.
void delete(JiraServiceContext jiraServiceContext, Comment comment, boolean dispatchEvent)
Deletes a comment and updates the issue's change history and updated date.
Comment getCommentById(User user, Long commentId, ErrorCollection errorCollection)
Will return a comment for the passed in commentId.
List<Comment> getCommentsForUser(User currentUser, Issue issue, ErrorCollection errorCollection)
Will return a list of Comments for the given user
MutableComment getMutableComment(User user, Long commentId, ErrorCollection errorCollection)
Will return a MutableComment for the passed in commentId.
boolean hasPermissionToCreate(User user, Issue issue, ErrorCollection errorCollection)
Has the correct permission to create a comment for the given issue.
boolean hasPermissionToDelete(JiraServiceContext jiraServiceContext, Long commentId)
Determines whether the user can delete a comment.
boolean hasPermissionToEdit(JiraServiceContext jiraServiceContext, Long commentId)
Determines whether the user can edit a comment.
boolean hasPermissionToEdit(User user, Comment comment, ErrorCollection errorCollection)
Determine whether the current user has the permission to edit the comment.
boolean isGroupVisiblityEnabled()
Returns the flag that indicates whether group visiblity is enabled
boolean isProjectRoleVisiblityEnabled()
Returns the flag that indicates whether project role visibility is enabled
boolean isValidAllCommentData(User user, Issue issue, String body, String groupLevel, String roleLevelId, ErrorCollection errorCollection)
Will call all other validate methods setting the appropriate errors in the errorCollection if any errors occur.
boolean isValidCommentBody(String body, ErrorCollection errorCollection)
Validates that the body is a valid string, if not the appropriate error is added to the errorCollection.
boolean isValidCommentBody(String body, ErrorCollection errorCollection, boolean allowEmpty)
Validates that the body is a valid string, if not the appropriate error is added to the errorCollection.
boolean isValidCommentData(User user, Issue issue, String groupLevel, String roleLevelId, ErrorCollection errorCollection)
This method validates if the comment has the correct role and group levels set.
void update(User user, MutableComment comment, boolean dispatchEvent, ErrorCollection errorCollection)
Updates a Comment and sets the comments updated date to be now and the updatedAuthor to be the passed in user.
void validateCommentUpdate(User user, Long commentId, String body, String groupLevel, Long roleLevelId, ErrorCollection errorCollection)
Confirms the parameters to update a comment are valid and that the updating user has the permission to do so.

Public Methods

public Comment create (User user, Issue issue, String body, String groupLevel, Long roleLevelId, boolean dispatchEvent, ErrorCollection errorCollection)

Creates and persists a Comment on the given Issue set with current date and time.

Parameters
user The User who will be performing the operation.
issue The Issue you wish to associate the Comment with. This can not be null
body The body of the comment
groupLevel The group level visibility of the comment (null if roleLevelId specified)
roleLevelId The role level visibility id of the comment (null if groupLevel specified)
dispatchEvent whether or not you want to have an event dispatched on Comment creation
errorCollection holder for any errors that were thrown attempting to create a comment
Returns
  • the created Comment object, or null if no object created.

public Comment create (User user, Issue issue, String body, boolean dispatchEvent, ErrorCollection errorCollection)

Creates and persists a Comment on the given Issue set with current date and time, visible to all - no group level or role level restriction.

Parameters
user The User who will be performing the operation.
issue The Issue you wish to associate the Comment with. This can not be null
body The body of the comment
dispatchEvent whether or not you want to have an event dispatched on Comment creation
errorCollection holder for any errors that were thrown attempting to create a comment
Returns
  • the created Comment object, or null if no object created.

public Comment create (User user, Issue issue, String body, String groupLevel, Long roleLevelId, Date created, boolean dispatchEvent, ErrorCollection errorCollection)

Creates and persists a Comment on the given Issue.

Parameters
user The User who will be performing the operation.
issue The Issue you wish to associate the Comment with. This can not be null
body The body of the comment
groupLevel The group level visibility of the comment (null if roleLevelId specified)
roleLevelId The role level visibility id of the comment (null if groupLevel specified)
created The date of comment creation
dispatchEvent whether or not you want to have an event dispatched on Comment creation
errorCollection holder for any errors that were thrown attempting to create a comment
Returns
  • the created Comment object, or null if no object created.

public void delete (JiraServiceContext jiraServiceContext, Comment comment, boolean dispatchEvent)

Deletes a comment and updates the issue's change history and updated date. Expects that hasPermissionToDelete(com.atlassian.jira.bc.JiraServiceContext, Long) is successfully called first.

Parameters
jiraServiceContext containing the user who wishes to delete a comment and the errorCollection that will contain any errors encountered when calling the method
comment the comment to delete (cannot be null)
dispatchEvent a flag indicating whether to dispatch an issue updated event. If this flag is false then the issue will not be reindexed.

public Comment getCommentById (User user, Long commentId, ErrorCollection errorCollection)

Will return a comment for the passed in commentId. This will return null if the user does not have permission to view the comment

Parameters
user who is looking up the comment
commentId the id representing the Comment you would like to retrieve.
errorCollection holder for any errors that can occur in process of validation
Returns
  • a Comment or null (if the user cannot browse the comment).

public List<Comment> getCommentsForUser (User currentUser, Issue issue, ErrorCollection errorCollection)

Will return a list of Comments for the given user

Parameters
currentUser current user
issue the issue with associated comments
errorCollection holder for any errors that were thrown attempting to update a comment
Returns
  • a List of comments

public MutableComment getMutableComment (User user, Long commentId, ErrorCollection errorCollection)

Will return a MutableComment for the passed in commentId. This will return null if the user does not have permission to view the comment. The difference between this method and getCommentById(User, Long, ErrorCollection) is that this method returns a version of the Comment that we can set values on.

Parameters
user the current user.
commentId the id that we use to find the comment object.
errorCollection holder for any errors that can occur in process of validation
Returns
  • the comment that is identified by the commentId.

public boolean hasPermissionToCreate (User user, Issue issue, ErrorCollection errorCollection)

Has the correct permission to create a comment for the given issue.

Parameters
user The User who will be performing the operation.
issue The Issue you wish to associate the Comment with. This can not be null.
errorCollection holder for any errors that were thrown attempting permission checks
Returns
  • true if permission check passes.

public boolean hasPermissionToDelete (JiraServiceContext jiraServiceContext, Long commentId)

Determines whether the user can delete a comment. Will return true when the following are satisfied:

  • The user has the DELETE_COMMENT_ALL permission, or the user has the DELETE_COMMENT_OWN permission and is attempting to delete a comment they authored
  • The issue is in an editable workflow state

Parameters
jiraServiceContext jiraServiceContext containing the user who wishes to delete a comment and the errorCollection that will contain any errors encountered when calling the method
commentId the id of the target comment (cannot be null)
Returns
  • true if the user has permission to delete the target comment, false otherwise

public boolean hasPermissionToEdit (JiraServiceContext jiraServiceContext, Long commentId)

Determines whether the user can edit a comment. Will return true when the following are satisfied:

  • The user has the comment edit all or comment edit own permission
  • The issue is in an editable workflow state

Parameters
jiraServiceContext JIRA service context containing the user who wishes to edit a comment and the errorCollection that will contain any errors encountered when calling the method
commentId the id of the target comment (cannot be null)
Returns
  • true if the user has permission to edit the comment, false otherwise

public boolean hasPermissionToEdit (User user, Comment comment, ErrorCollection errorCollection)

Determine whether the current user has the permission to edit the comment. In case of errors, add error messages to the error collection.

Passing in null comment or a comment with null ID will return false and an error message will be added to the error collection.

Passing in null error collection will throw NPE.

Parameters
user The User who will be performing the operation.
comment The Comment you wish to edit.
errorCollection holder for any errors that were thrown attempting permission checks
Returns
  • true if the user has edit permission, false otherwise

public boolean isGroupVisiblityEnabled ()

Returns the flag that indicates whether group visiblity is enabled

Returns
  • true if enabled, false otherwise

public boolean isProjectRoleVisiblityEnabled ()

Returns the flag that indicates whether project role visibility is enabled

Returns
  • true if enabled, false otherwise

public boolean isValidAllCommentData (User user, Issue issue, String body, String groupLevel, String roleLevelId, ErrorCollection errorCollection)

Will call all other validate methods setting the appropriate errors in the errorCollection if any errors occur.

Parameters
user The User who will be performing the operation.
issue issue to associate the comment with
body comment body
groupLevel comment group visibility level
roleLevelId comment project role visibility level id
errorCollection holder for any errors that can occur in process of validarion
Returns
  • true if validation passes

public boolean isValidCommentBody (String body, ErrorCollection errorCollection)

Validates that the body is a valid string, if not the appropriate error is added to the errorCollection. This method was added so the CommentSystemField can validate the body and set the appropriate error message.

Parameters
body comment body to validate
errorCollection holder for any errors that can occur in process of validation
Returns
  • true is the body is valid.

public boolean isValidCommentBody (String body, ErrorCollection errorCollection, boolean allowEmpty)

Validates that the body is a valid string, if not the appropriate error is added to the errorCollection. This method was added so the CommentSystemField can validate the body and set the appropriate error message.

Parameters
body comment body to validate
errorCollection holder for any errors that can occur in process of validation
allowEmpty indicates whether empty body is allowed
Returns
  • true is the body is valid.

public boolean isValidCommentData (User user, Issue issue, String groupLevel, String roleLevelId, ErrorCollection errorCollection)

This method validates if the comment has the correct role and group levels set. If there is an error during validation the passed in errorCollection will contain the errors.

Parameters
user The User who will be performing the operation.
issue issue to associate the comment with
groupLevel comment group visibility level
roleLevelId comment project role visibility level id
errorCollection holder for any errors that can occur in process of validation
Returns
  • true if the role and group level information has been set correctly for a comment

public void update (User user, MutableComment comment, boolean dispatchEvent, ErrorCollection errorCollection)

Updates a Comment and sets the comments updated date to be now and the updatedAuthor to be the passed in user.

Parameters
user the user who must have permission to update this comment and who will be used as the updateAuthor
comment the object that contains the changes to the comment to persist.
dispatchEvent whether or not you want to have an event dispatched on Comment update. If false then the issue will not be reindexed.
errorCollection holder for any errors that were thrown attempting to update a comment
Throws
IllegalArgumentException if comment or its id is null

public void validateCommentUpdate (User user, Long commentId, String body, String groupLevel, Long roleLevelId, ErrorCollection errorCollection)

Confirms the parameters to update a comment are valid and that the updating user has the permission to do so. This method will validate the raw input parameters. This method only validates the parameters and will not actually persist the changes, you must call update(User, MutableComment, boolean, ErrorCollection) to persist the changes. If an error is encountered then the ErrorCollection will contain the specific error message.

Parameters
user The User who will be performing the operation and who will be the updatedAuthor.
commentId The id of the comment to be updated. Permissions will be checked to insure that the user has the right to update this comment. If the comment does not exist an error will be reported.
body The body of the comment to be updated.
groupLevel The group level visibility of the comment (null if roleLevelId specified)
roleLevelId The role level visibility id of the comment (null if groupLevel specified)
errorCollection holder for any errors that were thrown attempting to update a comment