From b4a5435b5f62d3c27d91eb44d09fc60bf7b1b90d Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 8 Feb 2020 14:27:21 +0100 Subject: [PATCH] Fixed user search --- src/main/java/envoy/server/Startup.java | 8 +++++++- .../java/envoy/server/database/PersistenceManager.java | 2 +- .../envoy/server/processors/ContactsRequestProcesor.java | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index 8ccbe5e..f4e5bc7 100644 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -10,7 +10,12 @@ import envoy.server.data.ConfigItem; import envoy.server.database.PersistenceManager; import envoy.server.net.ObjectMessageProcessor; import envoy.server.net.ObjectMessageReader; -import envoy.server.processors.*; +import envoy.server.processors.ContactsRequestProcesor; +import envoy.server.processors.IdGeneratorRequestProcessor; +import envoy.server.processors.LoginCredentialProcessor; +import envoy.server.processors.MessageProcessor; +import envoy.server.processors.MessageStatusChangeProcessor; +import envoy.server.processors.UserStatusChangeProcessor; /** * Starts the server.
@@ -38,6 +43,7 @@ public class Startup { processors.add(new MessageStatusChangeProcessor()); processors.add(new UserStatusChangeProcessor()); processors.add(new IdGeneratorRequestProcessor()); + processors.add(new ContactsRequestProcesor()); Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors)); initializeCurrentMessageId(); diff --git a/src/main/java/envoy/server/database/PersistenceManager.java b/src/main/java/envoy/server/database/PersistenceManager.java index 32a5219..91c7b19 100644 --- a/src/main/java/envoy/server/database/PersistenceManager.java +++ b/src/main/java/envoy/server/database/PersistenceManager.java @@ -177,7 +177,7 @@ public class PersistenceManager { } public List searchUsers(String searchPhrase) { - return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase).getResultList(); + return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase + "%").getResultList(); } /** diff --git a/src/main/java/envoy/server/processors/ContactsRequestProcesor.java b/src/main/java/envoy/server/processors/ContactsRequestProcesor.java index 7757345..13bda86 100644 --- a/src/main/java/envoy/server/processors/ContactsRequestProcesor.java +++ b/src/main/java/envoy/server/processors/ContactsRequestProcesor.java @@ -3,6 +3,7 @@ package envoy.server.processors; import java.io.IOException; import java.util.stream.Collectors; +import envoy.data.Contacts; import envoy.event.ContactsRequest; import envoy.server.ObjectProcessor; import envoy.server.database.PersistenceManager; @@ -21,11 +22,11 @@ public class ContactsRequestProcesor implements ObjectProcessor @Override public void process(ContactsRequest request, long socketId, ObjectWriteProxy writeProxy) throws IOException { writeProxy.write(socketId, - PersistenceManager.getPersistenceManager() + new Contacts(PersistenceManager.getPersistenceManager() .searchUsers(request.get()) .stream() .map(envoy.server.data.User::toCommonUser) - .collect(Collectors.toList())); + .collect(Collectors.toList()))); } @Override