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

88 lines
2.5 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
/**
2020-01-03 16:21:35 +01:00
* This class serves as a way to let Hibernate communicate with the server
* without bringing the dependency of JPA/Hibernate into the client.<br>
* It will be referenced as "database user" to clarify between the different
* user objects.<br>
* <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 final 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 envoy.data.User.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 passwordHash of a {link envoy.data.User}
* @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
* @see User#getPasswordHash()
*/
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 an {link envoy.data.User} has been online
* @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 has been seen to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getLastSeen()
*/
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 of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
2020-01-02 17:50:56 +01:00
public envoy.data.User.UserStatus getStatus() { return status; }
2020-01-03 16:21:35 +01:00
/**
* @param status the status to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getStatus()
*/
2020-01-02 17:50:56 +01:00
public void setStatus(envoy.data.User.UserStatus status) { this.status = status; }
}