Class UserService

java.lang.Object
com.plannaplan.services.UserService

@Service
public class UserService
extends java.lang.Object
Service of UserService which can get(By Email), login, save user.
  • Constructor Summary

    Constructors 
    Constructor Description
    UserService()  
  • Method Summary

    Modifier and Type Method Description
    boolean adminExists()  
    User checkForUser​(java.lang.String email, java.lang.String usosId)
    checks if user exist and return him or creates new one with student role otherwise
    User checkForUser​(java.lang.String email, java.lang.String usosId, UserRoles roleIfNotExist)
    checks if user exist and creates new one if doesn't
    java.util.List<User> getAllStudents()  
    java.util.Optional<User> getByAuthority​(java.lang.String authority)
    return user by given authority
    java.util.Optional<User> getById​(java.lang.Long userId)  
    java.util.Optional<User> getByToken​(java.lang.String token)  
    java.util.List<User> getStudentsSortedByRanking()
    get students sorted by their ranking
    User getUserByEmail​(java.lang.String email)  
    java.util.Optional<User> getUserByRefreshToken​(java.lang.String refreshToken)  
    User login​(User authority)
    generates token for user and if user don't have name in database it will attemp to obtain these from usos api and saves changes in database
    User save​(User user)
    sacves user to databse and return instatnce with id
    void saveAll​(java.util.List<User> users)  
    java.util.List<User> searchForStudents​(java.lang.String query)
    search for user with given query

    Methods inherited from class java.lang.Object

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

  • Method Details

    • checkForUser

      public User checkForUser​(java.lang.String email, java.lang.String usosId)
      checks if user exist and return him or creates new one with student role otherwise
      Parameters:
      email - user email in usos
      usosId - user id in usos
      Returns:
      user entity instace containing changes saved in database
    • checkForUser

      public User checkForUser​(java.lang.String email, java.lang.String usosId, UserRoles roleIfNotExist)
      checks if user exist and creates new one if doesn't
      Parameters:
      email - user email in usos
      usosId - user id in usos
      roleIfNotExist - role to be set in case user is not in database yet
      Returns:
      user entity instace containing changes saved in database
    • login

      public User login​(User authority) throws UserNotFoundException
      generates token for user and if user don't have name in database it will attemp to obtain these from usos api and saves changes in database
      Parameters:
      authority - user we want to login
      Returns:
      user with changed values after save in db
      Throws:
      UserNotFoundException - throwed if user doesn't exist
    • save

      public User save​(User user)
      sacves user to databse and return instatnce with id
      Parameters:
      user - to be saved
      Returns:
      instatnce with bd id
    • getUserByEmail

      public User getUserByEmail​(java.lang.String email) throws UserNotFoundException
      Parameters:
      email - of user to be find
      Returns:
      user with given mail
      Throws:
      UserNotFoundException - throwed if user doesn't exist
    • getByAuthority

      public java.util.Optional<User> getByAuthority​(java.lang.String authority)
      return user by given authority
      Parameters:
      authority - user usosId or email
      Returns:
      optional with user if found
    • getByToken

      public java.util.Optional<User> getByToken​(java.lang.String token)
    • searchForStudents

      public java.util.List<User> searchForStudents​(java.lang.String query)
      search for user with given query
      Parameters:
      query - string that will be matched to users name and surname
      Returns:
      list opf results
    • getById

      public java.util.Optional<User> getById​(java.lang.Long userId)
    • getAllStudents

      public java.util.List<User> getAllStudents()
    • getUserByRefreshToken

      public java.util.Optional<User> getUserByRefreshToken​(java.lang.String refreshToken)
    • adminExists

      public boolean adminExists()
    • saveAll

      public void saveAll​(java.util.List<User> users)
    • getStudentsSortedByRanking

      public java.util.List<User> getStudentsSortedByRanking()
      get students sorted by their ranking
      Returns:
      list of students