This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/server/data/User.java

87 lines
2.4 KiB
Java
Raw Normal View History

2020-01-02 17:50:56 +01:00
package envoy.server.data;
import java.util.Date;
import java.util.stream.Collectors;
2020-01-02 17:50:56 +01:00
import javax.persistence.*;
2020-01-02 17:50:56 +01:00
import envoy.data.User.UserStatus;
2020-01-02 17:50:56 +01: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
* @author Maximilian K&auml;fer
2020-01-02 17:50:56 +01:00
* @since Envoy Server Standalone v0.1-alpha
*/
@Entity
@Table(name = "users")
@NamedQueries(
{ @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"
) }
)
public class User extends Contact {
2020-01-02 17:50:56 +01:00
private byte[] passwordHash;
2020-01-02 17:50:56 +01:00
@Temporal(TemporalType.TIMESTAMP)
private Date lastSeen;
private UserStatus status;
/**
* {@inheritDoc}
2020-01-03 16:21:35 +01:00
*/
@Override
public envoy.data.User toCommon() {
return new envoy.data.User(id, name, status, contacts.stream().map(Contact::toCommon).collect(Collectors.toSet()));
}
2020-01-02 17:50:56 +01:00
2020-01-03 16:21:35 +01: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
/**
* @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
/**
* @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
/**
* @return the status
2020-01-03 16:21:35 +01:00
* @since Envoy Server Standalone v0.1-alpha
*/
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
*/
public void setStatus(UserStatus status) { this.status = status; }
2020-01-02 17:50:56 +01:00
}