Class DefaultWatcherService
java.lang.Object
com.atlassian.jira.bc.issue.watcher.DefaultWatcherService
- All Implemented Interfaces:
WatcherService
Implementation of WatcherService.
- Since:
- v4.2
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.atlassian.jira.bc.issue.watcher.WatcherService
WatcherService.BulkWatchResult
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultWatcherService
(ApplicationProperties applicationProperties, I18nHelper.BeanFactory i18n, PermissionManager permissionManager, WatcherManager watcherManager, UserManager userManager) Creates a new DefaultWatcherService with the given dependencies. -
Method Summary
Modifier and TypeMethodDescriptionaddWatcher
(Issue issue, ApplicationUser remoteUser, ApplicationUser watcher) Adds a watcher to an issue's list of watchers, returning the updated list of watchers.addWatcherToAll
(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher) Adds a watcher to all of the supplied issues.addWatcherToAll
(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher, Context taskContext) Adds a watcher to all of the supplied issues.protected boolean
canEditWatcherList
(Issue issue, ApplicationUser remoteUser) Returns true iff the given User has permission to edit the watcher list of the issue.boolean
canUnwatchAll
(Iterable<Issue> issues, ApplicationUser remoteUser) Whether the specified user can unwatch all the specified issues.boolean
canWatchAll
(Iterable<Issue> issues, ApplicationUser applicationUser) Whether the specified user can watch all the specified issues.protected void
checkModifyWatchersPermission
(Issue issue, ApplicationUser remoteUser, ApplicationUser watcher) Ensures that the given remoteUser has permission to add or remove the given watcher to/from the issue.protected <T extends ApplicationUser>
Pair<Integer,List<T>> convertUsers
(Pair<Integer, List<String>> watchers, com.google.common.base.Function<String, T> function) Converts the usernames into User objects using the given function.protected List<ApplicationUser>
getCurrentWatchersFor
(Issue issue) Returns a List containing the users that are currently watching an issue.getWatchers
(Issue issue, ApplicationUser remoteUser) Returns a the total number of watchers for a given issue in the first element of the returned Pair, and the list of visible watchers in the second element of the Pair.getWatcherUsernames
(Issue issue, ApplicationUser remoteUser) Returns a pair containing the watcher count and the watcher usernames for a given issue.boolean
hasViewWatcherListPermission
(Issue issue, ApplicationUser remoteUser) Returns true iff the given User has permission to view the watcher list of the issue.boolean
Returns true iff watching is enabled.removeWatcher
(Issue issue, ApplicationUser remoteUser, ApplicationUser watcher) Removes a watcher from an issue's list of watchers, returning the updated list of watchers.removeWatcherFromAll
(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher) Removes a watcher from all of the supplied issues.removeWatcherFromAll
(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher, Context taskContext) Removes a watcher from all of the supplied issues.
-
Constructor Details
-
DefaultWatcherService
public DefaultWatcherService(ApplicationProperties applicationProperties, I18nHelper.BeanFactory i18n, PermissionManager permissionManager, WatcherManager watcherManager, UserManager userManager) Creates a new DefaultWatcherService with the given dependencies.- Parameters:
applicationProperties
- an ApplicationPropertiesi18n
- a I18nBeanpermissionManager
- a PermissionManagerwatcherManager
- a WatcherManageruserManager
- a UserManager
-
-
Method Details
-
getWatchers
public ServiceOutcome<Pair<Integer,List<ApplicationUser>>> getWatchers(Issue issue, @Nullable ApplicationUser remoteUser) throws WatchingDisabledException Description copied from interface:WatcherService
Returns a the total number of watchers for a given issue in the first element of the returned Pair, and the list of visible watchers in the second element of the Pair. Note that if the remote user does not have permission to view the list of watchers, it is possible for the number of elements in the returned user list to be less than the returned number of watchers.- Specified by:
getWatchers
in interfaceWatcherService
- Parameters:
issue
- the Issue to find watchers forremoteUser
- the calling User- Returns:
- a ServiceOutcome containing the total number of watchers, and a list of visible watchers
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
addWatcher
public ServiceOutcome<List<ApplicationUser>> addWatcher(Issue issue, ApplicationUser remoteUser, ApplicationUser watcher) throws WatchingDisabledException Description copied from interface:WatcherService
Adds a watcher to an issue's list of watchers, returning the updated list of watchers.- Specified by:
addWatcher
in interfaceWatcherService
- Parameters:
issue
- the issue to updateremoteUser
- the remote user on behalf of which the operation is performedwatcher
- the watcher to add- Returns:
- a ServiceOutcome containing a list of User
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
addWatcherToAll
public WatcherService.BulkWatchResult addWatcherToAll(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher) throws WatchingDisabledException Description copied from interface:WatcherService
Adds a watcher to all of the supplied issues.If there is partial success, the issues which we can modify will be modified and the ones we cannot will be returned in a BulkWatchResult.
- Specified by:
addWatcherToAll
in interfaceWatcherService
- Parameters:
issues
- the list of issues to updateremoteUser
- the remote user on behalf of which the operation is performedwatcher
- the watcher to add- Returns:
- a BulkWatchResult containing the issues that could not be modified
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
addWatcherToAll
public WatcherService.BulkWatchResult addWatcherToAll(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher, Context taskContext) throws WatchingDisabledException Description copied from interface:WatcherService
Adds a watcher to all of the supplied issues.If there is partial success, the issues which we can modify will be modified and the ones we cannot will be returned in a BulkWatchResult.
- Specified by:
addWatcherToAll
in interfaceWatcherService
- Parameters:
issues
- the list of issues to updateremoteUser
- the remote user on behalf of which the operation is performedwatcher
- the watcher to addtaskContext
- a context through which progress can be reported back- Returns:
- a BulkWatchResult containing the issues that could not be modified
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
removeWatcher
public ServiceOutcome<List<ApplicationUser>> removeWatcher(Issue issue, ApplicationUser remoteUser, ApplicationUser watcher) throws WatchingDisabledException Description copied from interface:WatcherService
Removes a watcher from an issue's list of watchers, returning the updated list of watchers.- Specified by:
removeWatcher
in interfaceWatcherService
- Parameters:
issue
- the Issue to updateremoteUser
- a User indicating the user on behalf of whom this operation is being performedwatcher
- a User representing the User to remove from the watcher list- Returns:
- a ServiceOutcome containing a list of User
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
removeWatcherFromAll
public WatcherService.BulkWatchResult removeWatcherFromAll(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher) throws WatchingDisabledException Description copied from interface:WatcherService
Removes a watcher from all of the supplied issues.If there is partial success, the issues which we can modify will be modified and the ones we cannot will be returned in a BulkWatchResult.
- Specified by:
removeWatcherFromAll
in interfaceWatcherService
- Parameters:
issues
- the list of Issues to updateremoteUser
- an ApplicationUser indicating the user on behalf of whom this operation is being performedwatcher
- an ApplicationUser representing the user to remove from the watcher list for each issue- Returns:
- a BulkWatchResult containing the issues that could not be modified
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
removeWatcherFromAll
public WatcherService.BulkWatchResult removeWatcherFromAll(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher, Context taskContext) throws WatchingDisabledException Description copied from interface:WatcherService
Removes a watcher from all of the supplied issues.If there is partial success, the issues which we can modify will be modified and the ones we cannot will be returned in a BulkWatchResult.
- Specified by:
removeWatcherFromAll
in interfaceWatcherService
- Parameters:
issues
- the list of Issues to updateremoteUser
- an ApplicationUser indicating the user on behalf of whom this operation is being performedwatcher
- an ApplicationUser representing the user to remove from the watcher list for each issuetaskContext
- a context through which progress can be reported back- Returns:
- a BulkWatchResult containing the issues that could not be modified
- Throws:
WatchingDisabledException
- if watching is currently disabled
-
canWatchAll
Description copied from interface:WatcherService
Whether the specified user can watch all the specified issues.- Specified by:
canWatchAll
in interfaceWatcherService
- Parameters:
issues
- The list of issues to checkapplicationUser
- The user to execute this check for- Returns:
- true; if the specified user can watch all the specified issues; otherwise, false is returned.
-
canUnwatchAll
Description copied from interface:WatcherService
Whether the specified user can unwatch all the specified issues.- Specified by:
canUnwatchAll
in interfaceWatcherService
- Parameters:
issues
- The list of issues to checkremoteUser
- The user to execute this check for- Returns:
- true; if the specified user can unwatch all the specified issues; otherwise, false is returned.
-
isWatchingEnabled
public boolean isWatchingEnabled()Returns true iff watching is enabled.- Specified by:
isWatchingEnabled
in interfaceWatcherService
- Returns:
- true iff watching is enabled
-
hasViewWatcherListPermission
Returns true iff the given User has permission to view the watcher list of the issue.- Specified by:
hasViewWatcherListPermission
in interfaceWatcherService
- Parameters:
issue
- an IssueremoteUser
- a User- Returns:
- a boolean indicating whether the user can view the watch list
-
getWatcherUsernames
protected Pair<Integer,List<String>> getWatcherUsernames(Issue issue, ApplicationUser remoteUser) throws WatchingDisabledException Returns a pair containing the watcher count and the watcher usernames for a given issue.- Parameters:
issue
- the IssueremoteUser
- the calling User- Returns:
- a Pair containing the watcher count and the watcher usernames for a given issue
- Throws:
WatchingDisabledException
- if watching is disabled
-
getCurrentWatchersFor
Returns a List containing the users that are currently watching an issue.- Parameters:
issue
- the Issue to get the watcher list for- Returns:
- a List of users that are watching the issue
-
canEditWatcherList
Returns true iff the given User has permission to edit the watcher list of the issue.- Parameters:
issue
- an IssueremoteUser
- a User- Returns:
- a boolean indicating whether the user can edit the watch list
-
convertUsers
protected <T extends ApplicationUser> Pair<Integer,List<T>> convertUsers(Pair<Integer, List<String>> watchers, com.google.common.base.Function<String, T> function) Converts the usernames into User objects using the given function.- Parameters:
watchers
- a Pair of watcher count and watcher usernamesfunction
- a Function used for conversion- Returns:
- a Pair of watcher count and User object
-
checkModifyWatchersPermission
protected void checkModifyWatchersPermission(Issue issue, ApplicationUser remoteUser, ApplicationUser watcher) throws com.atlassian.jira.bc.issue.watcher.DefaultWatcherService.PermissionException, WatchingDisabledException Ensures that the given remoteUser has permission to add or remove the given watcher to/from the issue. Throws an exception if the user does not have permission.- Parameters:
issue
- an IssueremoteUser
- a User representing the callerwatcher
- a User representing the watcher to add or remove- Throws:
com.atlassian.jira.bc.issue.watcher.DefaultWatcherService.PermissionException
- if the caller does not have permission to manage watchers, or cannot see the issueWatchingDisabledException
- if watching is disabled
-