diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index aac2491f7ad910290b2ec2d2e9d49a7787466108..5f7a1e7cf8a721ebcf8bb32ddbd261ab77d104e4 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -591,7 +591,7 @@ public class CouchDBDao implements IDatabaseDao { } @Override - public final boolean saveQuestion(final Session session, final InterposedQuestion question) { + public final InterposedQuestion saveQuestion(final Session session, final InterposedQuestion question) { Document q = new Document(); q.put("type", "interposed_question"); q.put("sessionId", session.get_id()); @@ -601,11 +601,15 @@ public class CouchDBDao implements IDatabaseDao { q.put("read", false); try { database.saveDocument(q); - return true; + question.set_id(q.getId()); + question.set_rev(q.getRev()); + + return question; } catch (IOException e) { LOGGER.error("Could not save interposed question {}", question); } - return false; + + return null; } @Override diff --git a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java index 88af93db896c5c5b8b63844d828bde97ae68f4d5..74a255fb19c7dd61a11268cf463dcbb4aa67ea11 100644 --- a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java +++ b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java @@ -52,7 +52,7 @@ public interface IDatabaseDao { Question saveQuestion(Session session, Question question); - boolean saveQuestion(Session session, InterposedQuestion question); + InterposedQuestion saveQuestion(Session session, InterposedQuestion question); Question getQuestion(String id); diff --git a/src/main/java/de/thm/arsnova/services/QuestionService.java b/src/main/java/de/thm/arsnova/services/QuestionService.java index e148ed21a944234f577c65c87f0233905a992620..f04ead0eb51bbdb3f6cb359f96c24df427cdcbc5 100644 --- a/src/main/java/de/thm/arsnova/services/QuestionService.java +++ b/src/main/java/de/thm/arsnova/services/QuestionService.java @@ -36,6 +36,7 @@ import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; +import de.thm.arsnova.socket.ARSnovaSocketIOServer; @Service public class QuestionService implements IQuestionService { @@ -46,6 +47,9 @@ public class QuestionService implements IQuestionService { @Autowired private IUserService userService; + @Autowired + private ARSnovaSocketIOServer socketIoServer; + public void setDatabaseDao(IDatabaseDao databaseDao) { this.databaseDao = databaseDao; } @@ -72,14 +76,20 @@ public class QuestionService implements IQuestionService { public Question saveQuestion(Question question) { Session session = this.databaseDao.getSessionFromKeyword(question.getSessionKeyword()); question.setSessionId(session.get_id()); - return this.databaseDao.saveQuestion(session, question); + Question result = this.databaseDao.saveQuestion(session, question); + socketIoServer.reportLecturerQuestionAvailable(result.getSessionKeyword(), result.get_id()); + + return result; } @Override @Authenticated public boolean saveQuestion(InterposedQuestion question) { Session session = this.databaseDao.getSessionFromKeyword(question.getSessionId()); - return this.databaseDao.saveQuestion(session, question); + InterposedQuestion result = this.databaseDao.saveQuestion(session, question); + socketIoServer.reportAudienceQuestionAvailable(result.getSessionId(), result.get_id()); + + return null != result; } @Override @@ -263,6 +273,9 @@ public class QuestionService implements IQuestionService { if (question == null) { throw new NotFoundException(); } + + socketIoServer.reportAnswersToLecturerQuestionAvailable(question.getSessionKeyword(), question.get_id()); + return this.databaseDao.saveAnswer(answer, user); } @@ -273,6 +286,10 @@ public class QuestionService implements IQuestionService { if (user == null || !user.getUsername().equals(answer.getUser())) { throw new UnauthorizedException(); } + + Question question = this.getQuestion(answer.getQuestionId()); + socketIoServer.reportAnswersToLecturerQuestionAvailable(question.getSessionKeyword(), question.get_id()); + return this.databaseDao.updateAnswer(answer); } @@ -289,5 +306,7 @@ public class QuestionService implements IQuestionService { throw new UnauthorizedException(); } this.databaseDao.deleteAnswer(answerId); + + socketIoServer.reportAnswersToLecturerQuestionAvailable(question.getSessionKeyword(), question.get_id()); } } diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java index 7712bca5669bcd80adacd9160b9057413dd50bb1..be88f17ad179d47b1b8b1936bfa30d56850d4557 100644 --- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java +++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java @@ -198,7 +198,7 @@ public class ARSnovaSocketIOServer { // Find the client whose feedback has been deleted and send a // message. if (connectionIds.contains(client.getSessionId())) { - client.sendEvent("removedFeedback", arsSessions); + client.sendEvent("feedbackReset", arsSessions); } } } @@ -221,14 +221,14 @@ public class ARSnovaSocketIOServer { * @param client */ public void reportSessionDataToClient(String sessionKey, SocketIOClient client) { - client.sendEvent("updateActiveUserCount", userService.getUsersInSessionCount(sessionKey)); + client.sendEvent("activeUserCountData", userService.getUsersInSessionCount(sessionKey)); de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(sessionKey); - client.sendEvent("updateFeedback", fb.getValues()); + client.sendEvent("feedbackData", fb.getValues()); } public void reportUpdatedFeedbackForSession(String sessionKey) { de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(sessionKey); - broadcastInSession(sessionKey, "updateFeedback", fb.getValues()); + broadcastInSession(sessionKey, "feedbackData", fb.getValues()); } public void reportActiveUserCountForSession(String sessionKey) { @@ -239,10 +239,25 @@ public class ARSnovaSocketIOServer { } lastActiveUserCount = count; - broadcastInSession(sessionKey, "updateActiveUserCount", count); + broadcastInSession(sessionKey, "activeUserCountData", count); + } + + public void reportAnswersToLecturerQuestionAvailable(String sessionKey, String lecturerQuestionId) { + broadcastInSession(sessionKey, "answersToLecQuestionAvail", lecturerQuestionId); + } + + public void reportAudienceQuestionAvailable(String sessionKey, String audienceQuestionId) { + /* TODO role handling implementation, send this only to users with role lecturer */ + broadcastInSession(sessionKey, "audQuestionAvail", audienceQuestionId); + } + + public void reportLecturerQuestionAvailable(String sessionKey, String lecturerQuestionId) { + /* TODO role handling implementation, send this only to users with role audience */ + broadcastInSession(sessionKey, "lecQuestionAvail", lecturerQuestionId); } public void broadcastInSession(String sessionKey, String eventName, Object data) { + /* TODO role handling implementation */ logger.info("Broadcasting " + eventName + " for session " + sessionKey + "."); /**