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
Executable File

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.<br>
* It will be referenced as "database user" to clarify between the different
* user objects.<br>
* <br>
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>User.java</strong><br>
* Created: <strong>02.01.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @author Maximilian K&auml;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 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; }
}