From 91cc8ebbf56689e53190f33cf04e97a26ac757fb Mon Sep 17 00:00:00 2001 From: Christoph Thelen <christoph.thelen@mni.thm.de> Date: Tue, 14 May 2013 19:01:23 +0200 Subject: [PATCH] Send feedback and average feedback to new users --- .../thm/arsnova/services/SessionService.java | 1 + .../arsnova/socket/ARSnovaSocketIOServer.java | 30 ++++++++++++++++++- .../arsnova/services/SessionServiceTest.java | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index 1a4473b3..34b2b3d2 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -100,6 +100,7 @@ public class SessionService implements ISessionService { userService.addCurrentUserToSessionMap(keyword); socketIoServer.reportActiveUserCountForSession(keyword); + socketIoServer.reportFeedbackForUserInSession(session, userService.getCurrentUser()); if (connectorClient != null && session.isCourseSession()) { String courseid = session.getCourseId(); diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java index 7f0279ea..a5c377e9 100644 --- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java +++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java @@ -22,8 +22,8 @@ import com.corundumstudio.socketio.listener.ConnectListener; import com.corundumstudio.socketio.listener.DataListener; import com.corundumstudio.socketio.listener.DisconnectListener; -import de.thm.arsnova.entities.Question; import de.thm.arsnova.entities.User; +import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.services.IFeedbackService; import de.thm.arsnova.services.IQuestionService; import de.thm.arsnova.services.ISessionService; @@ -237,6 +237,34 @@ public class ARSnovaSocketIOServer { public void reportUpdatedFeedbackForSession(String sessionKey) { de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(sessionKey); broadcastInSession(sessionKey, "feedbackData", fb.getValues()); + try { + long averageFeedback = feedbackService.getAverageFeedbackRounded(sessionKey); + broadcastInSession(sessionKey, "feedbackDataRoundedAverage", averageFeedback); + } catch (NoContentException e) { + broadcastInSession(sessionKey, "feedbackDataRoundedAverage", null); + } + } + + public void reportFeedbackForUserInSession(de.thm.arsnova.entities.Session session, User user) { + de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(session.getKeyword()); + Long averageFeedback; + try { + averageFeedback = feedbackService.getAverageFeedbackRounded(session.getKeyword()); + } catch (NoContentException e) { + averageFeedback = null; + } + List<UUID> connectionIds = findConnectionIdForUser(user.getUsername()); + if (connectionIds.isEmpty()) { + return; + } + + for (SocketIOClient client : server.getAllClients()) { + if (connectionIds.contains(client.getSessionId())) { + logger.info("Sending " + user.getUsername() + " feedback data " + fb.getValues() + "."); + client.sendEvent("feedbackData", fb.getValues()); + client.sendEvent("feedbackDataRoundedAverage", averageFeedback); + } + } } public void reportActiveUserCountForSession(String sessionKey) { diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index c6ede4f8..5700c0ea 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -103,6 +103,8 @@ public class SessionServiceTest { @Test public void testShouldSaveSession() { userService.setUserAuthenticated(true); + // Prevent "NotFoundExceptions" inside StubDatabase while saving the session + databaseDao.saveFeedback("11111111", 1, userService.getCurrentUser()); Session session = new Session(); session.setActive(true); -- GitLab