diff --git a/src/main/java/de/thm/arsnova/controller/SessionController.java b/src/main/java/de/thm/arsnova/controller/SessionController.java index 7b9e1bdb321671eca85ba7ec1ef9ed4e7edd45a0..d1e4f32c306487054a7eca4f84e60861c5bd364d 100644 --- a/src/main/java/de/thm/arsnova/controller/SessionController.java +++ b/src/main/java/de/thm/arsnova/controller/SessionController.java @@ -334,6 +334,17 @@ public class SessionController extends PaginationController { return sessionService.changeSessionFeatures(sessionkey, features); } + @RequestMapping(value = "/{sessionkey}/lockfeedbackinput", method = RequestMethod.POST) + @ApiOperation(value = "locks input of user live feedback", + nickname = "lockFeedbackInput") + public boolean lockFeedbackInput( + @ApiParam(value = "session-key from current session", required = true) @PathVariable final String sessionkey, + @ApiParam(value="lock", required=true) @RequestParam(required = true) final Boolean lock, + @ApiParam(value = "http servlet response", required = true) final HttpServletResponse response + ) { + return sessionService.lockFeedbackInput(sessionkey, lock); + } + /* internal redirections */ @RequestMapping(value = "/{sessionKey}/lecturerquestion") diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index a9385e8ee8e55d7a7c24a39bdadf7e4c9488aa3d..153319dc7d0e77914a5c9b53195f95c72ca3c06b 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -488,6 +488,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware sessionDocument.put("ppLevel", session.getPpLevel()); sessionDocument.put("sessionType", session.getSessionType()); sessionDocument.put("features", JSONObject.fromObject(session.getFeatures())); + sessionDocument.put("feedbackLock", false); try { database.saveDocument(sessionDocument); } catch (final IOException e) { @@ -1549,6 +1550,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware s.put("ppLevel", session.getPpLevel()); s.put("learningProgressOptions", JSONObject.fromObject(session.getLearningProgressOptions())); s.put("features", JSONObject.fromObject(session.getFeatures())); + s.put("feedbackLock", session.getFeedbackLock()); database.saveDocument(s); session.set_rev(s.getRev()); diff --git a/src/main/java/de/thm/arsnova/entities/Session.java b/src/main/java/de/thm/arsnova/entities/Session.java index eeb11981381b165706759f4a953d8b3d008c1679..a681dc2ab33e39e3e39c97e14f366c834a14b0ab 100644 --- a/src/main/java/de/thm/arsnova/entities/Session.java +++ b/src/main/java/de/thm/arsnova/entities/Session.java @@ -56,6 +56,7 @@ public class Session implements Serializable { private String ppFaculty; private String ppLevel; private String sessionType; + private boolean feedbackLock; private String _id; private String _rev; @@ -90,6 +91,7 @@ public class Session implements Serializable { copy.ppFaculty = original.ppFaculty; copy.ppLevel = original.ppLevel; copy.sessionType = original.sessionType; + copy.feedbackLock = original.feedbackLock; copy._id = original._id; copy._rev = original._rev; @@ -329,6 +331,15 @@ public class Session implements Serializable { this.sessionType = sessionType; } + @ApiModelProperty(required = true, value = "the feedback lock status") + public boolean getFeedbackLock() { + return feedbackLock; + } + + public void setFeedbackLock(Boolean lock) { + this.feedbackLock = lock; + } + @Override public String toString() { return "Session [keyword=" + keyword + ", type=" + type + ", creator=" + creator + "]"; diff --git a/src/main/java/de/thm/arsnova/services/FeedbackService.java b/src/main/java/de/thm/arsnova/services/FeedbackService.java index 03112362a8f0eaaab6536dfbfd9c2290417c4ce5..0d48aaad14a726fd569d7f5b24592992df69beb8 100644 --- a/src/main/java/de/thm/arsnova/services/FeedbackService.java +++ b/src/main/java/de/thm/arsnova/services/FeedbackService.java @@ -109,6 +109,21 @@ public class FeedbackService implements IFeedbackService, ApplicationEventPublis } } + @Override + public void cleanFeedbackVotesInSession(final String keyword, final int cleanupFeedbackDelayInMins) { + final Session session = databaseDao.getSessionFromKeyword(keyword); + List<User> affectedUsers = feedbackStorage.cleanFeedbackVotesInSession(session, cleanupFeedbackDelayInMins); + Set<Session> sessionSet = new HashSet<Session>(); + sessionSet.add(session); + + // Send feedback reset event to all affected users + for (User user : affectedUsers) { + this.publisher.publishEvent(new DeleteFeedbackForSessionsEvent(this, sessionSet, user)); + } + // send the new feedback to all clients in affected session + this.publisher.publishEvent(new NewFeedbackEvent(this, session)); + } + @Override public Feedback getFeedback(final String keyword) { final Session session = databaseDao.getSessionFromKeyword(keyword); diff --git a/src/main/java/de/thm/arsnova/services/IFeedbackService.java b/src/main/java/de/thm/arsnova/services/IFeedbackService.java index 407f323fddaf8966b5182c335c01150cfbb18913..ef87c5fec9cc3b79dabdfa228d5813c36638ca83 100644 --- a/src/main/java/de/thm/arsnova/services/IFeedbackService.java +++ b/src/main/java/de/thm/arsnova/services/IFeedbackService.java @@ -26,6 +26,8 @@ import de.thm.arsnova.entities.User; public interface IFeedbackService { void cleanFeedbackVotes(); + void cleanFeedbackVotesInSession(String keyword, int cleanupFeedbackDelayInMins); + Feedback getFeedback(String keyword); int getFeedbackCount(String keyword); diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java index 22ccbf90bbe1ad60ffaaa685852c5b0645135986..fa405d819138bb958af1ec7f6cec674a740ebc9b 100644 --- a/src/main/java/de/thm/arsnova/services/ISessionService.java +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -77,4 +77,6 @@ public interface ISessionService { SessionFeature getSessionFeatures(String sessionkey); SessionFeature changeSessionFeatures(String sessionkey, SessionFeature features); + + boolean lockFeedbackInput(String sessionkey, Boolean lock); } diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index a2df7abf69a6a15da18c673733decee40073d0d3..e9e14221e8317e6b97f495cdadf0dda599d76a1f 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -48,6 +48,7 @@ import de.thm.arsnova.entities.transport.ImportExportSession; import de.thm.arsnova.entities.transport.LearningProgressValues; import de.thm.arsnova.events.DeleteSessionEvent; import de.thm.arsnova.events.FeatureChangeEvent; +import de.thm.arsnova.events.LockFeedbackEvent; import de.thm.arsnova.events.NewSessionEvent; import de.thm.arsnova.events.StatusSessionEvent; import de.thm.arsnova.exceptions.BadRequestException; @@ -104,6 +105,9 @@ public class SessionService implements ISessionService, ApplicationEventPublishe @Autowired private IUserService userService; + @Autowired + private IFeedbackService feedbackService; + @Autowired private ILearningProgressFactory learningProgressFactory; @@ -316,7 +320,8 @@ public class SessionService implements ISessionService, ApplicationEventPublishe existingSession.setPpLevel(session.getPpLevel()); existingSession.setPpLicense(session.getPpLicense()); existingSession.setPpSubject(session.getPpSubject()); - + existingSession.setFeedbackLock(session.getFeedbackLock()); + handleLogo(session); existingSession.setPpLogo(session.getPpLogo()); @@ -421,7 +426,23 @@ public class SessionService implements ISessionService, ApplicationEventPublishe this.publisher.publishEvent(new FeatureChangeEvent(this, session)); return databaseDao.updateSession(session).getFeatures(); } - + + @Override + public boolean lockFeedbackInput(String sessionkey, Boolean lock) { + final Session session = databaseDao.getSessionFromKeyword(sessionkey); + final User user = userService.getCurrentUser(); + if (!session.isCreator(user)) { + throw new UnauthorizedException(); + } + if (!lock) { + feedbackService.cleanFeedbackVotesInSession(sessionkey, 0); + } + + session.setFeedbackLock(lock); + this.publisher.publishEvent(new LockFeedbackEvent(this, session)); + return databaseDao.updateSession(session).getFeedbackLock(); + } + /** * * @param session