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

147 lines
4.0 KiB
Java

package envoy.server.data;
import java.util.Date;
import java.util.List;
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
* @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"), // not tested
@NamedQuery(query = "SELECT u FROM User u WHERE lower(u.name) LIKE lower(:searchPhrase)", name = "searchUsers") }
)
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
private byte[] passwordHash;
@Temporal(TemporalType.TIMESTAMP)
private Date lastSeen;
private envoy.data.User.UserStatus status;
@OneToMany(targetEntity = User.class, cascade = CascadeType.ALL, orphanRemoval = true)
private List<User> contacts;
/**
* Creates an instance of @link{User}.
* Solely used for JPA/ Hibernate
*
* @since Envoy Server Standalone v0.1-alpha
*/
public User() {}
/**
* Creates an instance of @link{User}.
*
* @param user the {@link envoy.data.User} to convert
* @since Envoy Server Standalone v0.1-alpha
*/
public User(envoy.data.User user) {
id = user.getId();
name = user.getName();
status = user.getStatus();
}
/**
* @return a database {@link User} converted into an {@link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public envoy.data.User toCommonUser() { return new envoy.data.User(id, name); }
/**
* @return the id of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public long getId() { return id; }
/**
* @param id the id to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getId
*/
public void setId(long id) { this.id = id; }
/**
* @return the name of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public String getName() { return name; }
/**
* @param name the username to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getName()
*/
public void setName(String name) { this.name = name; }
/**
* @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; }
/**
* @return the contacts of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public List<User> getContacts() { return contacts; }
/**
* @param contacts the contacts to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getContacts()
*/
public void setContacts(List<User> contacts) { this.contacts = contacts; }
}