public class

DefaultWatcherService

extends Object
implements WatcherService
java.lang.Object
   ↳ com.atlassian.jira.bc.issue.watcher.DefaultWatcherService

Class Overview

Implementation of WatcherService.

Summary

Public Constructors
DefaultWatcherService(ApplicationProperties applicationProperties, I18nHelper.BeanFactory i18n, PermissionManager permissionManager, WatcherManager watcherManager, UserManager userManager)
Creates a new DefaultWatcherService with the given dependencies.
Public Methods
ServiceOutcome<List<User>> addWatcher(Issue issue, User remoteUser, User watcher)
Adds a watcher to an issue's list of watchers, returning the updated list of watchers.
WatcherService.BulkWatchResult addWatcherToAll(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher)
Adds a watcher to all of the supplied issues.
@Deprecated boolean canUnwatchAll(Iterable<Issue> issues, User remoteUser)
Whether the specified user can unwatch all the specified issues.
boolean canUnwatchAll(Iterable<Issue> issues, ApplicationUser remoteUser)
Whether the specified user can unwatch all the specified issues.
@Deprecated boolean canWatchAll(Iterable<Issue> issues, User remoteUser)
Whether the specified user can watch all the specified issues.
boolean canWatchAll(Iterable<Issue> issues, ApplicationUser applicationUser)
Whether the specified user can watch all the specified issues.
ServiceOutcome<Pair<IntegerList<User>>> getWatchers(Issue issue, User 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.
boolean hasViewWatcherListPermission(Issue issue, User remoteUser)
Returns true iff the given User has permission to view the watcher list of the issue.
boolean isWatchingEnabled()
Returns true iff watching is enabled.
ServiceOutcome<List<User>> removeWatcher(Issue issue, User remoteUser, User watcher)
Removes a watcher from an issue's list of watchers, returning the updated list of watchers.
WatcherService.BulkWatchResult removeWatcherFromAll(Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher)
Removes a watcher from all of the supplied issues.
Protected Methods
boolean canEditWatcherList(Issue issue, User remoteUser)
Returns true iff the given User has permission to edit the watcher list of the issue.
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.
<T extends User> Pair<IntegerList<T>> convertUsers(Pair<IntegerList<String>> watchers, Function<String, T> function)
Converts the usernames into User objects using the given function.
List<User> getCurrentWatchersFor(Issue issue)
Returns a List containing the users that are currently watching an issue.
Pair<IntegerList<String>> getWatcherUsernames(Issue issue, User remoteUser)
Returns a pair containing the watcher count and the watcher usernames for a given issue.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.bc.issue.watcher.WatcherService

Public Constructors

public DefaultWatcherService (ApplicationProperties applicationProperties, I18nHelper.BeanFactory i18n, PermissionManager permissionManager, WatcherManager watcherManager, UserManager userManager)

Creates a new DefaultWatcherService with the given dependencies.

Parameters
applicationProperties an ApplicationProperties
i18n a I18nBean
permissionManager a PermissionManager
watcherManager a WatcherManager
userManager a UserManager

Public Methods

public ServiceOutcome<List<User>> addWatcher (Issue issue, User remoteUser, User watcher)

Adds a watcher to an issue's list of watchers, returning the updated list of watchers.

Parameters
issue the issue to update
remoteUser the remote user on behalf of which
watcher the watcher to add
Returns
  • a ServiceOutcome containing a list of User

public WatcherService.BulkWatchResult addWatcherToAll (Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher)

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.

Parameters
issues the list of issues to update
remoteUser the remote user on behalf of which
watcher the watcher to add
Returns
  • a BulkWatchResult containing the issues that could not be modified

@Deprecated public boolean canUnwatchAll (Iterable<Issue> issues, User remoteUser)

Whether the specified user can unwatch all the specified issues.

Parameters
issues The list of issues to check
remoteUser The user to execute this check for
Returns
  • true; if the specified user can unwatch all the specified issues; otherwise, false is returned.

public boolean canUnwatchAll (Iterable<Issue> issues, ApplicationUser remoteUser)

Whether the specified user can unwatch all the specified issues.

Parameters
issues The list of issues to check
remoteUser The user to execute this check for
Returns
  • true; if the specified user can unwatch all the specified issues; otherwise, false is returned.

@Deprecated public boolean canWatchAll (Iterable<Issue> issues, User remoteUser)

Whether the specified user can watch all the specified issues.

Parameters
issues The list of issues to check
remoteUser The user to execute this check for
Returns
  • true; if the specified user can watch all the specified issues; otherwise, false is returned.

public boolean canWatchAll (Iterable<Issue> issues, ApplicationUser applicationUser)

Whether the specified user can watch all the specified issues.

Parameters
issues The list of issues to check
applicationUser The user to execute this check for
Returns
  • true; if the specified user can watch all the specified issues; otherwise, false is returned.

public ServiceOutcome<Pair<IntegerList<User>>> getWatchers (Issue issue, User 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. 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.

Parameters
issue the Issue to find watchers for
remoteUser the calling User
Returns
  • a ServiceOutcome containing the total number of watchers, and a list of visible watchers

public boolean hasViewWatcherListPermission (Issue issue, User remoteUser)

Returns true iff the given User has permission to view the watcher list of the issue.

Parameters
issue an Issue
remoteUser a User
Returns
  • a boolean indicating whether the user can view the watch list

public boolean isWatchingEnabled ()

Returns true iff watching is enabled.

Returns
  • true iff watching is enabled

public ServiceOutcome<List<User>> removeWatcher (Issue issue, User remoteUser, User watcher)

Removes a watcher from an issue's list of watchers, returning the updated list of watchers.

Parameters
issue the Issue to update
remoteUser a User indicating the user on behalf of whom this operation is being performed
watcher a User representing the User to remove from the watcher list
Returns
  • a ServiceOutcome containing a list of User

public WatcherService.BulkWatchResult removeWatcherFromAll (Collection<Issue> issues, ApplicationUser remoteUser, ApplicationUser watcher)

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.

Parameters
issues the list of Issues to update
remoteUser an ApplicationUser indicating the user on behalf of whom this operation is being performed
watcher 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

Protected Methods

protected boolean canEditWatcherList (Issue issue, User remoteUser)

Returns true iff the given User has permission to edit the watcher list of the issue.

Parameters
issue an Issue
remoteUser a User
Returns
  • a boolean indicating whether the user can edit the watch list

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. Throws an exception if the user does not have permission.

Parameters
issue an Issue
remoteUser a User representing the caller
watcher a User representing the watcher to add or remove
Throws
if the caller does not have permission to manage watchers, or cannot see the issue
WatchingDisabledException if watching is disabled
DefaultWatcherService.PermissionException

protected Pair<IntegerList<T>> convertUsers (Pair<IntegerList<String>> watchers, Function<String, T> function)

Converts the usernames into User objects using the given function.

Parameters
watchers a Pair of watcher count and watcher usernames
function a Function used for conversion
Returns
  • a Pair of watcher count and User object

protected List<User> getCurrentWatchersFor (Issue issue)

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

protected Pair<IntegerList<String>> getWatcherUsernames (Issue issue, User remoteUser)

Returns a pair containing the watcher count and the watcher usernames for a given issue.

Parameters
issue the Issue
remoteUser the calling User
Returns
  • a Pair containing the watcher count and the watcher usernames for a given issue
Throws
WatchingDisabledException if watching is disabled