From 68466c7fa2e1854f2e28dd04f1741292cbb12f6d Mon Sep 17 00:00:00 2001 From: Christoph Thelen <christoph.thelen@mni.thm.de> Date: Mon, 11 May 2015 12:32:50 +0200 Subject: [PATCH] Add UnlockQuestionEvent, DeleteAllQuestionsEvent These events add more detail about what specific action just happened. --- .../java/de/thm/arsnova/dao/CacheBuster.java | 8 ++++ .../domain/LearningProgressFactory.java | 14 ++++++ .../events/DeleteAllQuestionsEvent.java | 35 +++++++++++++++ .../arsnova/events/DeleteQuestionEvent.java | 10 ++++- .../thm/arsnova/events/NovaEventVisitor.java | 4 ++ .../arsnova/events/UnlockQuestionEvent.java | 43 +++++++++++++++++++ .../thm/arsnova/services/QuestionService.java | 10 +++-- .../arsnova/socket/ARSnovaSocketIOServer.java | 15 ++++++- 8 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/thm/arsnova/events/DeleteAllQuestionsEvent.java create mode 100644 src/main/java/de/thm/arsnova/events/UnlockQuestionEvent.java diff --git a/src/main/java/de/thm/arsnova/dao/CacheBuster.java b/src/main/java/de/thm/arsnova/dao/CacheBuster.java index cd9cc80a..f767ca21 100644 --- a/src/main/java/de/thm/arsnova/dao/CacheBuster.java +++ b/src/main/java/de/thm/arsnova/dao/CacheBuster.java @@ -24,6 +24,7 @@ import de.thm.arsnova.events.ChangeLearningProgressEvent; import de.thm.arsnova.events.DeleteAllLectureAnswersEvent; import de.thm.arsnova.events.DeleteAllPreparationAnswersEvent; import de.thm.arsnova.events.DeleteAllQuestionsAnswersEvent; +import de.thm.arsnova.events.DeleteAllQuestionsEvent; import de.thm.arsnova.events.DeleteAnswerEvent; import de.thm.arsnova.events.DeleteFeedbackForSessionsEvent; import de.thm.arsnova.events.DeleteInterposedQuestionEvent; @@ -36,6 +37,7 @@ import de.thm.arsnova.events.NewAnswerEvent; import de.thm.arsnova.events.NewFeedbackEvent; import de.thm.arsnova.events.NewInterposedQuestionEvent; import de.thm.arsnova.events.NewQuestionEvent; +import de.thm.arsnova.events.UnlockQuestionEvent; import de.thm.arsnova.events.UnlockQuestionsEvent; import de.thm.arsnova.events.NewSessionEvent; import de.thm.arsnova.events.NovaEventVisitor; @@ -63,6 +65,9 @@ public class CacheBuster implements ICacheBuster, NovaEventVisitor { @Override public void visit(NewQuestionEvent event) {} + @Override + public void visit(UnlockQuestionEvent event) {} + @Override public void visit(UnlockQuestionsEvent newQuestionsEvent) {} @@ -82,6 +87,9 @@ public class CacheBuster implements ICacheBuster, NovaEventVisitor { @Override public void visit(DeleteQuestionEvent event) {} + @Override + public void visit(DeleteAllQuestionsEvent event) {} + @Override public void visit(DeleteAllQuestionsAnswersEvent event) {} diff --git a/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java b/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java index 198ae7d5..eb12fa9b 100644 --- a/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java +++ b/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java @@ -28,6 +28,7 @@ import de.thm.arsnova.events.ChangeLearningProgressEvent; import de.thm.arsnova.events.DeleteAllLectureAnswersEvent; import de.thm.arsnova.events.DeleteAllPreparationAnswersEvent; import de.thm.arsnova.events.DeleteAllQuestionsAnswersEvent; +import de.thm.arsnova.events.DeleteAllQuestionsEvent; import de.thm.arsnova.events.DeleteAnswerEvent; import de.thm.arsnova.events.DeleteFeedbackForSessionsEvent; import de.thm.arsnova.events.DeleteInterposedQuestionEvent; @@ -40,6 +41,7 @@ import de.thm.arsnova.events.NewAnswerEvent; import de.thm.arsnova.events.NewFeedbackEvent; import de.thm.arsnova.events.NewInterposedQuestionEvent; import de.thm.arsnova.events.NewQuestionEvent; +import de.thm.arsnova.events.UnlockQuestionEvent; import de.thm.arsnova.events.UnlockQuestionsEvent; import de.thm.arsnova.events.NewSessionEvent; import de.thm.arsnova.events.NovaEventVisitor; @@ -81,6 +83,12 @@ public class LearningProgressFactory implements NovaEventVisitor, ILearningProgr this.publisher.publishEvent(new ChangeLearningProgressEvent(this, event.getSession())); } + @CacheEvict(value = "learningprogress", key = "#event.Session") + @Override + public void visit(UnlockQuestionEvent event) { + this.publisher.publishEvent(new ChangeLearningProgressEvent(this, event.getSession())); + } + @CacheEvict(value = "learningprogress", key = "#event.Session") @Override public void visit(UnlockQuestionsEvent event) { @@ -117,6 +125,12 @@ public class LearningProgressFactory implements NovaEventVisitor, ILearningProgr this.publisher.publishEvent(new ChangeLearningProgressEvent(this, event.getSession())); } + @CacheEvict(value = "learningprogress", key = "#event.Session") + @Override + public void visit(DeleteAllQuestionsEvent event) { + this.publisher.publishEvent(new ChangeLearningProgressEvent(this, event.getSession())); + } + @CacheEvict(value = "learningprogress", key = "#event.Session") @Override public void visit(DeleteAllQuestionsAnswersEvent event) { diff --git a/src/main/java/de/thm/arsnova/events/DeleteAllQuestionsEvent.java b/src/main/java/de/thm/arsnova/events/DeleteAllQuestionsEvent.java new file mode 100644 index 00000000..e0bb0421 --- /dev/null +++ b/src/main/java/de/thm/arsnova/events/DeleteAllQuestionsEvent.java @@ -0,0 +1,35 @@ +/* + * This file is part of ARSnova Backend. + * Copyright (C) 2012-2015 The ARSnova Team + * + * ARSnova Backend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova Backend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package de.thm.arsnova.events; + +import de.thm.arsnova.entities.Session; + +public class DeleteAllQuestionsEvent extends SessionEvent { + + private static final long serialVersionUID = 1L; + + public DeleteAllQuestionsEvent(Object source, Session session) { + super(source, session); + } + + @Override + public void accept(NovaEventVisitor visitor) { + visitor.visit(this); + } + +} diff --git a/src/main/java/de/thm/arsnova/events/DeleteQuestionEvent.java b/src/main/java/de/thm/arsnova/events/DeleteQuestionEvent.java index 4c063a96..e92f2e6a 100644 --- a/src/main/java/de/thm/arsnova/events/DeleteQuestionEvent.java +++ b/src/main/java/de/thm/arsnova/events/DeleteQuestionEvent.java @@ -17,14 +17,22 @@ */ package de.thm.arsnova.events; +import de.thm.arsnova.entities.Question; import de.thm.arsnova.entities.Session; public class DeleteQuestionEvent extends SessionEvent { private static final long serialVersionUID = 1L; - public DeleteQuestionEvent(Object source, Session session) { + private final Question question; + + public DeleteQuestionEvent(Object source, Session session, Question question) { super(source, session); + this.question = question; + } + + public Question getQuestion() { + return this.question; } @Override diff --git a/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java b/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java index c23fec9c..26e956bd 100644 --- a/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java +++ b/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java @@ -25,6 +25,8 @@ public interface NovaEventVisitor { void visit(NewQuestionEvent newQuestionEvent); + void visit(UnlockQuestionEvent unlockQuestionEvent); + void visit(UnlockQuestionsEvent newQuestionsEvent); void visit(LockQuestionEvent lockQuestionEvent); @@ -37,6 +39,8 @@ public interface NovaEventVisitor { void visit(DeleteQuestionEvent deleteQuestionEvent); + void visit(DeleteAllQuestionsEvent deleteAllQuestionsEvent); + void visit(DeleteAllQuestionsAnswersEvent deleteAllAnswersEvent); void visit(DeleteAllPreparationAnswersEvent deleteAllPreparationAnswersEvent); diff --git a/src/main/java/de/thm/arsnova/events/UnlockQuestionEvent.java b/src/main/java/de/thm/arsnova/events/UnlockQuestionEvent.java new file mode 100644 index 00000000..acd1b6d0 --- /dev/null +++ b/src/main/java/de/thm/arsnova/events/UnlockQuestionEvent.java @@ -0,0 +1,43 @@ +/* + * This file is part of ARSnova Backend. + * Copyright (C) 2012-2015 The ARSnova Team + * + * ARSnova Backend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova Backend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package de.thm.arsnova.events; + +import de.thm.arsnova.entities.Question; +import de.thm.arsnova.entities.Session; + +public class UnlockQuestionEvent extends SessionEvent { + + private static final long serialVersionUID = 1L; + + private final Question question; + + public UnlockQuestionEvent(Object source, Session session, Question question) { + super(source, session); + this.question = question; + } + + public Question getQuestion() { + return this.question; + } + + @Override + public void accept(NovaEventVisitor visitor) { + visitor.visit(this); + } + +} diff --git a/src/main/java/de/thm/arsnova/services/QuestionService.java b/src/main/java/de/thm/arsnova/services/QuestionService.java index e48f1aad..dca2ad7c 100644 --- a/src/main/java/de/thm/arsnova/services/QuestionService.java +++ b/src/main/java/de/thm/arsnova/services/QuestionService.java @@ -49,6 +49,7 @@ import de.thm.arsnova.entities.User; import de.thm.arsnova.events.DeleteAllLectureAnswersEvent; import de.thm.arsnova.events.DeleteAllPreparationAnswersEvent; import de.thm.arsnova.events.DeleteAllQuestionsAnswersEvent; +import de.thm.arsnova.events.DeleteAllQuestionsEvent; import de.thm.arsnova.events.DeleteAnswerEvent; import de.thm.arsnova.events.DeleteInterposedQuestionEvent; import de.thm.arsnova.events.DeleteQuestionEvent; @@ -58,6 +59,7 @@ import de.thm.arsnova.events.LockVotingEvent; import de.thm.arsnova.events.NewAnswerEvent; import de.thm.arsnova.events.NewInterposedQuestionEvent; import de.thm.arsnova.events.NewQuestionEvent; +import de.thm.arsnova.events.UnlockQuestionEvent; import de.thm.arsnova.events.UnlockQuestionsEvent; import de.thm.arsnova.events.NovaEvent; import de.thm.arsnova.events.PiRoundCancelEvent; @@ -219,7 +221,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis deleteQuestionFromSortOrder(question); databaseDao.deleteQuestionWithAnswers(question); - final DeleteQuestionEvent event = new DeleteQuestionEvent(this, session); + final DeleteQuestionEvent event = new DeleteQuestionEvent(this, session, question); this.publisher.publishEvent(event); } @@ -229,7 +231,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis final Session session = getSessionWithAuthCheck(sessionKeyword); databaseDao.deleteAllQuestionsWithAnswers(session); - final DeleteQuestionEvent event = new DeleteQuestionEvent(this, session); + final DeleteAllQuestionsEvent event = new DeleteAllQuestionsEvent(this, session); this.publisher.publishEvent(event); } @@ -329,7 +331,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis final Question question = databaseDao.getQuestion(questionId); final Session session = databaseDao.getSessionFromKeyword(question.getSessionKeyword()); question.setVotingDisabled(disable); - + databaseDao.updateQuestion(question); this.publisher.publishEvent(new LockVotingEvent(this, session, question)); } @@ -601,7 +603,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis final Question result = databaseDao.updateQuestion(question); if (!oldQuestion.isActive() && question.isActive()) { - final NewQuestionEvent event = new NewQuestionEvent(this, session, result); + final UnlockQuestionEvent event = new UnlockQuestionEvent(this, session, result); this.publisher.publishEvent(event); } else if (oldQuestion.isActive() && !question.isActive()) { final LockQuestionEvent event = new LockQuestionEvent(this, session, result); diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java index 9b658f60..b54ce1f7 100644 --- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java +++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java @@ -54,6 +54,7 @@ import de.thm.arsnova.events.ChangeLearningProgressEvent; import de.thm.arsnova.events.DeleteAllLectureAnswersEvent; import de.thm.arsnova.events.DeleteAllPreparationAnswersEvent; import de.thm.arsnova.events.DeleteAllQuestionsAnswersEvent; +import de.thm.arsnova.events.DeleteAllQuestionsEvent; import de.thm.arsnova.events.DeleteAnswerEvent; import de.thm.arsnova.events.DeleteFeedbackForSessionsEvent; import de.thm.arsnova.events.DeleteInterposedQuestionEvent; @@ -66,6 +67,7 @@ import de.thm.arsnova.events.NewAnswerEvent; import de.thm.arsnova.events.NewFeedbackEvent; import de.thm.arsnova.events.NewInterposedQuestionEvent; import de.thm.arsnova.events.NewQuestionEvent; +import de.thm.arsnova.events.UnlockQuestionEvent; import de.thm.arsnova.events.UnlockQuestionsEvent; import de.thm.arsnova.events.NewSessionEvent; import de.thm.arsnova.events.NovaEventVisitor; @@ -471,6 +473,11 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { this.reportLecturerQuestionAvailable(event.getSession(), Arrays.asList(event.getQuestion())); } + @Override + public void visit(UnlockQuestionEvent event) { + this.reportLecturerQuestionAvailable(event.getSession(), Arrays.asList(event.getQuestion())); + } + @Override public void visit(LockQuestionEvent event) { this.reportLecturerQuestionsLocked(event.getSession(), Arrays.asList(event.getQuestion())); @@ -497,7 +504,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { final String sessionKey = event.getSession().getKeyword(); this.reportAnswersToLecturerQuestionAvailable(event.getSession(), new Question(event.getQuestion())); broadcastInSession(sessionKey, "countQuestionAnswersByQuestionId", questionService.getAnswerAndAbstentionCountInternal(event.getQuestion().get_id())); - + // TODO: These events are currently unused. Uncomment once the client does something with the data. //broadcastInSession(sessionKey, "countLectureQuestionAnswers", questionService.countLectureQuestionAnswersInternal(sessionKey)); //broadcastInSession(sessionKey, "countPreparationQuestionAnswers", questionService.countPreparationQuestionAnswersInternal(sessionKey)); @@ -565,6 +572,12 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { } + @Override + public void visit(DeleteAllQuestionsEvent event) { + // TODO Auto-generated method stub + + } + @Override public void visit(DeleteAllQuestionsAnswersEvent deleteAllAnswersEvent) { // TODO Auto-generated method stub -- GitLab