Class AccountServiceImpl

java.lang.Object
it.unisa.c03.myPersonalTrainer.account.service.AccountServiceImpl
All Implemented Interfaces:
AccountService

public class AccountServiceImpl
extends java.lang.Object
implements AccountService
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int MAX_EMAIL_LENGTH  
    static int MAX_PASSWORD_LENGTH  
    static int MIN_PASSWORD_LENGTH  
  • Constructor Summary

    Constructors
    Constructor Description
    AccountServiceImpl()  
    AccountServiceImpl​(AccountDAO accountDao)
    Service constructor.
  • Method Summary

    Modifier and Type Method Description
    boolean changePassword​(java.lang.String email, java.lang.String password)
    This service method changes the password of an account.
    boolean checkCredentials​(java.lang.String clientMail, java.lang.String newPassword)
    check the credential with the regular expression.
    Account getAccountByEmail​(java.lang.String email)
    This method return the account given its mail.
    boolean loginAccount​(java.lang.String email, java.lang.String password)
    Check the credential before login.
    boolean registerAccount​(Account utente)
    this function register the account.
    boolean searchAccountByEmail​(java.lang.String email)
    This service method checks if an account exists in the database.
    void sendEmail​(java.lang.String account, java.lang.String pw)
    This method send an Email with new account credentials.
    boolean verifyIsAdmin​(Account account)  
    java.util.ArrayList<Account> viewInfoAccount()
    This function return the list of the accounts registered into the db.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • AccountServiceImpl

      public AccountServiceImpl​(AccountDAO accountDao)
      Service constructor.
      Parameters:
      accountDao - is required, because is the DAO that all the service methods will call.
    • AccountServiceImpl

      public AccountServiceImpl()
  • Method Details

    • loginAccount

      public boolean loginAccount​(java.lang.String email, java.lang.String password) throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
      Check the credential before login.
      Specified by:
      loginAccount in interface AccountService
      Parameters:
      email -
      password -
      Returns:
      true or false
      Throws:
      java.io.IOException
      java.util.concurrent.ExecutionException
      java.lang.InterruptedException
    • checkCredentials

      public boolean checkCredentials​(java.lang.String clientMail, java.lang.String newPassword) throws java.lang.IllegalArgumentException
      check the credential with the regular expression.
      Specified by:
      checkCredentials in interface AccountService
      Parameters:
      clientMail - email of the client
      newPassword - new password to update
      Returns:
      clientMail, new Passoword, after check
      Throws:
      java.lang.IllegalArgumentException
    • searchAccountByEmail

      public boolean searchAccountByEmail​(java.lang.String email) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This service method checks if an account exists in the database.
      Specified by:
      searchAccountByEmail in interface AccountService
      Parameters:
      email - referring to the account to search for
      Returns:
      true if the account exists, false if not
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • getAccountByEmail

      public Account getAccountByEmail​(java.lang.String email) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOException
      This method return the account given its mail.
      Specified by:
      getAccountByEmail in interface AccountService
      Parameters:
      email - referring to the account to search for
      Returns:
      the Account if it exists, null if not
      Throws:
      java.lang.InterruptedException
      java.util.concurrent.ExecutionException
      java.io.IOException
    • changePassword

      public boolean changePassword​(java.lang.String email, java.lang.String password) throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
      This service method changes the password of an account.
      Specified by:
      changePassword in interface AccountService
      Parameters:
      email - of the account
      password - updated
      Returns:
      true after the change has taken place
      Throws:
      java.io.IOException
      java.util.concurrent.ExecutionException
      java.lang.InterruptedException
    • viewInfoAccount

      public java.util.ArrayList<Account> viewInfoAccount() throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
      This function return the list of the accounts registered into the db.
      Specified by:
      viewInfoAccount in interface AccountService
      Returns:
      list of all accounts stored
      Throws:
      java.io.IOException - exception
      java.util.concurrent.ExecutionException
      java.lang.InterruptedException
    • registerAccount

      public boolean registerAccount​(Account utente) throws java.io.IOException, java.lang.IllegalArgumentException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
      this function register the account.
      Specified by:
      registerAccount in interface AccountService
      Parameters:
      utente - user into the db.
      Returns:
      true.
      Throws:
      java.io.IOException
      java.lang.IllegalArgumentException
      java.util.concurrent.ExecutionException
      java.lang.InterruptedException
    • verifyIsAdmin

      public boolean verifyIsAdmin​(Account account)
      Specified by:
      verifyIsAdmin in interface AccountService
      Parameters:
      account - Account of registred user into the DataBase.
      Returns:
      Return true if the following account is a Personal Trainer's account.
      Throws:
      java.lang.IllegalArgumentException
    • sendEmail

      public void sendEmail​(java.lang.String account, java.lang.String pw) throws org.apache.commons.mail.EmailException
      This method send an Email with new account credentials.
      Specified by:
      sendEmail in interface AccountService
      Parameters:
      account -
      pw -
      Throws:
      org.apache.commons.mail.EmailException