diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index 9215e163b91ce193810082d2e0f36cb3b6ca321a..2d8068b9719e4e055493017426033c38701f02b4 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -436,10 +436,6 @@ public class CouchDBDao implements IDatabaseDao { return null; } - private String currentTimestamp() { - return Long.toString(System.currentTimeMillis()); - } - private String actualUserName() { User user = userService.getCurrentUser(); if (user == null) @@ -653,8 +649,11 @@ public class CouchDBDao implements IDatabaseDao { Document question = this.getDatabase().getDocument(questionId); this.getDatabase().deleteDocument(question); - } catch(Exception e) { - logger.error("Could not delete question and its answers with id {}", questionId); + } catch(IOException e) { + logger.error( + "IOException: Could not delete question and its answers with id {}. Connection to CouchDB available?", + questionId + ); } } diff --git a/src/main/java/de/thm/arsnova/services/UserService.java b/src/main/java/de/thm/arsnova/services/UserService.java index 075e85cd3a75d8516db2d4dc8f8d2b88347b5a66..544874328872613cd5fd8a6f9926200fc9d46ec3 100644 --- a/src/main/java/de/thm/arsnova/services/UserService.java +++ b/src/main/java/de/thm/arsnova/services/UserService.java @@ -36,19 +36,16 @@ import com.github.leleuj.ss.oauth.client.authentication.OAuthAuthenticationToken import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.UnauthorizedException; -public class UserService implements IUserService, InitializingBean, - DisposableBean { +public class UserService implements IUserService, InitializingBean, DisposableBean { - public static final Logger logger = LoggerFactory - .getLogger(UserService.class); + public static final Logger logger = LoggerFactory.getLogger(UserService.class); private static final ConcurrentHashMap<UUID, User> socketid2user = new ConcurrentHashMap<UUID, User>(); private static final ConcurrentHashMap<String, String> user2session = new ConcurrentHashMap<String, String>(); @Override public User getCurrentUser() { - Authentication authentication = SecurityContextHolder.getContext() - .getAuthentication(); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || authentication.getPrincipal() == null) { return null; } @@ -58,16 +55,13 @@ public class UserService implements IUserService, InitializingBean, if (authentication instanceof OAuthAuthenticationToken) { OAuthAuthenticationToken token = (OAuthAuthenticationToken) authentication; if (token.getUserProfile() instanceof Google2Profile) { - Google2Profile profile = (Google2Profile) token - .getUserProfile(); + Google2Profile profile = (Google2Profile) token.getUserProfile(); user = new User(profile); } else if (token.getUserProfile() instanceof TwitterProfile) { - TwitterProfile profile = (TwitterProfile) token - .getUserProfile(); + TwitterProfile profile = (TwitterProfile) token.getUserProfile(); user = new User(profile); } else if (token.getUserProfile() instanceof FacebookProfile) { - FacebookProfile profile = (FacebookProfile) token - .getUserProfile(); + FacebookProfile profile = (FacebookProfile) token.getUserProfile(); user = new User(profile); } } else if (authentication instanceof CasAuthenticationToken) { @@ -150,14 +144,11 @@ public class UserService implements IUserService, InitializingBean, if (!store.exists()) { return; } - ObjectInputStream ois = new ObjectInputStream(new FileInputStream( - store)); - Hashtable<String, Map<?, ?>> map = (Hashtable<String, Map<?, ?>>) ois - .readObject(); + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(store)); + Hashtable<String, Map<?, ?>> map = (Hashtable<String, Map<?, ?>>) ois.readObject(); ois.close(); Map<UUID, User> s2u = (Map<UUID, User>) map.get("socketid2user"); - Map<String, String> u2s = (Map<String, String>) map - .get("user2session"); + Map<String, String> u2s = (Map<String, String>) map.get("user2session"); logger.info("load from store: {}", map); @@ -167,8 +158,7 @@ public class UserService implements IUserService, InitializingBean, } catch (IOException e) { logger.error("IOException during restoring UserService", e); } catch (ClassNotFoundException e) { - logger.error("ClassNotFoundException during restoring UserService", - e); + logger.error("ClassNotFoundException during restoring UserService", e); } } @@ -182,7 +172,9 @@ public class UserService implements IUserService, InitializingBean, File tmpDir = new File(System.getProperty("java.io.tmpdir")); File store = new File(tmpDir, "arsnova.bin"); if (!store.exists()) { - store.createNewFile(); + if (! store.createNewFile()) { + logger.info("Could not create store file"); + } } OutputStream file = new FileOutputStream(store); ObjectOutputStream objOut = new ObjectOutputStream(file); diff --git a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java index 8cf20ed56e4a919291c40ddc3c06f5b10f172528..7b19d5f8c8efc0b047b9ba781a22ccf81ed09422 100644 --- a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java @@ -85,4 +85,16 @@ public class FeedbackControllerTest { assertTrue(response.getStatus() == 200); assertEquals("0", response.getContentAsString()); } + + @Test + public void testShouldReturnFeedback() throws Exception { + userService.setUserAuthenticated(true); + + request.setMethod("GET"); + request.setRequestURI("/session/87654321/feedback"); + handlerAdapter.handle(request, response, feedbackController); + + assertTrue(response.getStatus() == 200); + assertEquals("{\"values\":[2,3,5,7]}", response.getContentAsString()); + } } diff --git a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java index ce228e655522c80bd159909fd9d7e78dbc5d09f6..8e2c33587cdc3b01663562fc9765c18cfb206693 100644 --- a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java @@ -27,7 +27,8 @@ import de.thm.arsnova.services.StubUserService; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", - "file:src/test/resources/test-config.xml" }) + "file:src/test/resources/test-config.xml" +}) public class SessionControllerTest { @Inject