From ec90a3c2f5af5dd24ab9d6072174c5b96d509870 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 9 Feb 2020 22:16:33 +0100 Subject: [PATCH] Implemented AddContact mechanism on the server (currently unfinished an not working see stack trace for current problem) --- src/main/java/envoy/server/Startup.java | 2 ++ src/main/java/envoy/server/data/User.java | 12 +++++++++++- .../envoy/server/database/PersistenceManager.java | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index f4e5bc7..8039f24 100644 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -10,6 +10,7 @@ import envoy.server.data.ConfigItem; import envoy.server.database.PersistenceManager; import envoy.server.net.ObjectMessageProcessor; import envoy.server.net.ObjectMessageReader; +import envoy.server.processors.ContactOperationProcessor; import envoy.server.processors.ContactsRequestProcesor; import envoy.server.processors.IdGeneratorRequestProcessor; import envoy.server.processors.LoginCredentialProcessor; @@ -44,6 +45,7 @@ public class Startup { processors.add(new UserStatusChangeProcessor()); processors.add(new IdGeneratorRequestProcessor()); processors.add(new ContactsRequestProcesor()); + processors.add(new ContactOperationProcessor()); Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors)); initializeCurrentMessageId(); diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java index 6a07bcf..9865978 100644 --- a/src/main/java/envoy/server/data/User.java +++ b/src/main/java/envoy/server/data/User.java @@ -3,7 +3,17 @@ package envoy.server.data; import java.util.Date; import java.util.List; -import javax.persistence.*; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; /** * This class serves as a way to let Hibernate communicate with the server diff --git a/src/main/java/envoy/server/database/PersistenceManager.java b/src/main/java/envoy/server/database/PersistenceManager.java index 9815ebe..0ec57d6 100644 --- a/src/main/java/envoy/server/database/PersistenceManager.java +++ b/src/main/java/envoy/server/database/PersistenceManager.java @@ -194,7 +194,9 @@ public class PersistenceManager { * @return the contacts of this User - currently everyone using Envoy * @since Envoy Server Standalone v0.1-alpha */ - public List getContacts(User user) { return entityManager.createQuery("FROM User").getResultList(); } + public List getContacts(User user) { + return entityManager.createNamedQuery("getContactsOfUser").setParameter("user", user).getResultList(); + } // TODO current solution gets all users, not just contacts. Should be changed to // entityManager.createNamedQuery("getContactsOfUser").setParameter("user", // user).getResultList();