From 2784eafdb69b8b9e2410960c401b5b88a8b0b286 Mon Sep 17 00:00:00 2001
From: Daniel Gerhardt <daniel.gerhardt@mni.thm.de>
Date: Fri, 8 Mar 2013 02:21:02 +0100
Subject: [PATCH] Updated getSessionForUser method in UserService for Socket.IO
 implementation updates.

---
 .../java/de/thm/arsnova/services/UserService.java    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main/java/de/thm/arsnova/services/UserService.java b/src/main/java/de/thm/arsnova/services/UserService.java
index 6fa6e45f..b2e0dcdb 100644
--- a/src/main/java/de/thm/arsnova/services/UserService.java
+++ b/src/main/java/de/thm/arsnova/services/UserService.java
@@ -140,6 +140,7 @@ public class UserService implements IUserService, InitializingBean, DisposableBe
 		User user = getCurrentUser();
 		if (user == null)
 			throw new UnauthorizedException();
+		LOGGER.info("Mapping user " + user.getUsername() + " to session " + keyword + " [legacy].");
 		user2sessionLegacy.put(user, keyword);
 	}
 
@@ -147,6 +148,7 @@ public class UserService implements IUserService, InitializingBean, DisposableBe
 	@Transactional(isolation = Isolation.READ_COMMITTED)
 	public void addUserToSessionBySocketId(UUID socketId, String keyword) {
 		User user = socketid2user.get(socketId);
+		LOGGER.info("Mapping user " + user.getUsername() + " to session " + keyword + ".");
 		user2session.put(user, keyword);
 	}
 
@@ -158,9 +160,17 @@ public class UserService implements IUserService, InitializingBean, DisposableBe
 
 	@Override
 	public String getSessionForUser(String username) {
+		for (Entry<User, String> entry  : user2session.entrySet()) {
+			if (entry.getKey().getUsername().equals(username)) {
+				return entry.getValue();
+			}
+		}
 		for (Entry<User, String> entry  : user2sessionLegacy.entrySet()) {
-			if (entry.getKey().getUsername().equals(username)) return entry.getValue();
+			if (entry.getKey().getUsername().equals(username)) {
+				return entry.getValue();
+			}
 		}
+
 		return null;
 	}
 	
-- 
GitLab