2020-01-02 17:50:56 +01:00
|
|
|
package envoy.server.data;
|
|
|
|
|
|
|
|
import java.util.Date;
|
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-04-09 14:15:39 +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.<br>
|
2020-01-03 16:21:35 +01:00
|
|
|
* <br>
|
2020-01-02 17:50:56 +01:00
|
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
|
|
|
* File: <strong>User.java</strong><br>
|
|
|
|
* Created: <strong>02.01.2020</strong><br>
|
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äfer
|
2020-01-02 17:50:56 +01:00
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
|
|
|
@Entity
|
2020-01-03 18:17:26 +01:00
|
|
|
@Table(name = "users")
|
2020-01-18 13:28:54 +01:00
|
|
|
@NamedQueries(
|
2020-02-10 22:29:34 +01:00
|
|
|
{ @NamedQuery(query = "SELECT u FROM User u WHERE u.name = :name", name = "getUserByName"), @NamedQuery(
|
|
|
|
query = "SELECT u.contacts FROM User u WHERE u = :user",
|
|
|
|
name = "getContactsOfUser"
|
|
|
|
), @NamedQuery(
|
|
|
|
query = "SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND NOT :context in elements(u.contacts))",
|
|
|
|
name = "searchUsers"
|
|
|
|
) }
|
2020-01-18 13:28:54 +01:00
|
|
|
)
|
2020-04-09 14:15:39 +02:00
|
|
|
public class User extends Contact {
|
2020-01-02 17:50:56 +01:00
|
|
|
|
2020-03-26 17:18:27 +01:00
|
|
|
private byte[] passwordHash;
|
2020-01-06 13:58:28 +01:00
|
|
|
|
2020-01-02 17:50:56 +01:00
|
|
|
@Temporal(TemporalType.TIMESTAMP)
|
2020-04-09 14:15:39 +02:00
|
|
|
private Date lastSeen;
|
|
|
|
|
|
|
|
private UserStatus status;
|
2020-01-06 13:58:28 +01:00
|
|
|
|
2020-01-11 18:28:48 +01:00
|
|
|
/**
|
2020-03-25 16:34:55 +01:00
|
|
|
* {@inheritDoc}
|
2020-01-03 16:21:35 +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-04-09 21:01:19 +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
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected envoy.data.User toFlatCommon() { return new envoy.data.User(id, name, status, Set.of()); }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
2020-04-09 14:15:39 +02:00
|
|
|
* @return the password hash
|
2020-01-03 16:21:35 +01:00
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public byte[] getPasswordHash() { return passwordHash; }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
|
|
|
* @param passwordHash the password hash to set
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public void setPasswordHash(byte[] passwordHash) { this.passwordHash = passwordHash; }
|
|
|
|
|
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-01-03 16:21:35 +01:00
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public Date getLastSeen() { return lastSeen; }
|
|
|
|
|
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-01-03 16:21:35 +01:00
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public void setLastSeen(Date lastSeen) { this.lastSeen = lastSeen; }
|
|
|
|
|
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-01-02 17:50:56 +01:00
|
|
|
}
|