From 890f49afcb7364d50454a12c494e4276bdc26075 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <code@dgerhardt.net> Date: Sun, 24 Aug 2014 11:45:45 +0200 Subject: [PATCH] Remove session joining via HTTP and online ping --- .../arsnova/controller/SessionController.java | 10 +------- .../thm/arsnova/services/ISessionService.java | 4 +--- .../thm/arsnova/services/SessionService.java | 24 +------------------ .../controller/SessionControllerTest.java | 8 ------- .../arsnova/services/SessionServiceTest.java | 8 +++---- 5 files changed, 7 insertions(+), 47 deletions(-) diff --git a/src/main/java/de/thm/arsnova/controller/SessionController.java b/src/main/java/de/thm/arsnova/controller/SessionController.java index 5e8f03fa8..b54df6d52 100644 --- a/src/main/java/de/thm/arsnova/controller/SessionController.java +++ b/src/main/java/de/thm/arsnova/controller/SessionController.java @@ -42,7 +42,6 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import de.thm.arsnova.connector.model.Course; -import de.thm.arsnova.entities.LoggedIn; import de.thm.arsnova.entities.Session; import de.thm.arsnova.exceptions.UnauthorizedException; import de.thm.arsnova.services.ISessionService; @@ -65,7 +64,7 @@ public class SessionController extends AbstractController { @RequestMapping(value = "/{sessionkey}", method = RequestMethod.GET) public final Session joinSession(@PathVariable final String sessionkey) { - final Session session = sessionService.joinSession(sessionkey); + final Session session = sessionService.getSession(sessionkey); if (! session.getCreator().equals(userService.getCurrentUser().getUsername())) { session.setCreator("NOT VISIBLE TO YOU"); } else { @@ -79,13 +78,6 @@ public class SessionController extends AbstractController { sessionService.deleteSession(sessionkey); } - @DeprecatedApi - @RequestMapping(value = "/{sessionkey}/online", method = RequestMethod.POST) - @ResponseStatus(HttpStatus.CREATED) - public final LoggedIn registerAsOnlineUser(@PathVariable final String sessionkey) { - return sessionService.registerAsOnlineUser(sessionkey); - } - @DeprecatedApi @RequestMapping(value = "/{sessionkey}/activeusercount", method = RequestMethod.GET) public final int countActiveUsers(@PathVariable final String sessionkey) { diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java index 20e40d828..16faadd4a 100644 --- a/src/main/java/de/thm/arsnova/services/ISessionService.java +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -28,7 +28,7 @@ import de.thm.arsnova.entities.LoggedIn; import de.thm.arsnova.entities.Session; public interface ISessionService { - Session joinSession(String keyword); + Session getSession(String keyword); Session saveSession(Session session); @@ -40,8 +40,6 @@ public interface ISessionService { List<Session> getMyVisitedSessions(); - LoggedIn registerAsOnlineUser(String sessionkey); - int countSessions(List<Course> courses); int activeUsers(String sessionkey); diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index d2742c182..a00c4e448 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -35,7 +35,6 @@ import org.springframework.stereotype.Service; import de.thm.arsnova.connector.client.ConnectorClient; import de.thm.arsnova.connector.model.Course; import de.thm.arsnova.dao.IDatabaseDao; -import de.thm.arsnova.entities.LoggedIn; import de.thm.arsnova.entities.Question; import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.User; @@ -116,9 +115,7 @@ public class SessionService implements ISessionService { @Override @PreAuthorize("isAuthenticated()") - public final Session joinSession(final String keyword) { - /* HTTP polling solution (legacy) */ - + public final Session getSession(final String keyword) { final User user = userService.getCurrentUser(); final Session session = databaseDao.getSessionFromKeyword(keyword); if (session == null) { @@ -132,10 +129,6 @@ public class SessionService implements ISessionService { } } - userService.addCurrentUserToSessionMap(keyword); - socketIoServer.reportActiveUserCountForSession(keyword); - socketIoServer.reportFeedbackForUserInSession(session, userService.getCurrentUser()); - if (connectorClient != null && session.isCourseSession()) { final String courseid = session.getCourseId(); if (!connectorClient.getMembership(userService.getCurrentUser().getUsername(), courseid).isMember()) { @@ -206,21 +199,6 @@ public class SessionService implements ISessionService { return generateKeyword(); } - @Override - public final LoggedIn registerAsOnlineUser(final String sessionkey) { - /* HTTP polling solution (legacy) */ - - final Session session = this.joinSession(sessionkey); - if (session == null) { - throw new NotFoundException(); - } - if (session.getCreator().equals(userService.getCurrentUser().getUsername())) { - databaseDao.updateSessionOwnerActivity(session); - } - - return databaseDao.registerAsOnlineUser(userService.getCurrentUser(), session); - } - @Override public int countSessions(final List<Course> courses) { final List<Session> sessions = databaseDao.getCourseSessions(courses); diff --git a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java index 4860c0746..76ca780e0 100644 --- a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java @@ -147,14 +147,6 @@ public class SessionControllerTest { .andExpect(header().string(AbstractController.X_DEPRECATED_API, "1")); } - @Test - public void testShouldEndInUnauthorizedResult() throws Exception { - setAuthenticated(false, "ptsr00"); - - mockMvc.perform(post("/session/12345678/online").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isUnauthorized()); - } - @Test public void testShouldEndInForbidden() throws Exception { setAuthenticated(true, "ptsr00"); diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index 09c07f185..d3a721140 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -103,13 +103,13 @@ public class SessionServiceTest { @Test(expected = NotFoundException.class) public void testShouldNotFindNonExistantSession() { setAuthenticated(true, "ptsr00"); - sessionService.joinSession("00000000"); + sessionService.getSession("00000000"); } @Test(expected = AuthenticationCredentialsNotFoundException.class) public void testShouldNotReturnSessionIfUnauthorized() { setAuthenticated(false, null); - sessionService.joinSession("12345678"); + sessionService.getSession("12345678"); } @Test(expected = AuthenticationCredentialsNotFoundException.class) @@ -126,7 +126,7 @@ public class SessionServiceTest { setAuthenticated(true, "ptsr00"); - assertNull(sessionService.joinSession("11111111")); + assertNull(sessionService.getSession("11111111")); } @Test @@ -140,7 +140,7 @@ public class SessionServiceTest { session.setName("TestSessionX"); session.setShortName("TSX"); sessionService.saveSession(session); - assertNotNull(sessionService.joinSession("11111111")); + assertNotNull(sessionService.getSession("11111111")); } @Test(expected = AccessDeniedException.class) -- GitLab