2020-01-02 17:50:56 +01:00
|
|
|
package envoy.server.data;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
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
|
|
|
|
* @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-01-28 19:25:30 +01:00
|
|
|
{ @NamedQuery(query = "SELECT u FROM User u WHERE u.name = :name", name = "getUserByName"),
|
2020-01-18 13:28:54 +01:00
|
|
|
@NamedQuery(query = "SELECT u.contacts FROM User u WHERE u = :user", name = "getContactsOfUser")// not tested
|
|
|
|
}
|
|
|
|
)
|
2020-01-02 17:50:56 +01:00
|
|
|
public class User {
|
|
|
|
|
|
|
|
@Id
|
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
2020-01-11 18:28:48 +01:00
|
|
|
private long id;
|
|
|
|
private String name;
|
|
|
|
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-28 19:25:30 +01:00
|
|
|
@OneToMany(targetEntity = User.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
|
2020-01-11 18:28:48 +01:00
|
|
|
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
|
|
|
|
*/
|
2020-01-28 19:25:30 +01:00
|
|
|
public envoy.data.User toCommonUser() { return new envoy.data.User(id, name); }
|
2020-01-02 17:50:56 +01:00
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
|
|
|
* @return the id of a {link envoy.data.User}
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public long getId() { return id; }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
|
|
|
* @param id the id to set
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
* @see User#getId
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public void setId(long id) { this.id = id; }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
|
|
|
* @return the name of a {link envoy.data.User}
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public String getName() { return name; }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
2020-01-28 19:25:30 +01:00
|
|
|
* @param name the user name to set
|
2020-01-03 16:21:35 +01:00
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
* @see User#getName()
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public void setName(String name) { this.name = name; }
|
|
|
|
|
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; }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
|
|
|
* @return the contacts of a {link envoy.data.User}
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public List<User> getContacts() { return contacts; }
|
|
|
|
|
2020-01-03 16:21:35 +01:00
|
|
|
/**
|
|
|
|
* @param contacts the contacts to set
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
* @see User#getContacts()
|
|
|
|
*/
|
2020-01-02 17:50:56 +01:00
|
|
|
public void setContacts(List<User> contacts) { this.contacts = contacts; }
|
|
|
|
}
|