Interface UserDao

All Known Implementing Classes:
MongoUserDao

public interface UserDao
This is the UserDao which is used to update users in the database. Since users can remain long after deletion, this has several methods which behave slightly differently.

Generally methods with the word "strict" in their prototype mean the operation without regard for the active flag. Other methods may use the active flag to emulate a user that has been deleted from the system.

Created by patricktwohig on 3/26/15.

  • Method Details

    • getUser

      User getUser(String userId)
      Gets the user with the userId. If the user is not active, then this method will behave as if the user does not exist.
      Parameters:
      userId - the user's as determined by User.getId()
      Returns:
      the active user
    • findUser

      default Optional<User> findUser(String userId)
      Finds a user based on the supplied user id, returning the Optional<User> representing the resuot.
      Parameters:
      userId - the user's ID
      Returns:
      an Optional<User>
    • findUserByNameOrEmail

      Optional<User> findUserByNameOrEmail(String userNameOrEmail)
      Finds a user either by email or name.
      Parameters:
      userNameOrEmail - the username or email
      Returns:
      an Optional<User>
    • getUserByNameOrEmail

      default User getUserByNameOrEmail(String userNameOrEmail)
      Gets the user with the user name or email address. If the user is not active, then this method will behave as if the user does not exist.
      Parameters:
      userNameOrEmail - the username or email
      Returns:
      the active user
    • getUsers

      Pagination<User> getUsers(int offset, int count)
      Gets a listing of all users given the offset, and count. Additionally, the user requested must be active. Users not active will be treated as if they do not exist.
      Parameters:
      offset - the offset
      count - the count
      Returns:
      the users in the system
    • getUsers

      Pagination<User> getUsers(int offset, int count, String query)
      Gets a listing of all users given the offset, and count. Additionally, the user requested must be active.
      Parameters:
      offset - the offset
      count - the count
      query - a query to filter the results
      Returns:
      the users in the system
    • getUsersByPrimaryPhoneNumbers

      Pagination<User> getUsersByPrimaryPhoneNumbers(int offset, int count, List<String> phone)
      Gets a listing of all users given the offset, count and phone number
      Parameters:
      offset - the offset
      count - the count
      phone - a phone numberto filter the results
      Returns:
      the users in the system
    • createUserStrict

      User createUserStrict(User user)
      Creates a user with the given User object. Using "Strict" semantics, if the user exists then this will throw an exception. The resulting user will have a scrambled password.
      Parameters:
      user - the user to create
      Returns:
      the User as it was created.
    • createUserWithPasswordStrict

      User createUserWithPasswordStrict(User user, String password)
      Creates a user with the given User object and password. Using "Strict" semantics, if the user exists then this will throw an exception. The resulting user will be assigned the given password.
      Parameters:
      user - the user to create
      password - the password to assign the user
      Returns:
      the User as it was created.
    • createUser

      User createUser(User user)
      Creates or activates a user, or if the user is currently inactive this will reinstate access. This securely scrambles the user's password and therefore the user must change password at a later date.

      Similar to createUserStrict(User) the user will be assigned a scrambled password if the user does not exist (or was previously inactive). This will not touch the user's password if the user both exists and was flagged as active.

      Parameters:
      user - the user
      Returns:
      the User, as written to the database
    • createUserWithPassword

      User createUserWithPassword(User user, String password)
      Creates a user and sets the user's password. If the user exists then this will reinstate the user's account with a new password.
      Parameters:
      user - the user to create
      password - the password for the user to use
      Returns:
      the User, as was written to the database
    • updateUserStrict

      User updateUserStrict(User user)
      Updates the given user, regardless of active status and then returns the user instance as it was written to the database.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      This does not change the user's password.
      Parameters:
      user - the user to update
      Returns:
      the user as was written to the database
    • updateUserStrict

      User updateUserStrict(User user, String password)
      Updates the given user, regardless of active status and then returns the user instance as it was written to the database.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      This will update the user's password.
      Parameters:
      user - the user to update
      Returns:
      the user as was written to the database
    • updateUser

      User updateUser(User user)
      Updates the given active user. If the user has been deleted or has been flagged as inactive, then this method will fail.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      This does not change the user's password.
      Parameters:
      user - the user to update
      Returns:
      the User as written to the database
    • updateUser

      User updateUser(User user, String password)
      Updates the given active user. If the user has been deleted or has been flagged as inactive, then this method will fail.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      Parameters:
      user - the user to update
      password - the user password
      Returns:
      the User, as written to the database
    • updateUser

      User updateUser(User user, String newPassword, String oldPassword)
      Updates the given active user. If the user has been deleted or has been flagged as inactive, then this method will fail.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      Parameters:
      user - the user to update
      newPassword - the user's new password
      oldPassword - the user's old password
      Returns:
      the User, as written to the database
    • createOrUpdateUser

      User createOrUpdateUser(User user)
      Creates a user if one does not exist for the provided info or updates a user if one does exist.

      If the user is currently inactive this will reinstate access. This securely scrambles the user's password and therefore the user must change password at a later date.

      Similar to createUserStrict(User) the user will be assigned a scrambled password if the user does not exist (or was previously inactive). This will not touch the user's password if the user both exists and was flagged as active.

      Parameters:
      user - the user
      Returns:
      the User, as written to the database
    • softDeleteUser

      void softDeleteUser(String userId)
      Deletes a user from the database. In actuality, this isn't a true delete, but rather just flags the user as inactive. LazyValue flagged inactive, a user will not show up in any results for active users.
      Parameters:
      userId - the user's as determined by User.getId()
    • validateUserPassword

      default User validateUserPassword(String userNameOrEmail, String password)
      Validates the user's password and returns the current User instance. If the password validation fails, then this simply throws an instance of ForbiddenException
      Parameters:
      userNameOrEmail - the user's name or email address
      password - the password
      Returns:
      the User, never null
    • findUserWithLoginAndPassword

      Optional<User> findUserWithLoginAndPassword(String userNameOrEmail, String password)
      Finds a User given the login credentials and assword. If the password validation fails, then this will return an empty Optional. If the password validation succeeds, then this returns the user that matched.
      Parameters:
      userNameOrEmail - the user's name or email address
      password - the password
      Returns:
      the User, never null