Skip to content
Snippets Groups Projects
Commit fb81028f authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Added Socket.IO solution to inform clients about new AudienceQuestions,

LecturerQuestions and Answers to LecturerQuestions.
Renamed events concerning feedback for consistency.
parent 0161167e
No related merge requests found
...@@ -591,7 +591,7 @@ public class CouchDBDao implements IDatabaseDao { ...@@ -591,7 +591,7 @@ public class CouchDBDao implements IDatabaseDao {
} }
@Override @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(); Document q = new Document();
q.put("type", "interposed_question"); q.put("type", "interposed_question");
q.put("sessionId", session.get_id()); q.put("sessionId", session.get_id());
...@@ -601,11 +601,15 @@ public class CouchDBDao implements IDatabaseDao { ...@@ -601,11 +601,15 @@ public class CouchDBDao implements IDatabaseDao {
q.put("read", false); q.put("read", false);
try { try {
database.saveDocument(q); database.saveDocument(q);
return true; question.set_id(q.getId());
question.set_rev(q.getRev());
return question;
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Could not save interposed question {}", question); LOGGER.error("Could not save interposed question {}", question);
} }
return false;
return null;
} }
@Override @Override
......
...@@ -52,7 +52,7 @@ public interface IDatabaseDao { ...@@ -52,7 +52,7 @@ public interface IDatabaseDao {
Question saveQuestion(Session session, Question question); Question saveQuestion(Session session, Question question);
boolean saveQuestion(Session session, InterposedQuestion question); InterposedQuestion saveQuestion(Session session, InterposedQuestion question);
Question getQuestion(String id); Question getQuestion(String id);
......
...@@ -36,6 +36,7 @@ import de.thm.arsnova.entities.User; ...@@ -36,6 +36,7 @@ import de.thm.arsnova.entities.User;
import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.exceptions.NoContentException;
import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.exceptions.UnauthorizedException; import de.thm.arsnova.exceptions.UnauthorizedException;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
@Service @Service
public class QuestionService implements IQuestionService { public class QuestionService implements IQuestionService {
...@@ -46,6 +47,9 @@ public class QuestionService implements IQuestionService { ...@@ -46,6 +47,9 @@ public class QuestionService implements IQuestionService {
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired
private ARSnovaSocketIOServer socketIoServer;
public void setDatabaseDao(IDatabaseDao databaseDao) { public void setDatabaseDao(IDatabaseDao databaseDao) {
this.databaseDao = databaseDao; this.databaseDao = databaseDao;
} }
...@@ -72,14 +76,20 @@ public class QuestionService implements IQuestionService { ...@@ -72,14 +76,20 @@ public class QuestionService implements IQuestionService {
public Question saveQuestion(Question question) { public Question saveQuestion(Question question) {
Session session = this.databaseDao.getSessionFromKeyword(question.getSessionKeyword()); Session session = this.databaseDao.getSessionFromKeyword(question.getSessionKeyword());
question.setSessionId(session.get_id()); 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 @Override
@Authenticated @Authenticated
public boolean saveQuestion(InterposedQuestion question) { public boolean saveQuestion(InterposedQuestion question) {
Session session = this.databaseDao.getSessionFromKeyword(question.getSessionId()); 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 @Override
...@@ -263,6 +273,9 @@ public class QuestionService implements IQuestionService { ...@@ -263,6 +273,9 @@ public class QuestionService implements IQuestionService {
if (question == null) { if (question == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
socketIoServer.reportAnswersToLecturerQuestionAvailable(question.getSessionKeyword(), question.get_id());
return this.databaseDao.saveAnswer(answer, user); return this.databaseDao.saveAnswer(answer, user);
} }
...@@ -273,6 +286,10 @@ public class QuestionService implements IQuestionService { ...@@ -273,6 +286,10 @@ public class QuestionService implements IQuestionService {
if (user == null || !user.getUsername().equals(answer.getUser())) { if (user == null || !user.getUsername().equals(answer.getUser())) {
throw new UnauthorizedException(); throw new UnauthorizedException();
} }
Question question = this.getQuestion(answer.getQuestionId());
socketIoServer.reportAnswersToLecturerQuestionAvailable(question.getSessionKeyword(), question.get_id());
return this.databaseDao.updateAnswer(answer); return this.databaseDao.updateAnswer(answer);
} }
...@@ -289,5 +306,7 @@ public class QuestionService implements IQuestionService { ...@@ -289,5 +306,7 @@ public class QuestionService implements IQuestionService {
throw new UnauthorizedException(); throw new UnauthorizedException();
} }
this.databaseDao.deleteAnswer(answerId); this.databaseDao.deleteAnswer(answerId);
socketIoServer.reportAnswersToLecturerQuestionAvailable(question.getSessionKeyword(), question.get_id());
} }
} }
...@@ -198,7 +198,7 @@ public class ARSnovaSocketIOServer { ...@@ -198,7 +198,7 @@ public class ARSnovaSocketIOServer {
// Find the client whose feedback has been deleted and send a // Find the client whose feedback has been deleted and send a
// message. // message.
if (connectionIds.contains(client.getSessionId())) { if (connectionIds.contains(client.getSessionId())) {
client.sendEvent("removedFeedback", arsSessions); client.sendEvent("feedbackReset", arsSessions);
} }
} }
} }
...@@ -221,14 +221,14 @@ public class ARSnovaSocketIOServer { ...@@ -221,14 +221,14 @@ public class ARSnovaSocketIOServer {
* @param client * @param client
*/ */
public void reportSessionDataToClient(String sessionKey, SocketIOClient 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); de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(sessionKey);
client.sendEvent("updateFeedback", fb.getValues()); client.sendEvent("feedbackData", fb.getValues());
} }
public void reportUpdatedFeedbackForSession(String sessionKey) { public void reportUpdatedFeedbackForSession(String sessionKey) {
de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(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) { public void reportActiveUserCountForSession(String sessionKey) {
...@@ -239,10 +239,25 @@ public class ARSnovaSocketIOServer { ...@@ -239,10 +239,25 @@ public class ARSnovaSocketIOServer {
} }
lastActiveUserCount = count; 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) { public void broadcastInSession(String sessionKey, String eventName, Object data) {
/* TODO role handling implementation */
logger.info("Broadcasting " + eventName + " for session " + sessionKey + "."); logger.info("Broadcasting " + eventName + " for session " + sessionKey + ".");
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment