package envoy.server.data; import java.util.Date; import java.util.stream.Collectors; import javax.persistence.*; /** * This class serves as a way to let Hibernate communicate with the server * without bringing the dependency of JPA/Hibernate into the client.
* It will be referenced as "database user" to clarify between the different * user objects.
*
* Project: envoy-server-standalone
* File: User.java
* Created: 02.01.2020
* * @author Kai S. K. Engelbart * @author Maximilian Käfer * @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 { private byte[] passwordHash; @Temporal(TemporalType.TIMESTAMP) private Date lastSeen; private envoy.data.User.UserStatus status; /** * {@inheritDoc} */ @Override public envoy.data.User toCommon() { return new envoy.data.User(id, name, status, contacts.stream().map(Contact::toCommon).collect(Collectors.toSet())); } /** * @return the passwordHash of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public byte[] getPasswordHash() { return passwordHash; } /** * @param passwordHash the password hash to set * @since Envoy Server Standalone v0.1-alpha * @see User#getPasswordHash() */ public void setPasswordHash(byte[] passwordHash) { this.passwordHash = passwordHash; } /** * @return the last date an {link envoy.data.User} has been online * @since Envoy Server Standalone v0.1-alpha */ public Date getLastSeen() { return lastSeen; } /** * @param lastSeen the latest date at which has been seen to set * @since Envoy Server Standalone v0.1-alpha * @see User#getLastSeen() */ public void setLastSeen(Date lastSeen) { this.lastSeen = lastSeen; } /** * @return the status of a {link envoy.data.User} * @since Envoy Server Standalone v0.1-alpha */ public envoy.data.User.UserStatus getStatus() { return status; } /** * @param status the status to set * @since Envoy Server Standalone v0.1-alpha * @see User#getStatus() */ public void setStatus(envoy.data.User.UserStatus status) { this.status = status; } }