Implemented user search response
This commit is contained in:
parent
48e12dcdfe
commit
1630b3aede
2
pom.xml
2
pom.xml
@ -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>
|
||||||
|
@ -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 {
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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; }
|
||||||
|
}
|
@ -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
|
||||||
|
Reference in New Issue
Block a user