Implemented user search response

This commit is contained in:
Kai S. K. Engelbart 2020-02-08 13:53:58 +01:00
parent 48e12dcdfe
commit 1630b3aede
5 changed files with 41 additions and 5 deletions

View File

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.github.informatik-ag-ngl</groupId> <groupId>com.github.informatik-ag-ngl</groupId>
<artifactId>envoy-common</artifactId> <artifactId>envoy-common</artifactId>
<version>develop-SNAPSHOT</version> <version>f~contacts-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.informatik-ag-ngl</groupId> <groupId>com.github.informatik-ag-ngl</groupId>

View File

@ -22,8 +22,8 @@ import javax.persistence.*;
@Table(name = "users") @Table(name = "users")
@NamedQueries( @NamedQueries(
{ @NamedQuery(query = "SELECT u FROM User u WHERE u.name = :name", name = "getUserByName"), { @NamedQuery(query = "SELECT u FROM User u WHERE u.name = :name", name = "getUserByName"),
@NamedQuery(query = "SELECT u.contacts FROM User u WHERE u = :user", name = "getContactsOfUser")// not tested @NamedQuery(query = "SELECT u.contacts FROM User u WHERE u = :user", name = "getContactsOfUser"), // not tested
} @NamedQuery(query = "SELECT u FROM User u WHERE lower(u.name) LIKE lower(:searchPhrase)", name = "searchUsers") }
) )
public class User { public class User {

View File

@ -176,6 +176,10 @@ public class PersistenceManager {
return entityManager.createNamedQuery("getUnreadMessages").setParameter("recipient", user).getResultList(); return entityManager.createNamedQuery("getUnreadMessages").setParameter("recipient", user).getResultList();
} }
public List<User> searchUsers(String searchPhrase) {
return entityManager.createNamedQuery("searchUsers").setParameter("searchPhrase", searchPhrase).getResultList();
}
/** /**
* @param user the User whose contacts should be retrieved * @param user the User whose contacts should be retrieved
* @return the contacts of this User - currently everyone using Envoy * @return the contacts of this User - currently everyone using Envoy

View File

@ -0,0 +1,33 @@
package envoy.server.processors;
import java.io.IOException;
import java.util.stream.Collectors;
import envoy.event.ContactsRequest;
import envoy.server.ObjectProcessor;
import envoy.server.database.PersistenceManager;
import envoy.server.net.ObjectWriteProxy;
/**
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>ContactsRequestProcesor.java</strong><br>
* Created: <strong>08.02.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
public class ContactsRequestProcesor implements ObjectProcessor<ContactsRequest> {
@Override
public void process(ContactsRequest request, long socketId, ObjectWriteProxy writeProxy) throws IOException {
writeProxy.write(socketId,
PersistenceManager.getPersistenceManager()
.searchUsers(request.get())
.stream()
.map(envoy.server.data.User::toCommonUser)
.collect(Collectors.toList()));
}
@Override
public Class<ContactsRequest> getInputClass() { return ContactsRequest.class; }
}

View File

@ -52,8 +52,7 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
UserStatusChangeProcessor.updateUserStatus(user); UserStatusChangeProcessor.updateUserStatus(user);
// Create contacts // Create contacts
Contacts contacts = new Contacts(user.getId(), Contacts contacts = new Contacts(user.getContacts().stream().map(envoy.server.data.User::toCommonUser).collect(Collectors.toList()));
user.getContacts().stream().map(envoy.server.data.User::toCommonUser).collect(Collectors.toList()));
contacts.getContacts().add(user.toCommonUser()); contacts.getContacts().add(user.toCommonUser());
// Complete handshake // Complete handshake