155 lines
4.4 KiB
Java
Executable File
155 lines
4.4 KiB
Java
Executable File
package envoy.server.data;
|
|
|
|
import java.time.Instant;
|
|
import java.util.Set;
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.persistence.*;
|
|
|
|
import envoy.data.User.UserStatus;
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @author Maximilian Käfer
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
*/
|
|
@Entity
|
|
@NamedQueries({
|
|
@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)")
|
|
})
|
|
public final class User extends Contact {
|
|
|
|
/**
|
|
* Named query retrieving a user by name (parameter {@code :name}).
|
|
*
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public static final String findByName = "User.findByName";
|
|
|
|
/**
|
|
* Named query retrieving the contacts of a given user (parameter {@code :user}).
|
|
*
|
|
* @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
|
|
* {@code :searchPhrase}) that are not in the contact list of a given user (parameter
|
|
* {@code :context}).
|
|
*
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public static final String searchByName = "User.searchByName";
|
|
|
|
@Column(name = "password_hash")
|
|
private String passwordHash;
|
|
|
|
@Column(name = "auth_token")
|
|
private String authToken;
|
|
|
|
@Column(name = "auth_token_expiration")
|
|
private Instant authTokenExpiration;
|
|
|
|
@Column(name = "last_seen")
|
|
private Instant lastSeen;
|
|
|
|
@Column(name = "latest_contact_deletion")
|
|
private Instant latestContactDeletion;
|
|
|
|
private UserStatus status;
|
|
|
|
@Override
|
|
public envoy.data.User toCommon() {
|
|
return new envoy.data.User(id, name, status,
|
|
contacts.parallelStream().map(Contact::toFlatCommon).collect(Collectors.toSet()));
|
|
}
|
|
|
|
@Override
|
|
protected envoy.data.User toFlatCommon() {
|
|
return new envoy.data.User(id, name, status, Set.of());
|
|
}
|
|
|
|
/**
|
|
* @return the password hash
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public String getPasswordHash() { return passwordHash; }
|
|
|
|
/**
|
|
* @param passwordHash the password hash to set
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }
|
|
|
|
/**
|
|
* @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; }
|
|
|
|
/**
|
|
* @param authTokenExpiration the authentication token expiration timestamp to set
|
|
* @since Envoy Server v0.2-beta
|
|
*/
|
|
public void setAuthTokenExpiration(Instant authTokenExpiration) {
|
|
this.authTokenExpiration = authTokenExpiration;
|
|
}
|
|
|
|
/**
|
|
* @return the last date the user has been online
|
|
* @since Envoy Server Standalone v0.2-beta
|
|
*/
|
|
public Instant getLastSeen() { return lastSeen; }
|
|
|
|
/**
|
|
* @param lastSeen the latest date at which the user has been online to set
|
|
* @since Envoy Server Standalone v0.2-beta
|
|
*/
|
|
public void setLastSeen(Instant lastSeen) { this.lastSeen = lastSeen; }
|
|
|
|
/**
|
|
* @return the status
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
*/
|
|
public UserStatus getStatus() { return status; }
|
|
|
|
/**
|
|
* @param status the status to set
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
*/
|
|
public void setStatus(UserStatus status) { this.status = status; }
|
|
|
|
/**
|
|
* @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
|
|
*/
|
|
public void setLatestContactDeletion(Instant latestContactDeletion) {
|
|
this.latestContactDeletion = latestContactDeletion;
|
|
}
|
|
}
|