public class DefaultCommentService extends Object implements CommentService
CommentService.CommentCreateValidationResult, CommentService.CommentParameters, CommentService.CommentUpdateValidationResult, CommentService.CommentVisibility| Modifier and Type | Field and Description |
|---|---|
static String |
ERROR_BODY_TOOLONG |
static String |
ERROR_COMMENT_DELETE_NO_PERMISSION |
static String |
ERROR_COMMENT_DELETE_NON_EDITABLE_ISSUE |
static String |
ERROR_COMMENT_EDIT_NON_EDITABLE_ISSUE |
static String |
ERROR_NULL_COMMENT |
static String |
ERROR_NULL_COMMENT_DELETE |
static String |
ERROR_NULL_COMMENT_ID |
static String |
ERROR_NULL_COMMENT_ID_DELETE |
| Constructor and Description |
|---|
DefaultCommentService(CommentManager commentManager,
PermissionManager permissionManager,
JiraAuthenticationContext jiraAuthenticationContext,
CommentPermissionManager commentPermissionManager,
IssueManager issueManager,
VisibilityValidator visibilityValidator,
TextFieldCharacterLengthValidator textFieldCharacterLengthValidator) |
| Modifier and Type | Method and Description |
|---|---|
Comment |
create(ApplicationUser applicationUser,
CommentService.CommentCreateValidationResult validationResult,
boolean dispatchEvent)
|
Comment |
create(ApplicationUser user,
Issue issue,
String body,
boolean dispatchEvent,
ErrorCollection errorCollection)
|
Comment |
create(ApplicationUser user,
Issue issue,
String body,
String groupLevel,
Long roleLevelId,
boolean dispatchEvent,
ErrorCollection errorCollection)
|
Comment |
create(ApplicationUser user,
Issue issue,
String body,
String groupLevel,
Long roleLevelId,
Date created,
boolean dispatchEvent,
ErrorCollection errorCollection)
|
void |
delete(JiraServiceContext jiraServiceContext,
Comment comment,
boolean dispatchEvent)
Deletes a comment and updates the issue's change history and updated date.
|
Comment |
getCommentById(ApplicationUser user,
Long commentId,
ErrorCollection errorCollection)
Will return a comment for the passed in commentId.
|
List<Comment> |
getCommentsForUser(ApplicationUser user,
Issue issue)
|
List<Comment> |
getCommentsForUser(ApplicationUser currentUser,
Issue issue,
ErrorCollection errorCollection)
Will return a list of
Comments for the given user. |
List<Comment> |
getCommentsForUserSince(ApplicationUser currentUser,
Issue issue,
Date since)
Will return a list of
Comments that were created or updated since the provided date, for the given user. |
MutableComment |
getMutableComment(ApplicationUser user,
Long commentId,
ErrorCollection errorCollection)
Will return a
MutableComment for the passed in commentId. |
boolean |
hasPermissionToCreate(ApplicationUser user,
Issue issue,
ErrorCollection errorCollection)
Check if the given user has permission to create a comment in the current state of the issue.
|
boolean |
hasPermissionToCreate(ApplicationUser user,
Issue issue,
ErrorCollection errorCollection,
com.opensymphony.workflow.loader.ActionDescriptor actionDescriptor)
Check if the given user has permission to create a comment during a workflow transition for a given action description.
|
boolean |
hasPermissionToCreate(ApplicationUser user,
Issue issue,
ErrorCollection errorCollection,
Optional<Status> status)
Check if the given user has permission to create a comment in the current state of the issue or if the issue was in the given status.
|
boolean |
hasPermissionToDelete(JiraServiceContext jiraServiceContext,
Long commentId)
Determines whether the user can delete a comment.
|
boolean |
hasPermissionToEdit(ApplicationUser user,
Comment comment,
ErrorCollection errorCollection)
Determine whether the current user has the permission to edit the
comment.
|
boolean |
hasPermissionToEdit(JiraServiceContext jiraServiceContext,
Long commentId)
Determines whether the user can edit a comment.
|
protected boolean |
hasVisibility(JiraServiceContext jiraServiceContext,
Comment comment) |
boolean |
isGroupVisibilityEnabled()
Returns the flag that indicates whether group visiblity is enabled
|
boolean |
isGroupVisiblityEnabled()
Returns the flag that indicates whether group visiblity is enabled
|
boolean |
isProjectRoleVisibilityEnabled()
Returns the flag that indicates whether project role visibility is enabled
|
boolean |
isProjectRoleVisiblityEnabled()
Returns the flag that indicates whether project role visibility is enabled
|
boolean |
isValidAllCommentData(ApplicationUser currentUser,
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 |
isValidAllCommentData(ApplicationUser currentUser,
Issue issue,
String body,
Visibility visibility,
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(ApplicationUser currentUser,
Issue issue,
String groupLevel,
String roleLevelId,
ErrorCollection errorCollection)
This method validates if the comment has the correct role and group
levels set.
|
boolean |
isValidCommentVisibility(ApplicationUser currentUser,
Issue issue,
Visibility visibility,
ErrorCollection errorCollection)
This method validates if the comment has the correct role and group
levels set.
|
void |
update(ApplicationUser user,
CommentService.CommentUpdateValidationResult validationResult,
boolean dispatchEvent)
Updates a
Comment and sets the comments updated date to be now and the updatedAuthor to be the
passed in user. |
void |
update(ApplicationUser 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. |
CommentService.CommentCreateValidationResult |
validateCommentCreate(ApplicationUser user,
CommentService.CommentParameters commentParameters)
Confirms the parameters to create a comment are valid and that the user has the permission to do so.
|
CommentService.CommentCreateValidationResult |
validateCommentCreate(ApplicationUser user,
CommentService.CommentParameters commentParameters,
Optional<Status> status)
Confirms the parameters to create a comment are valid and that the user has the permission to do so if the issue was in the given status.
|
CommentService.CommentUpdateValidationResult |
validateCommentUpdate(ApplicationUser user,
Long commentId,
CommentService.CommentParameters commentParameters)
Confirms the parameters to update a comment are valid and that the updating user has the permission to do so.
|
void |
validateCommentUpdate(ApplicationUser 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 static final String ERROR_NULL_COMMENT_ID
public static final String ERROR_NULL_COMMENT
public static final String ERROR_NULL_COMMENT_DELETE
public static final String ERROR_NULL_COMMENT_ID_DELETE
public static final String ERROR_COMMENT_EDIT_NON_EDITABLE_ISSUE
public static final String ERROR_COMMENT_DELETE_NON_EDITABLE_ISSUE
public static final String ERROR_COMMENT_DELETE_NO_PERMISSION
public static final String ERROR_BODY_TOOLONG
public DefaultCommentService(CommentManager commentManager, PermissionManager permissionManager, JiraAuthenticationContext jiraAuthenticationContext, CommentPermissionManager commentPermissionManager, IssueManager issueManager, VisibilityValidator visibilityValidator, TextFieldCharacterLengthValidator textFieldCharacterLengthValidator)
public void validateCommentUpdate(ApplicationUser user, Long commentId, String body, String groupLevel, Long roleLevelId, ErrorCollection errorCollection)
CommentServiceCommentService.update(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.comments.MutableComment, boolean, com.atlassian.jira.util.ErrorCollection) to persist the changes. If an error is encountered
then the ErrorCollection will contain the specific error message.validateCommentUpdate in interface CommentServiceuser - The ApplicationUser 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 ensure 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 commentpublic CommentService.CommentUpdateValidationResult validateCommentUpdate(ApplicationUser user, Long commentId, CommentService.CommentParameters commentParameters)
CommentServiceCommentService.update(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.comments.MutableComment, boolean, com.atlassian.jira.util.ErrorCollection) to persist the changes. If an error is encountered
then the ErrorCollection will contain the specific error message.validateCommentUpdate in interface CommentServiceuser - The ApplicationUser 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 ensure that the user
has the right to update this comment. If the comment does not exist an error will be reported.commentParameters - the comment parameters.public void update(ApplicationUser user, MutableComment comment, boolean dispatchEvent, ErrorCollection errorCollection)
CommentServiceComment and sets the comments updated date to be now and the updatedAuthor to be the
passed in user.update in interface CommentServiceuser - the User who must have permission to update this comment and who will be used as the updateAuthorcomment - 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 commentpublic void update(ApplicationUser user, CommentService.CommentUpdateValidationResult validationResult, boolean dispatchEvent)
CommentServiceComment and sets the comments updated date to be now and the updatedAuthor to be the
passed in user.update in interface CommentServiceuser - the ApplicationUser who must have permission to update this comment and who will be used as the updateAuthorvalidationResult - the comment parameters.dispatchEvent - whether or not you want to have an event dispatched on Comment update. If false then
the issue will not be reindexed.public CommentService.CommentCreateValidationResult validateCommentCreate(ApplicationUser user, @Nonnull CommentService.CommentParameters commentParameters)
CommentServiceCommentService.create(ApplicationUser, CommentCreateValidationResult, boolean)
to persist the changes.
If an error is encountered then the CommentService.CommentCreateValidationResult will contain the specific error message.
validateCommentCreate in interface CommentServiceuser - The ApplicationUser who will be performing the operation.commentParameters - the comment parameters.public CommentService.CommentCreateValidationResult validateCommentCreate(ApplicationUser user, @Nonnull CommentService.CommentParameters commentParameters, Optional<Status> status)
CommentServiceCommentService.create(ApplicationUser, CommentCreateValidationResult, boolean)
to persist the changes.
If an error is encountered then the CommentService.CommentCreateValidationResult will contain the specific error message.
validateCommentCreate in interface CommentServiceuser - The ApplicationUser who will be performing the operation.commentParameters - the comment parameters.status - The given status to be validated against.public Comment create(ApplicationUser user, Issue issue, String body, boolean dispatchEvent, ErrorCollection errorCollection)
CommentServiceComment on the given Issue set with current date and time, visible to all
- no group level or role level restriction.create in interface CommentServiceuser - The User who will be performing the operation.issue - The Issue you wish to associate the Comment with. This can not be nullbody - The body of the commentdispatchEvent - whether or not you want to have an event dispatched on Comment creationerrorCollection - holder for any errors that were thrown attempting to create a commentpublic Comment create(ApplicationUser user, Issue issue, String body, String groupLevel, Long roleLevelId, boolean dispatchEvent, ErrorCollection errorCollection)
CommentServicecreate in interface CommentServiceuser - The User who will be performing the operation.issue - The Issue you wish to associate the Comment with. This can not be nullbody - The body of the commentgroupLevel - 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 creationerrorCollection - holder for any errors that were thrown attempting to create a commentpublic Comment create(ApplicationUser user, Issue issue, String body, String groupLevel, Long roleLevelId, Date created, boolean dispatchEvent, ErrorCollection errorCollection)
CommentServicecreate in interface CommentServiceuser - The User who will be performing the operation.issue - The Issue you wish to associate the Comment with. This can not be nullbody - The body of the commentgroupLevel - 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 creationdispatchEvent - whether or not you want to have an event dispatched on Comment creationerrorCollection - holder for any errors that were thrown attempting to create a commentpublic Comment create(ApplicationUser applicationUser, CommentService.CommentCreateValidationResult validationResult, boolean dispatchEvent)
CommentServicecreate in interface CommentServiceapplicationUser - The ApplicationUser who will be performing the operation.validationResult - the results of CommentService.validateCommentCreate(ApplicationUser, com.atlassian.jira.bc.issue.comment.CommentService.CommentParameters).dispatchEvent - whether or not you want to have an event dispatched on Comment creationpublic List<Comment> getCommentsForUser(ApplicationUser currentUser, Issue issue, ErrorCollection errorCollection)
CommentServiceComments for the given user.getCommentsForUser in interface CommentServicecurrentUser - current Userissue - the issue with associated commentserrorCollection - holder for any errors that were thrown attempting to retrieve comments@Nonnull public List<Comment> getCommentsForUser(@Nullable ApplicationUser user, @Nonnull Issue issue)
CommentServiceComments for the given user
Will return a list of Comments for the given user.getCommentsForUser in interface CommentServiceuser - the user to check permissions against ApplicationUser, or anonymous if null.issue - the issue with associated comments. Must not be null.@Nonnull public List<Comment> getCommentsForUserSince(@Nullable ApplicationUser currentUser, @Nonnull Issue issue, @Nonnull Date since)
CommentServiceComments that were created or updated since the provided date, for the given user.getCommentsForUserSince in interface CommentServicecurrentUser - the user to check permissions against ApplicationUser, or anonymous if null.issue - the issue with associated comments. Must not be null.since - only comments created or updated after this date will be returned. Must not be null.public boolean isValidCommentData(ApplicationUser currentUser, Issue issue, String groupLevel, String roleLevelId, ErrorCollection errorCollection)
CommentServiceerrorCollection will contain the errors.isValidCommentData in interface CommentServicecurrentUser - The User who will be performing the operation.issue - issue to associate the comment withgroupLevel - comment group visibility levelroleLevelId - comment project role visibility level iderrorCollection - holder for any errors that can occur in process of validationpublic boolean isValidCommentVisibility(ApplicationUser currentUser, Issue issue, Visibility visibility, ErrorCollection errorCollection)
CommentServiceerrorCollection will contain the errors.isValidCommentVisibility in interface CommentServicecurrentUser - The User who will be performing the operation.issue - issue to associate the comment withvisibility - comment visibility levelerrorCollection - holder for any errors that can occur in process of validationpublic boolean isValidCommentBody(String body, ErrorCollection errorCollection)
CommentServiceerrorCollection. This method was added so
the CommentSystemField can validate the body and set the appropriate error message.isValidCommentBody in interface CommentServicebody - comment body to validateerrorCollection - holder for any errors that can occur in process of validationpublic boolean isValidCommentBody(String body, ErrorCollection errorCollection, boolean allowEmpty)
CommentServiceerrorCollection. This method was added so
the CommentSystemField can validate the body and set the appropriate error message.isValidCommentBody in interface CommentServicebody - comment body to validateerrorCollection - holder for any errors that can occur in process of validationallowEmpty - indicates whether empty body is allowedpublic boolean isValidAllCommentData(ApplicationUser currentUser, Issue issue, String body, String groupLevel, String roleLevelId, ErrorCollection errorCollection)
CommentServiceerrorCollection if any errors occur.isValidAllCommentData in interface CommentServicecurrentUser - The User who will be performing the operation.issue - issue to associate the comment withbody - comment bodygroupLevel - comment group visibility levelroleLevelId - comment project role visibility level iderrorCollection - holder for any errors that can occur in process of validarionpublic boolean isValidAllCommentData(ApplicationUser currentUser, Issue issue, String body, Visibility visibility, ErrorCollection errorCollection)
CommentServiceerrorCollection if any errors occur.isValidAllCommentData in interface CommentServicecurrentUser - The User who will be performing the operation.issue - issue to associate the comment withbody - comment bodyvisibility - visibility levelerrorCollection - holder for any errors that can occur in process of validarionpublic boolean isGroupVisiblityEnabled()
CommentServiceisGroupVisiblityEnabled in interface CommentServicepublic boolean isProjectRoleVisiblityEnabled()
CommentServiceisProjectRoleVisiblityEnabled in interface CommentServicepublic boolean isGroupVisibilityEnabled()
CommentServiceisGroupVisibilityEnabled in interface CommentServicepublic boolean isProjectRoleVisibilityEnabled()
CommentServiceisProjectRoleVisibilityEnabled in interface CommentServicepublic Comment getCommentById(ApplicationUser user, Long commentId, ErrorCollection errorCollection)
CommentServicegetCommentById in interface CommentServiceuser - who is looking up the commentcommentId - the id representing the Comment you would like to retrieve.errorCollection - holder for any errors that can occur in process of validationComment or null (if the user cannot browse the comment).public MutableComment getMutableComment(ApplicationUser user, Long commentId, ErrorCollection errorCollection)
CommentServiceMutableComment 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 CommentService.getCommentById(com.atlassian.jira.user.ApplicationUser, java.lang.Long, com.atlassian.jira.util.ErrorCollection) is that this
method returns a version of the Comment that we can set values on.getMutableComment in interface CommentServiceuser - 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 validationpublic boolean hasPermissionToDelete(JiraServiceContext jiraServiceContext, Long commentId)
CommentServicehasPermissionToDelete in interface CommentServicejiraServiceContext - jiraServiceContext containing the user who wishes to delete a comment and the
errorCollection that will contain any errors encountered when calling the methodcommentId - the id of the target comment (cannot be null)protected boolean hasVisibility(JiraServiceContext jiraServiceContext, Comment comment)
public void delete(JiraServiceContext jiraServiceContext, Comment comment, boolean dispatchEvent)
CommentServiceCommentService.hasPermissionToDelete(com.atlassian.jira.bc.JiraServiceContext, Long) is successfully called first.delete in interface CommentServicejiraServiceContext - containing the user who wishes to delete a comment and the errorCollection
that will contain any errors encountered when calling the methodcomment - 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 boolean hasPermissionToCreate(ApplicationUser user, Issue issue, ErrorCollection errorCollection)
CommentServicehasPermissionToCreate in interface CommentServiceuser - The ApplicationUser who will be performing the operation.issue - The issue with associated comments.errorCollection - Holder for any errors that were thrown attempting permission checks.public boolean hasPermissionToCreate(ApplicationUser user, Issue issue, ErrorCollection errorCollection, Optional<Status> status)
CommentService
If the state is Optional.none, we use the status in the issue param - the same as calling
CommentService.hasPermissionToCreate(ApplicationUser, Issue, ErrorCollection).
hasPermissionToCreate in interface CommentServiceuser - The ApplicationUser who will be performing the operation.issue - The issue with associated comments.errorCollection - Holder for any errors that were thrown attempting permission checks.status - The status that should be used for the permission check. If Optional.none, will check using current status of the given issue.public boolean hasPermissionToCreate(ApplicationUser user, Issue issue, ErrorCollection errorCollection, com.opensymphony.workflow.loader.ActionDescriptor actionDescriptor)
CommentServicehasPermissionToCreate in interface CommentServiceuser - The ApplicationUser who will be performing the operation.issue - The issue with associated comments.errorCollection - Holder for any errors that were thrown attempting permission checks.actionDescriptor - The status that should be used for the permission check. If Optional.none, will check using current status of the given issue.public boolean hasPermissionToEdit(JiraServiceContext jiraServiceContext, Long commentId)
CommentServicehasPermissionToEdit in interface CommentServicejiraServiceContext - JIRA service context containing the user who wishes to edit a comment and the
errorCollection that will contain any errors encountered when calling the methodcommentId - the id of the target comment (cannot be null)public boolean hasPermissionToEdit(ApplicationUser user, Comment comment, ErrorCollection errorCollection)
CommentServicePassing 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.
hasPermissionToEdit in interface CommentServiceuser - 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 checksCopyright © 2002-2016 Atlassian. All Rights Reserved.