diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java index c9700d5..b6bc402 100644 --- a/src/main/java/envoy/server/data/Contact.java +++ b/src/main/java/envoy/server/data/Contact.java @@ -1,8 +1,19 @@ package envoy.server.data; +import java.util.Date; import java.util.Set; -import javax.persistence.*; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; /** * This class acts as a superclass for all contacts, being {@link User}s and @@ -26,6 +37,9 @@ public abstract class Contact { protected long id; protected String name; + @Temporal(TemporalType.TIMESTAMP) + private Date creationDate; + @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) protected Set contacts; @@ -86,6 +100,18 @@ public abstract class Contact { */ public void setContacts(Set contacts) { this.contacts = contacts; } + /** + * @return the creationDate + * @since Envoy Server Standalone v0.1-beta + */ + public Date getCreationDate() { return creationDate; } + + /** + * @param creationDate the creationDate to set + * @since Envoy Server Standalone v0.1-beta + */ + public void setCreationDate(Date creationDate) { this.creationDate = creationDate; } + /** * {@inheritDoc} */ diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java index 688ad4c..5f3be22 100644 --- a/src/main/java/envoy/server/data/Group.java +++ b/src/main/java/envoy/server/data/Group.java @@ -3,6 +3,7 @@ package envoy.server.data; import java.util.stream.Collectors; import javax.persistence.Entity; +import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; @@ -19,18 +20,31 @@ import javax.persistence.Table; */ @Entity @Table(name = "groups") -@NamedQuery( - name = Group.findByName, - query = "SELECT g FROM Group g WHERE g.name = :name" -) +@NamedQueries({ + @NamedQuery( + name = Group.findByName, + query = "SELECT g FROM Group g WHERE g.name = :name" + ), + @NamedQuery( + name = Group.findPendingGroups, + query = "SELECT g FROM Group g WHERE g.creationDate > :lastSeen AND :user MEMBER OF g.contacts" + ) +}) public class Group extends Contact { /** - * Named query retrieving a group by name (parameter {@code :name}. + * Named query retrieving a group by name (parameter {@code :name}). * * @since Envoy Server Standalone v0.1-beta */ public static final String findByName = "Group.findByName"; + + /** + * Named query retrieving all pending groups for a specific user (parameter {@code :user}, {@code :lastSeen}). + * + * @since Envoy Server Standalone v0.1-beta + */ + public static final String findPendingGroups = "Group.findPendingGroups"; /** * {@inheritDoc}