Class UserDAO

java.lang.Object
com.rit.dca.pubpaper.dao.UserDAO

public class UserDAO
extends java.lang.Object
Database Connectivity and Access
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private int loggedInId  
  • Constructor Summary

    Constructors 
    Constructor Description
    UserDAO()  
  • Method Summary

    Modifier and Type Method Description
    User changeAdminStatus​(int userId, boolean adminStatus)
    Make a particular user Admin (Admin Only)
    User changeReviewStatus​(int userId, boolean reviewStatus)
    Change review status of a particular user (Admin Only)
    protected boolean checkAdmin​(MySQLDatabase connection, int adminUserId)
    Check whether a user is an admin user
    int deleteUsers​(int[] deletionIds)
    Delete a particular user (Admin only)
    java.util.ArrayList<User> getAllUsers()
    Get all users (Admin only)
    int getLoggedInId()  
    User getProfile​(int userId)
    Get the profile info for user object (all properties)
    User getUser​(int userId)
    Get a particular user information (Admin Only)
    User login​(java.lang.String email, java.lang.String password)
    Login a particular user into the system
    boolean logout()  
    private int nextUserId​(MySQLDatabase connection)
    Get the new user id to be inserted
    boolean resetPassword​(java.lang.String email)
    Resets user's password
    private java.lang.String setPassword​(java.lang.String password)
    Returns hashed password
    User setProfile​(java.util.HashMap<java.lang.String,​java.lang.Object> userData)
    Set/Create profile info for existing/new user

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • getLoggedInId

      public int getLoggedInId()
    • getProfile

      public User getProfile​(int userId) throws PubPaperException
      Get the profile info for user object (all properties)
      Parameters:
      userId - - user id for which profile data is requested.
      Returns:
      User object of the profile requested
      Throws:
      PubPaperException
    • setProfile

      public User setProfile​(java.util.HashMap<java.lang.String,​java.lang.Object> userData) throws PubPaperException
      Set/Create profile info for existing/new user
      Parameters:
      userData - HashMap (key-value pairs) of profile parameters
      Returns:
      User object of the profile which is updated/created
      Throws:
      PubPaperException
    • nextUserId

      private int nextUserId​(MySQLDatabase connection)
      Get the new user id to be inserted
      Parameters:
      connection - MySQLDatabase connection object
      Returns:
      int new user id to use
    • resetPassword

      public boolean resetPassword​(java.lang.String email) throws PubPaperException
      Resets user's password
      Parameters:
      email - emailId of the user
      Returns:
      Boolean value indicating if password reset was successful or no
      Throws:
      PubPaperException
    • login

      public User login​(java.lang.String email, java.lang.String password) throws PubPaperException
      Login a particular user into the system
      Parameters:
      email - emailId of the user
      password - password of the user
      Returns:
      User - user instance
      Throws:
      PubPaperException
    • setPassword

      private java.lang.String setPassword​(java.lang.String password)
      Returns hashed password
      Parameters:
      password - password of the user
      Returns:
      String hashed password string
    • checkAdmin

      protected boolean checkAdmin​(MySQLDatabase connection, int adminUserId) throws PubPaperException
      Check whether a user is an admin user
      Parameters:
      connection - MYSQLDatabase connection object
      adminUserId - id of the user
      Returns:
      boolean status of validation
      Throws:
      PubPaperException
    • getAllUsers

      public java.util.ArrayList<User> getAllUsers() throws PubPaperException
      Get all users (Admin only)
      Returns:
      ArrayList Arraylist of all users in the database
      Throws:
      PubPaperException
    • getUser

      public User getUser​(int userId) throws PubPaperException
      Get a particular user information (Admin Only)
      Parameters:
      userId - requested user
      Returns:
      User - user instance
      Throws:
      PubPaperException
    • deleteUsers

      public int deleteUsers​(int[] deletionIds) throws PubPaperException
      Delete a particular user (Admin only)
      Parameters:
      deletionIds - integer array of userIds to delete
      Returns:
      integer number of rowsAffected for the delete operation
      Throws:
      PubPaperException
    • changeAdminStatus

      public User changeAdminStatus​(int userId, boolean adminStatus) throws PubPaperException
      Make a particular user Admin (Admin Only)
      Parameters:
      userId - requested user
      adminStatus - admin status to be given to the user
      Returns:
      User - user instance
      Throws:
      PubPaperException
    • changeReviewStatus

      public User changeReviewStatus​(int userId, boolean reviewStatus) throws PubPaperException
      Change review status of a particular user (Admin Only)
      Parameters:
      userId - requested user
      reviewStatus - review status to be given to the user
      Returns:
      User - user instance
      Throws:
      PubPaperException
    • logout

      public boolean logout()