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 intMAX_EMAIL_LENGTHstatic intMAX_PASSWORD_LENGTHstatic intMIN_PASSWORD_LENGTH -
Constructor Summary
Constructors Constructor Description AccountServiceImpl()AccountServiceImpl(AccountDAO accountDao)Service constructor. -
Method Summary
Modifier and Type Method Description booleanchangePassword(java.lang.String email, java.lang.String password)This service method changes the password of an account.booleancheckCredentials(java.lang.String clientMail, java.lang.String newPassword)check the credential with the regular expression.AccountgetAccountByEmail(java.lang.String email)This method return the account given its mail.booleanloginAccount(java.lang.String email, java.lang.String password)Check the credential before login.booleanregisterAccount(Account utente)this function register the account.booleansearchAccountByEmail(java.lang.String email)This service method checks if an account exists in the database.voidsendEmail(java.lang.String account, java.lang.String pw)This method send an Email with new account credentials.booleanverifyIsAdmin(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
-
MAX_EMAIL_LENGTH
public static final int MAX_EMAIL_LENGTH- See Also:
- Constant Field Values
-
MIN_PASSWORD_LENGTH
public static final int MIN_PASSWORD_LENGTH- See Also:
- Constant Field Values
-
MAX_PASSWORD_LENGTH
public static final int MAX_PASSWORD_LENGTH- See Also:
- Constant Field Values
-
-
Constructor Details
-
AccountServiceImpl
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.InterruptedExceptionCheck the credential before login.- Specified by:
loginAccountin interfaceAccountService- Parameters:
email-password-- Returns:
- true or false
- Throws:
java.io.IOExceptionjava.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
checkCredentials
public boolean checkCredentials(java.lang.String clientMail, java.lang.String newPassword) throws java.lang.IllegalArgumentExceptioncheck the credential with the regular expression.- Specified by:
checkCredentialsin interfaceAccountService- Parameters:
clientMail- email of the clientnewPassword- 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.IOExceptionThis service method checks if an account exists in the database.- Specified by:
searchAccountByEmailin interfaceAccountService- Parameters:
email- referring to the account to search for- Returns:
- true if the account exists, false if not
- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOException
-
getAccountByEmail
public Account getAccountByEmail(java.lang.String email) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.io.IOExceptionThis method return the account given its mail.- Specified by:
getAccountByEmailin interfaceAccountService- Parameters:
email- referring to the account to search for- Returns:
- the Account if it exists, null if not
- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.io.IOException
-
changePassword
public boolean changePassword(java.lang.String email, java.lang.String password) throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedExceptionThis service method changes the password of an account.- Specified by:
changePasswordin interfaceAccountService- Parameters:
email- of the accountpassword- updated- Returns:
- true after the change has taken place
- Throws:
java.io.IOExceptionjava.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
viewInfoAccount
public java.util.ArrayList<Account> viewInfoAccount() throws java.io.IOException, java.util.concurrent.ExecutionException, java.lang.InterruptedExceptionThis function return the list of the accounts registered into the db.- Specified by:
viewInfoAccountin interfaceAccountService- Returns:
- list of all accounts stored
- Throws:
java.io.IOException- exceptionjava.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
registerAccount
public boolean registerAccount(Account utente) throws java.io.IOException, java.lang.IllegalArgumentException, java.util.concurrent.ExecutionException, java.lang.InterruptedExceptionthis function register the account.- Specified by:
registerAccountin interfaceAccountService- Parameters:
utente- user into the db.- Returns:
- true.
- Throws:
java.io.IOExceptionjava.lang.IllegalArgumentExceptionjava.util.concurrent.ExecutionExceptionjava.lang.InterruptedException
-
verifyIsAdmin
- Specified by:
verifyIsAdminin interfaceAccountService- 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.EmailExceptionThis method send an Email with new account credentials.- Specified by:
sendEmailin interfaceAccountService- Parameters:
account-pw-- Throws:
org.apache.commons.mail.EmailException
-