Class User

java.lang.Object
com.ehealthsystem.user.User
All Implemented Interfaces:
HasAddress

public class User extends Object implements HasAddress
The class represents a user and his attributes
  • Field Details

    • username

      private String username
      Attributes of the user.
    • email

      private String email
      Attributes of the user.
    • firstName

      private String firstName
      Attributes of the user.
    • lastName

      private String lastName
      Attributes of the user.
    • street

      private String street
      Attributes of the user.
    • houseNo

      private String houseNo
      Attributes of the user.
    • gender

      private String gender
      Attributes of the user.
    • zipCode

      private String zipCode
    • birthDate

      private LocalDate birthDate
    • insuranceName

      private String insuranceName
    • privateInsurance

      private boolean privateInsurance
  • Constructor Details

    • User

      public User(String username, String email, String firstName, String lastName, String street, String houseNo, String zipCode, LocalDate birthDate, String gender, String password, String insuranceName, boolean privateInsurance, boolean insertIntoDb) throws SQLException, javax.activation.UnsupportedDataTypeException
      Creates a new user object representing a row in the database
      Parameters:
      username - Username of the user.
      password - Password chosen by the user.
      firstName - First name of the user.
      lastName - Last name of the user.
      email - E-mail address of the user.
      street - Street where the user lives.
      houseNo - House no. of the street.
      zipCode - Zip code where the user lives.
      birthDate - Birthdate of the user.
      privateInsurance - Type of insurance.
      insertIntoDb - Inserts the user in to the Database. * true if this is a new user that is inserted to the database, * false if the object shall solely represent a user that is already saved in the database (i.e. result of a SELECT query) * or also false if object is for bridging the step from registration to email validation
      Throws:
      SQLException - Throws Exception during connection issues.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
  • Method Details

    • insertIntoDb

      public void insertIntoDb(String password) throws SQLException, javax.activation.UnsupportedDataTypeException
      Inserts this user into the database. Only to be used if a new user is created.
      Parameters:
      password - The password in plain-text that is to be stored for this user in a hashed form in the database
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format for the database.
    • changePassword

      public boolean changePassword(String currentPassword, String newPassword) throws SQLException
      Change a user's password Used by the user to change their own password
      Parameters:
      currentPassword - Verifying the current password of the user.
      newPassword - Sets a new password if the current password is valid.
      Returns:
      True if the new password is set, false if the process was aborted because current password is wrong.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
    • setPassword

      private void setPassword(String email, String password) throws SQLException
      Set a user's password Used as helper function but also by admin, which is why it's public
      Parameters:
      email - The E-mail of the user which password is being set.
      password - The password of the user set e.g. by the doctor.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
    • update

      private void update(Object[][] newValues) throws SQLException, javax.activation.UnsupportedDataTypeException
      Updates this user's entry in the database
      Parameters:
      newValues - Attributes(values) of the user.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setUsername

      public void setUsername(String username) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the username in the database
      Parameters:
      username - The username of the user.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setEmail

      public void setEmail(String email) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update email in the database
      Parameters:
      email - The e-mail address of the user-
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setFirstName

      public void setFirstName(String firstName) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the first name in the database
      Parameters:
      firstName - the first name of the user.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setLastName

      public void setLastName(String lastName) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the last name in the database
      Parameters:
      lastName - The last name of the user.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setStreet

      public void setStreet(String street) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update street in the database
      Parameters:
      street - The street where the user lives.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setHouseNo

      public void setHouseNo(String houseNo) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update house no. in the database
      Parameters:
      houseNo - The house no. of the street.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setZipCode

      public void setZipCode(String zipCode) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update zip code in the database
      Parameters:
      zipCode - The zip code where the user lives.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setBirthDate

      public void setBirthDate(LocalDate birthDate) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the birthday in the database
      Parameters:
      birthDate - The birthday from user.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setGender

      public void setGender(String gender) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the gender in the database
      Parameters:
      gender - The gender of the user.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setInsuranceName

      public void setInsuranceName(String insuranceName) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the insurance name in the database
      Parameters:
      insuranceName - The name of the insurance.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • setPrivateInsurance

      public void setPrivateInsurance(boolean privateInsurance) throws SQLException, javax.activation.UnsupportedDataTypeException
      set and update the insurance type in the database
      Parameters:
      privateInsurance - The type of the Insurance.
      Throws:
      SQLException - Throws Exception during connection issues with the Database.
      javax.activation.UnsupportedDataTypeException - Throws Exception if the input of data is invalid/in wrong format.
    • getUsername

      public String getUsername()
      get the username returned
      Returns:
      The username of the user.
    • getFirstName

      public String getFirstName()
      get the first name returned
      Returns:
      The first name of the user.
    • getLastName

      public String getLastName()
      get the last name returned
      Returns:
      The last name of the user.
    • getMail

      public String getMail()
      get the mail returned
      Returns:
      The E-mail of the user.
    • getStreet

      public String getStreet()
      get the street returned
      Specified by:
      getStreet in interface HasAddress
      Returns:
      The street where the user lives.
    • getHouseNumber

      public String getHouseNumber()
      get the house number returned
      Specified by:
      getHouseNumber in interface HasAddress
      Returns:
      The house no. of the street.
    • getGender

      public String getGender()
      get the gender returned
      Returns:
      The gender of the user.
    • getInsuranceName

      public String getInsuranceName()
      get the insurance name returned
      Returns:
      The insurance name.
    • getZipCode

      public String getZipCode()
      get the zip returned
      Specified by:
      getZipCode in interface HasAddress
      Returns:
      The zip code of the users place of residence.
    • getBirthDate

      public LocalDate getBirthDate()
      get the birthday returned
      Returns:
      The birthdate of the user as an object of the type LocalDate.
    • isPrivateInsurance

      public boolean isPrivateInsurance()
      get the insurance type returned
      Returns:
      The type of the insurance of the user.
    • getAppointments

      public ArrayList<Appointment> getAppointments() throws SQLException, javax.activation.UnsupportedDataTypeException
      Wrapper to get users appointments from the user object.
      Returns:
      The appointments of the user.
      Throws:
      SQLException - Throws Exception during connection issues.
      javax.activation.UnsupportedDataTypeException