Class UserService

  • All Implemented Interfaces:
    IUserService

    public class UserService
    extends java.lang.Object
    implements IUserService
    Class for user management.
    • Field Detail

      • users

        protected java.util.Map<User,​User> users
        The users.
      • followers

        protected java.util.Map<User,​java.util.Set<User>> followers
        The followers (that follow the user).
      • followeds

        protected java.util.Map<User,​java.util.Set<User>> followeds
        The followed people (that the user follows).
      • sessions

        protected java.util.Map<java.lang.String,​User> sessions
        The active sessions - logged in users.
    • Constructor Detail

      • UserService

        public UserService()
        Create a new user service.
    • Method Detail

      • register

        public IFuture<java.lang.Void> register​(User user)
        Register a new user.
        Specified by:
        register in interface IUserService
        Parameters:
        user - The new user.
      • registerUser

        protected void registerUser​(User user)
        Register a new user.
        Parameters:
        user - The new user.
      • login

        public IFuture<java.lang.String> login​(User user)
        Login a user.
        Specified by:
        login in interface IUserService
        Parameters:
        user - The user.
        Returns:
        The token for future access.
      • logout

        public IFuture<java.lang.Boolean> logout​(java.lang.String usertoken)
        Logout a user.
        Specified by:
        logout in interface IUserService
        Parameters:
        usertoken - The user token.
        Returns:
        The token for future access.
      • getUser

        public IFuture<User> getUser​(java.lang.String usertoken)
        Get a user per token.
        Specified by:
        getUser in interface IUserService
        Parameters:
        usertoken - The user token.
        Returns:
        The user or null if none.
      • getUserByEmail

        public IFuture<User> getUserByEmail​(java.lang.String email)
        Get a user per email.
        Specified by:
        getUserByEmail in interface IUserService
        Parameters:
        email - The user email.
        Returns:
        The user.
      • internalGetUserByEmail

        protected User internalGetUserByEmail​(java.lang.String email)
        Get a user per email
        Parameters:
        email - The email.
        Returns:
        The user or null.
      • getAllUsers

        public IFuture<java.util.Collection<User>> getAllUsers​(java.lang.String usertoken)
        Get all users.
        Specified by:
        getAllUsers in interface IUserService
        Returns:
        All users.
      • addFollower

        public IFuture<java.lang.Boolean> addFollower​(java.lang.String usertoken,
                                                      User follower)
        Add a new follower.
        Specified by:
        addFollower in interface IUserService
        Parameters:
        user - The user.
        follower - The follower.
        Returns:
        True if changed.
      • addFollower

        protected boolean addFollower​(User user,
                                      User follower)
        Add a follower.
        Parameters:
        user -
        follower -
        Returns:
      • removeFollower

        public IFuture<java.lang.Boolean> removeFollower​(java.lang.String usertoken,
                                                         User follower)
        Remove a follower.
        Specified by:
        removeFollower in interface IUserService
        Parameters:
        user - The user.
        follower - The follower.
        Returns:
        True if changed.
      • removeFollower

        protected boolean removeFollower​(User user,
                                         User follower)
        Remove a follower.
        Parameters:
        user -
        follower -
        Returns:
      • getFollowers

        public IFuture<java.util.Collection<User>> getFollowers​(java.lang.String usertoken)
        Get the current followers.
        Specified by:
        getFollowers in interface IUserService
        Parameters:
        user - The user.
        Returns:
        The followers.
      • addFollowed

        public IFuture<java.lang.Boolean> addFollowed​(java.lang.String usertoken,
                                                      User followed)
        Add a new followed user.
        Specified by:
        addFollowed in interface IUserService
        Parameters:
        user - The user.
        followed - The followed user.
      • addFollowed

        protected boolean addFollowed​(User user,
                                      User followed)
        Add a followed by person.
        Parameters:
        user -
        followed -
        Returns:
      • removeFollowed

        public IFuture<java.lang.Boolean> removeFollowed​(java.lang.String usertoken,
                                                         User followed)
        Remove a followed user.
        Specified by:
        removeFollowed in interface IUserService
        Parameters:
        followed - The followed user.
      • getFolloweds

        public IFuture<java.util.Collection<User>> getFolloweds​(java.lang.String usertoken)
        Get the current followers.
        Specified by:
        getFolloweds in interface IUserService
        Parameters:
        followed - The followed user.
        Returns:
        The user that follow this user.
      • isOnline

        protected boolean isOnline​(User user)
        Test if a user is online.
        Parameters:
        user - The user.
        Returns:
        True, if is currently online.
      • notifyOnlineState

        protected IFuture<java.lang.Void> notifyOnlineState​(User user,
                                                            boolean online)
        Notify all connected users of a specific online state.
      • processForClient

        protected java.util.Collection<User> processForClient​(java.util.Collection<User> coll)
        Process the user objects before sending to the client. - Erases password - Sets online state.
        Parameters:
        coll - The collection.
        Returns:
        The processed collection.
      • processForClient

        protected User processForClient​(User user)
        Process the user objects before sending to the client. - Erases password - Sets online state.
        Parameters:
        coll - The collection.
        Returns:
        The processed collection.