Class SwitchingUserDao

java.lang.Object
com.atlassian.jira.crowd.embedded.ofbiz.SwitchingUserDao
All Implemented Interfaces:
com.atlassian.crowd.embedded.spi.UserDao, ExtendedUserDao

public class SwitchingUserDao extends Object
Switch between indexing and nonindexing UserDao. The switch is made on construction time. This is a smell, because constructors should be lightweight have no side effects. Unfortunately, we cannot do it right, because of the conjunction of the following reasons:
  • OfBizUserDao has a dirty constructor
  • Pico implicitly publishes implementations under all supertypes of the explicit key
  • Pico doesn't allow a single implementation under multiple explicit keys
bad code + unnecessary framework = more bad code = this
  • Constructor Details

  • Method Details

    • delegate

      protected ExtendedUserDao delegate()
    • useFullCache

      public boolean useFullCache()
      Specified by:
      useFullCache in interface ExtendedUserDao
    • useInternedUserValues

      public boolean useInternedUserValues()
      Specified by:
      useInternedUserValues in interface ExtendedUserDao
    • getUniqueUserCount

      public long getUniqueUserCount(Set<Long> directoryIds) throws com.atlassian.crowd.exception.DirectoryNotFoundException
      Specified by:
      getUniqueUserCount in interface ExtendedUserDao
      Throws:
      com.atlassian.crowd.exception.DirectoryNotFoundException
    • findNamesOfUsersInGroups

      public Collection<String> findNamesOfUsersInGroups(Collection<String> groupNames)
      Description copied from interface: ExtendedUserDao
      Returns the lower-cased names of all users in the specified groups. Only searches directly in these groups, if a recursive group search is required the caller will need to pre-expand the groups.
      Specified by:
      findNamesOfUsersInGroups in interface ExtendedUserDao
      Parameters:
      groupNames - the names of the groups to search.
      Returns:
      set of all user names in these groups, in lower case.
    • getAllAttributeKeys

      public Collection<String> getAllAttributeKeys()
      Specified by:
      getAllAttributeKeys in interface ExtendedUserDao
    • processUsers

      public void processUsers(Consumer<? super com.atlassian.crowd.model.user.User> userProcessor)
      Description copied from interface: ExtendedUserDao
      Performs an operation on every user in the system.

      This can be a time-consuming operation on JIRA instances that contain many users. It is recommended to use one of the search methods where possible.

      This method performs a live iteration over a database result set. Care must be taken if additional database operations are performed within the userProcessor consumer.

      Specified by:
      processUsers in interface ExtendedUserDao
      Parameters:
      userProcessor - the operation to perform on each user.
    • flushCache

      public void flushCache()
      Description copied from interface: ExtendedUserDao
      Invoked by OfBizCacheFlushingManager to ensure caches are being flushed in the right order on XMLRestoreFinishedEvent
      Specified by:
      flushCache in interface ExtendedUserDao
    • findByName

      public com.atlassian.crowd.model.user.TimestampedUser findByName(long directoryId, String userName) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      findByName in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • findByExternalId

      public com.atlassian.crowd.model.user.TimestampedUser findByExternalId(long directoryId, String externalId) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      findByExternalId in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • findByNameWithAttributes

      public com.atlassian.crowd.model.user.UserWithAttributes findByNameWithAttributes(long directoryId, String userName) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      findByNameWithAttributes in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • getCredential

      public com.atlassian.crowd.embedded.api.PasswordCredential getCredential(long directoryId, String userName) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      getCredential in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • getCredentialHistory

      public List<com.atlassian.crowd.embedded.api.PasswordCredential> getCredentialHistory(long directoryId, String userName) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      getCredentialHistory in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • add

      public com.atlassian.crowd.model.user.User add(com.atlassian.crowd.model.user.User user, com.atlassian.crowd.embedded.api.PasswordCredential credential) throws com.atlassian.crowd.exception.UserAlreadyExistsException, IllegalArgumentException, com.atlassian.crowd.exception.DirectoryNotFoundException
      Specified by:
      add in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserAlreadyExistsException
      IllegalArgumentException
      com.atlassian.crowd.exception.DirectoryNotFoundException
    • update

      public com.atlassian.crowd.model.user.User update(com.atlassian.crowd.model.user.User user) throws com.atlassian.crowd.exception.UserNotFoundException, IllegalArgumentException
      Specified by:
      update in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
      IllegalArgumentException
    • updateCredential

      public void updateCredential(com.atlassian.crowd.model.user.User user, com.atlassian.crowd.embedded.api.PasswordCredential credential, int maxCredentialHistory) throws com.atlassian.crowd.exception.UserNotFoundException, IllegalArgumentException
      Specified by:
      updateCredential in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
      IllegalArgumentException
    • rename

      public com.atlassian.crowd.model.user.User rename(com.atlassian.crowd.model.user.User user, String newName) throws com.atlassian.crowd.exception.UserNotFoundException, com.atlassian.crowd.exception.UserAlreadyExistsException, IllegalArgumentException
      Specified by:
      rename in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
      com.atlassian.crowd.exception.UserAlreadyExistsException
      IllegalArgumentException
    • removeAttribute

      public void removeAttribute(com.atlassian.crowd.model.user.User user, String attributeName) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      removeAttribute in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • remove

      public void remove(com.atlassian.crowd.model.user.User user) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      remove in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • search

      public <T> List<T> search(long directoryId, com.atlassian.crowd.search.query.entity.EntityQuery<T> query)
      Specified by:
      search in interface com.atlassian.crowd.embedded.spi.UserDao
    • addAll

      public com.atlassian.crowd.util.BatchResult<com.atlassian.crowd.model.user.User> addAll(Set<com.atlassian.crowd.model.user.UserTemplateWithCredentialAndAttributes> users)
      Specified by:
      addAll in interface com.atlassian.crowd.embedded.spi.UserDao
    • removeAllUsers

      public com.atlassian.crowd.util.BatchResult<String> removeAllUsers(long directoryId, Set<String> userNames)
      Specified by:
      removeAllUsers in interface com.atlassian.crowd.embedded.spi.UserDao
    • setAttributeForAllInDirectory

      public void setAttributeForAllInDirectory(long directoryId, String attrName, String attrValue)
      Specified by:
      setAttributeForAllInDirectory in interface com.atlassian.crowd.embedded.spi.UserDao
    • findOfBizUser

      public OfBizUser findOfBizUser(long directoryId, String userName) throws UserNotFoundException
      Specified by:
      findOfBizUser in interface ExtendedUserDao
      Throws:
      UserNotFoundException
    • findAllByNameOrNull

      public List<OfBizUser> findAllByNameOrNull(long directoryId, @Nonnull Collection<String> userNames)
      Specified by:
      findAllByNameOrNull in interface ExtendedUserDao
    • findByNameOrNull

      @Nullable public OfBizUser findByNameOrNull(long directoryId, @Nonnull String userName)
      Description copied from interface: ExtendedUserDao
      Tries to find the user by name and returns null if not found. Just like the public method should have done in the first place!
      Specified by:
      findByNameOrNull in interface ExtendedUserDao
      Parameters:
      directoryId - Directory ID
      userName - the username
      Returns:
      the user, or null if the user does not exist
    • getAllExternalIds

      public Set<String> getAllExternalIds(long directoryId) throws com.atlassian.crowd.exception.DirectoryNotFoundException
      Specified by:
      getAllExternalIds in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.DirectoryNotFoundException
    • getUserCount

      public long getUserCount(long directoryId) throws com.atlassian.crowd.exception.DirectoryNotFoundException
      Specified by:
      getUserCount in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.DirectoryNotFoundException
    • findById

      @Nullable public OfBizUser findById(long internalUserId)
      Description copied from interface: ExtendedUserDao
      Finds a user by internal user ID.
      Specified by:
      findById in interface ExtendedUserDao
      Parameters:
      internalUserId - the user ID.
      Returns:
      the found user, or null if not found.
    • isDeletedExternally

      public boolean isDeletedExternally(long internalUserId)
      Description copied from interface: ExtendedUserDao
      Checks if user (identified by internal user ID) has been deleted from external user directory.
      Specified by:
      isDeletedExternally in interface ExtendedUserDao
      Parameters:
      internalUserId - the user ID.
      Returns:
      true if user has been deleted from external directory, false otherwise.
    • isDeletedExternally

      public boolean isDeletedExternally(long directoryId, @Nonnull String userName)
      Description copied from interface: ExtendedUserDao
      Checks if user (identified by directory ID and user name) has been deleted from external user directory.
      Specified by:
      isDeletedExternally in interface ExtendedUserDao
      Parameters:
      directoryId - Directory ID
      userName - the username
      Returns:
      true if user has been deleted from external directory, false otherwise.
    • update

      public com.atlassian.crowd.model.user.User update(com.atlassian.crowd.model.user.User user, boolean useJiraExtensions) throws UserNotFoundException
      Description copied from interface: ExtendedUserDao
      Updates user, for detailed description see UserDao.update(com.atlassian.crowd.model.user.User).
      Specified by:
      update in interface ExtendedUserDao
      Parameters:
      user - the user details, which should have the same name as the user to modify
      useJiraExtensions - Whether jira extensions should be run. Currently only extension is that when externally deleted user is updated (inactive and flagged) "externally deleted" flag is cleared and user is made active.
      Returns:
      the updated user
      Throws:
      UserNotFoundException - if there is no user with the same name (case-insensitive) and directory as the user provided
      See Also:
      • UserDao.update(com.atlassian.crowd.model.user.User)
    • storeAttributes

      public void storeAttributes(com.atlassian.crowd.model.user.User user, Map<String,Set<String>> attributes, boolean updateTimestamp) throws com.atlassian.crowd.exception.UserNotFoundException
      Specified by:
      storeAttributes in interface com.atlassian.crowd.embedded.spi.UserDao
      Throws:
      com.atlassian.crowd.exception.UserNotFoundException
    • findDirectoryIdsContainingUserName

      public Set<Long> findDirectoryIdsContainingUserName(String username)
      Specified by:
      findDirectoryIdsContainingUserName in interface com.atlassian.crowd.embedded.spi.UserDao
    • findByExternalIds

      public Map<String,String> findByExternalIds(long directoryId, Set<String> externalIds)
      Specified by:
      findByExternalIds in interface com.atlassian.crowd.embedded.spi.UserDao