2020-01-02 17:50:56 +01:00
package envoy.server.data ;
2020-07-16 17:04:35 +02:00
import java.time.Instant ;
2020-04-09 21:01:19 +02:00
import java.util.Set ;
2020-04-02 16:32:23 +02:00
import java.util.stream.Collectors ;
2020-01-02 17:50:56 +01:00
2020-01-28 19:25:30 +01:00
import javax.persistence.* ;
2020-01-02 17:50:56 +01:00
2020-04-09 14:15:39 +02:00
import envoy.data.User.UserStatus ;
2020-01-02 17:50:56 +01:00
/ * *
2020-10-19 18:17:51 +02:00
* This class enables the storage of user specific data inside a database using Hibernate . Its
* objects will be referred to as database users as opposed to the common user objects present on
* both the client and the server .
2020-01-03 16:21:35 +01:00
*
2020-01-02 17:50:56 +01:00
* @author Kai S . K . Engelbart
2020-02-10 20:02:05 +01:00
* @author Maximilian K & auml ; fer
2020-01-02 17:50:56 +01:00
* @since Envoy Server Standalone v0 . 1 - alpha
* /
@Entity
2020-04-24 21:24:19 +02:00
@NamedQueries ( {
2020-10-19 18:17:51 +02:00
@NamedQuery ( name = User . findByName , query = " SELECT u FROM User u WHERE u.name = :name " ) ,
@NamedQuery ( name = User . findContacts , query = " SELECT u.contacts FROM User u WHERE u = :user " ) ,
@NamedQuery ( name = User . searchByName , query = " SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND :context NOT MEMBER OF u.contacts) " )
2020-04-24 21:24:19 +02:00
} )
2020-08-22 13:37:07 +02:00
public final class User extends Contact {
2020-01-02 17:50:56 +01:00
2020-04-24 21:24:19 +02:00
/ * *
* Named query retrieving a user by name ( parameter { @code : name } ) .
2020-09-18 11:29:05 +02:00
*
2020-04-24 21:24:19 +02:00
* @since Envoy Server Standalone v0 . 1 - beta
* /
public static final String findByName = " User.findByName " ;
/ * *
2020-10-19 18:17:51 +02:00
* Named query retrieving the contacts of a given user ( parameter { @code : user } ) .
2020-09-18 11:29:05 +02:00
*
2020-04-24 21:24:19 +02:00
* @since Envoy Server Standalone v0 . 1 - beta
* /
public static final String findContacts = " User.findContacts " ;
/ * *
* Named query searching for users with a name like a search phrase ( parameter
2020-10-19 18:17:51 +02:00
* { @code : searchPhrase } ) that are not in the contact list of a given user ( parameter
* { @code : context } ) .
2020-09-18 11:29:05 +02:00
*
2020-04-24 21:24:19 +02:00
* @since Envoy Server Standalone v0 . 1 - beta
* /
public static final String searchByName = " User.searchByName " ;
2020-06-15 11:59:48 +02:00
@Column ( name = " password_hash " )
2020-07-10 23:25:13 +02:00
private String passwordHash ;
2020-01-06 13:58:28 +01:00
2020-09-18 11:29:05 +02:00
@Column ( name = " auth_token " )
private String authToken ;
@Column ( name = " auth_token_expiration " )
private Instant authTokenExpiration ;
2020-06-15 11:59:48 +02:00
@Column ( name = " last_seen " )
2020-07-16 17:04:35 +02:00
private Instant lastSeen ;
2020-04-09 14:15:39 +02:00
2020-10-10 22:25:39 +02:00
@Column ( name = " latest_contact_deletion " )
private Instant latestContactDeletion ;
2020-04-09 14:15:39 +02:00
private UserStatus status ;
2020-01-06 13:58:28 +01:00
2020-03-25 16:34:55 +01:00
@Override
2020-04-02 16:32:23 +02:00
public envoy . data . User toCommon ( ) {
2020-10-19 18:17:51 +02:00
return new envoy . data . User ( id , name , status ,
contacts . parallelStream ( ) . map ( Contact : : toFlatCommon ) . collect ( Collectors . toSet ( ) ) ) ;
2020-04-02 16:32:23 +02:00
}
2020-01-02 17:50:56 +01:00
2020-04-09 21:01:19 +02:00
@Override
2020-10-19 18:17:51 +02:00
protected envoy . data . User toFlatCommon ( ) {
return new envoy . data . User ( id , name , status , Set . of ( ) ) ;
}
2020-04-09 21:01:19 +02:00
2020-01-03 16:21:35 +01:00
/ * *
2020-04-09 14:15:39 +02:00
* @return the password hash
2020-07-10 23:25:13 +02:00
* @since Envoy Server Standalone v0 . 1 - beta
2020-01-03 16:21:35 +01:00
* /
2020-07-10 23:25:13 +02:00
public String getPasswordHash ( ) { return passwordHash ; }
2020-01-02 17:50:56 +01:00
2020-01-03 16:21:35 +01:00
/ * *
* @param passwordHash the password hash to set
2020-07-10 23:25:13 +02:00
* @since Envoy Server Standalone v0 . 1 - beta
2020-01-03 16:21:35 +01:00
* /
2020-07-10 23:25:13 +02:00
public void setPasswordHash ( String passwordHash ) { this . passwordHash = passwordHash ; }
2020-01-02 17:50:56 +01:00
2020-09-18 11:29:05 +02:00
/ * *
* @return the authentication token
* @since Envoy Server v0 . 2 - beta
* /
public String getAuthToken ( ) { return authToken ; }
/ * *
* @param authToken the authentication token to set
* @since Envoy Server v0 . 2 - beta
* /
public void setAuthToken ( String authToken ) { this . authToken = authToken ; }
/ * *
* @return the time at which the authentication token expires
* @since Envoy Server v0 . 2 - beta
* /
public Instant getAuthTokenExpiration ( ) { return authTokenExpiration ; }
/ * *
2020-10-19 18:17:51 +02:00
* @param authTokenExpiration the authentication token expiration timestamp to set
2020-09-18 11:29:05 +02:00
* @since Envoy Server v0 . 2 - beta
* /
2020-10-19 18:17:51 +02:00
public void setAuthTokenExpiration ( Instant authTokenExpiration ) {
this . authTokenExpiration = authTokenExpiration ;
}
2020-09-18 11:29:05 +02:00
2020-01-03 16:21:35 +01:00
/ * *
2020-04-09 14:15:39 +02:00
* @return the last date the user has been online
2020-07-16 17:04:35 +02:00
* @since Envoy Server Standalone v0 . 2 - beta
2020-01-03 16:21:35 +01:00
* /
2020-07-16 17:04:35 +02:00
public Instant getLastSeen ( ) { return lastSeen ; }
2020-01-02 17:50:56 +01:00
2020-01-03 16:21:35 +01:00
/ * *
2020-04-09 14:15:39 +02:00
* @param lastSeen the latest date at which the user has been online to set
2020-07-16 17:04:35 +02:00
* @since Envoy Server Standalone v0 . 2 - beta
2020-01-03 16:21:35 +01:00
* /
2020-07-16 17:04:35 +02:00
public void setLastSeen ( Instant lastSeen ) { this . lastSeen = lastSeen ; }
2020-01-02 17:50:56 +01:00
2020-01-03 16:21:35 +01:00
/ * *
2020-04-09 14:15:39 +02:00
* @return the status
2020-01-03 16:21:35 +01:00
* @since Envoy Server Standalone v0 . 1 - alpha
* /
2020-04-09 14:15:39 +02:00
public UserStatus getStatus ( ) { return status ; }
2020-01-02 17:50:56 +01:00
2020-01-03 16:21:35 +01:00
/ * *
* @param status the status to set
* @since Envoy Server Standalone v0 . 1 - alpha
* /
2020-04-09 14:15:39 +02:00
public void setStatus ( UserStatus status ) { this . status = status ; }
2020-10-10 22:25:39 +02:00
/ * *
* @return the latestContactDeletion
* @since Envoy Server v0 . 3 - beta
* /
public Instant getLatestContactDeletion ( ) { return latestContactDeletion ; }
/ * *
* @param latestContactDeletion the latestContactDeletion to set
* @since Envoy Server v0 . 3 - beta
* /
2020-10-19 18:17:51 +02:00
public void setLatestContactDeletion ( Instant latestContactDeletion ) {
this . latestContactDeletion = latestContactDeletion ;
}
2020-01-02 17:50:56 +01:00
}