2020-01-02 17:50:56 +01:00
|
|
|
package envoy.server.data;
|
|
|
|
|
|
|
|
import java.util.Date;
|
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-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
|
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-06 22:55:27 +02:00
|
|
|
public final 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)
|
|
|
|
private Date lastSeen;
|
|
|
|
private envoy.data.User.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() {
|
|
|
|
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; }
|
|
|
|
}
|