55 lines
1.7 KiB
Java
55 lines
1.7 KiB
Java
package envoy.server.data;
|
|
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
import javax.persistence.CascadeType;
|
|
import javax.persistence.Entity;
|
|
import javax.persistence.ManyToMany;
|
|
import javax.persistence.NamedQueries;
|
|
import javax.persistence.NamedQuery;
|
|
import javax.persistence.Table;
|
|
|
|
/**
|
|
* 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 group" to clarify between the different
|
|
* group objects.<br>
|
|
* <br>
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
|
* File: <strong>Group.java</strong><br>
|
|
* Created: <strong>24.03.2020</strong><br>
|
|
*
|
|
* @author Maximilian Käfer
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
*/
|
|
@Entity
|
|
@Table(name = "groups")
|
|
@NamedQueries({ @NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName") })
|
|
public class Group extends Contact {
|
|
|
|
@ManyToMany(targetEntity = Group.class, cascade = CascadeType.ALL)
|
|
private List<User> members;
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
public envoy.data.Group toCommon() { return new envoy.data.Group(id, name, members.stream().map(User::getID).collect(Collectors.toList())); }
|
|
|
|
/**
|
|
* @return a list of all users that are a member of this group.
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public List<User> getMembers() { return members; }
|
|
|
|
/**
|
|
* Sets the members of this group.
|
|
*
|
|
* @param members a list of all users, that should be assigned to this group.
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
*/
|
|
public void setMembers(List<User> members) { this.members = members; }
|
|
|
|
}
|