Added method to get contacts, although as of now all Users are returned
This commit is contained in:
		| @@ -8,6 +8,7 @@ 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.Table; | ||||
| import javax.persistence.Temporal; | ||||
| @@ -28,7 +29,11 @@ import javax.persistence.TemporalType; | ||||
|  */ | ||||
| @Entity | ||||
| @Table(name = "users") | ||||
| @NamedQuery(query = "SELECT u FROM User u WHERE u.id = :id", name = "getUserById") | ||||
| @NamedQueries( | ||||
| 	{ @NamedQuery(query = "SELECT u FROM User u WHERE u.id = :id", name = "getUserById"), | ||||
| 			@NamedQuery(query = "SELECT u.contacts FROM User u WHERE u = :user", name = "getContactsOfUser")// not tested | ||||
| 	} | ||||
| ) | ||||
| public class User { | ||||
|  | ||||
| 	@Id | ||||
|   | ||||
| @@ -98,7 +98,17 @@ public class PersistenceManager { | ||||
| 	 */ | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	public List<Message> getUnreadMessages(User user) { | ||||
| 		// TODO may need to be changed to clientId | ||||
| 		return entityManager.createNamedQuery("getUnreadMessages").setParameter("recipient", user).getResultList(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @param user the User whose contacts should be retrieved | ||||
| 	 * @return the contacts of this User - currently everyone using Envoy | ||||
| 	 * @since Envoy Server Standalone v0.1-alpha | ||||
| 	 */ | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	public List<User> getContacts(User user) { return entityManager.createQuery("FROM User").getResultList(); } | ||||
| 	// TODO current solution gets all users, not just contacts. Should be changed to | ||||
| 	// entityManager.createNamedQuery("getContactsOfUser").setParameter("user", | ||||
| 	// user).getResultList(); | ||||
| } | ||||
| @@ -1,9 +1,9 @@ | ||||
| package envoy.server.processors; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import envoy.data.Contacts; | ||||
| import envoy.data.LoginCredentials; | ||||
| @@ -42,7 +42,12 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential | ||||
| 		ConnectionManager.getInstance().registerUser(socketId, user.getId()); | ||||
|  | ||||
| 		// Create contacts | ||||
| 		Contacts contacts = new Contacts(user.getId(), new ArrayList<>()); | ||||
| 		List<User>	users		= PersistenceManager.getPersistenceManager() | ||||
| 			.getContacts(new envoy.server.data.User(user)) | ||||
| 			.stream() | ||||
| 			.map(envoy.server.data.User::toCommonUser) | ||||
| 			.collect(Collectors.toList()); | ||||
| 		Contacts	contacts	= new Contacts(user.getId(), users); | ||||
|  | ||||
| 		// Complete handshake | ||||
| 		System.out.println("Sending user..."); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 delvh
					delvh