From 54b0f381b985487fab720c9a574df4005ea88e94 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <code@dgerhardt.net> Date: Mon, 12 Nov 2018 11:51:07 +0100 Subject: [PATCH] Get rid of redundant legacy events Additionally, roomId is used instead of Room object for legacy RoomEvents. --- .../de/thm/arsnova/cache/CacheBusterImpl.java | 19 +++-- .../thm/arsnova/event/ChangeScoreEvent.java | 6 +- .../event/DeleteAllLectureAnswersEvent.java | 6 +- .../DeleteAllPreparationAnswersEvent.java | 6 +- .../event/DeleteAllQuestionsAnswersEvent.java | 6 +- .../event/DeleteAllQuestionsEvent.java | 6 +- .../thm/arsnova/event/DeleteAnswerEvent.java | 40 --------- .../thm/arsnova/event/DeleteCommentEvent.java | 41 ---------- .../arsnova/event/DeleteQuestionEvent.java | 41 ---------- .../de/thm/arsnova/event/DeleteRoomEvent.java | 34 -------- .../thm/arsnova/event/FeatureChangeEvent.java | 6 +- .../arsnova/event/FlipFlashcardsEvent.java | 6 +- .../thm/arsnova/event/LockFeedbackEvent.java | 6 +- .../thm/arsnova/event/LockQuestionEvent.java | 5 +- .../thm/arsnova/event/LockQuestionsEvent.java | 5 +- .../de/thm/arsnova/event/LockVoteEvent.java | 5 +- .../de/thm/arsnova/event/LockVotesEvent.java | 5 +- .../de/thm/arsnova/event/NewAnswerEvent.java | 55 ------------- .../de/thm/arsnova/event/NewCommentEvent.java | 41 ---------- .../thm/arsnova/event/NewFeedbackEvent.java | 6 +- .../thm/arsnova/event/NewQuestionEvent.java | 40 --------- .../de/thm/arsnova/event/NewRoomEvent.java | 33 -------- .../thm/arsnova/event/PiRoundCancelEvent.java | 5 +- .../event/PiRoundDelayedStartEvent.java | 5 +- .../de/thm/arsnova/event/PiRoundEndEvent.java | 5 +- .../thm/arsnova/event/PiRoundResetEvent.java | 5 +- .../java/de/thm/arsnova/event/RoomEvent.java | 12 ++- .../de/thm/arsnova/event/StatusRoomEvent.java | 6 +- .../arsnova/event/UnlockQuestionEvent.java | 5 +- .../arsnova/event/UnlockQuestionsEvent.java | 5 +- .../de/thm/arsnova/event/UnlockVoteEvent.java | 5 +- .../thm/arsnova/event/UnlockVotesEvent.java | 5 +- .../arsnova/service/AnswerServiceImpl.java | 20 +++-- .../arsnova/service/CommentServiceImpl.java | 10 +-- .../arsnova/service/ContentServiceImpl.java | 30 ++++--- .../arsnova/service/FeedbackServiceImpl.java | 12 +-- .../thm/arsnova/service/RoomServiceImpl.java | 15 ++-- .../thm/arsnova/service/TimerServiceImpl.java | 8 +- .../score/ScoreCalculatorFactoryImpl.java | 36 ++++---- .../websocket/ArsnovaSocketioServerImpl.java | 82 ++++++++++--------- 40 files changed, 171 insertions(+), 518 deletions(-) delete mode 100644 src/main/java/de/thm/arsnova/event/DeleteAnswerEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/DeleteCommentEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/DeleteQuestionEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/DeleteRoomEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/NewAnswerEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/NewCommentEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/NewQuestionEvent.java delete mode 100644 src/main/java/de/thm/arsnova/event/NewRoomEvent.java diff --git a/src/main/java/de/thm/arsnova/cache/CacheBusterImpl.java b/src/main/java/de/thm/arsnova/cache/CacheBusterImpl.java index 32f2b858b..ab506f7b0 100644 --- a/src/main/java/de/thm/arsnova/cache/CacheBusterImpl.java +++ b/src/main/java/de/thm/arsnova/cache/CacheBusterImpl.java @@ -17,7 +17,12 @@ */ package de.thm.arsnova.cache; -import de.thm.arsnova.event.*; +import de.thm.arsnova.event.AfterCreationEvent; +import de.thm.arsnova.event.AfterDeletionEvent; +import de.thm.arsnova.event.ChangeScoreEvent; +import de.thm.arsnova.model.Answer; +import de.thm.arsnova.model.Comment; +import de.thm.arsnova.model.Room; import org.springframework.cache.annotation.CacheEvict; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @@ -31,25 +36,25 @@ public class CacheBusterImpl implements CacheBuster { @CacheEvict(value = "statistics", allEntries = true) @EventListener - public void handleNewComment(NewCommentEvent event) { } + public void handleAfterCommentCreation(AfterCreationEvent<Comment> event) { } @CacheEvict(value = "statistics", allEntries = true) @EventListener - public void handleDeleteComment(DeleteCommentEvent event) { } + public void handleAfterCommentDeletion(AfterDeletionEvent<Comment> event) { } @CacheEvict(value = "answerlists", key = "#event.content.id") @EventListener - public void handleNewAnswer(NewAnswerEvent event) { } + public void handleAfterAnswerCreation(AfterCreationEvent<Answer> event) { } @CacheEvict(value = "statistics", allEntries = true) @EventListener - public void handleChangeScore(ChangeScoreEvent changeLearningProgress) { } + public void handleChangeScore(ChangeScoreEvent event) { } @CacheEvict(value = "statistics", allEntries = true) @EventListener - public void handleewRoom(NewRoomEvent newSessionEvent) { } + public void handleAfterRoomCreation(AfterCreationEvent<Room> event) { } @CacheEvict(value = "statistics", allEntries = true) @EventListener - public void handleDeleteRoom(DeleteRoomEvent deleteSessionEvent) { } + public void handleAfterRoomDeletion(AfterDeletionEvent<Room> event) { } } diff --git a/src/main/java/de/thm/arsnova/event/ChangeScoreEvent.java b/src/main/java/de/thm/arsnova/event/ChangeScoreEvent.java index 46cbaf639..3e2014db5 100644 --- a/src/main/java/de/thm/arsnova/event/ChangeScoreEvent.java +++ b/src/main/java/de/thm/arsnova/event/ChangeScoreEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever a score related value changes. */ @@ -26,8 +24,8 @@ public class ChangeScoreEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public ChangeScoreEvent(Object source, Room room) { - super(source, room); + public ChangeScoreEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/DeleteAllLectureAnswersEvent.java b/src/main/java/de/thm/arsnova/event/DeleteAllLectureAnswersEvent.java index 3ed09bb70..0ad169a83 100644 --- a/src/main/java/de/thm/arsnova/event/DeleteAllLectureAnswersEvent.java +++ b/src/main/java/de/thm/arsnova/event/DeleteAllLectureAnswersEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever all answers of all lecture questions of a session are deleted. */ @@ -26,8 +24,8 @@ public class DeleteAllLectureAnswersEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public DeleteAllLectureAnswersEvent(Object source, Room room) { - super(source, room); + public DeleteAllLectureAnswersEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/DeleteAllPreparationAnswersEvent.java b/src/main/java/de/thm/arsnova/event/DeleteAllPreparationAnswersEvent.java index a85f12e2f..49a8d9342 100644 --- a/src/main/java/de/thm/arsnova/event/DeleteAllPreparationAnswersEvent.java +++ b/src/main/java/de/thm/arsnova/event/DeleteAllPreparationAnswersEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever all answers of all preparation questions of a session are deleted. */ @@ -26,7 +24,7 @@ public class DeleteAllPreparationAnswersEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public DeleteAllPreparationAnswersEvent(Object source, Room room) { - super(source, room); + public DeleteAllPreparationAnswersEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsAnswersEvent.java b/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsAnswersEvent.java index bf7142ed6..aa671783f 100644 --- a/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsAnswersEvent.java +++ b/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsAnswersEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever all answers of all questions of a session are deleted. */ @@ -26,7 +24,7 @@ public class DeleteAllQuestionsAnswersEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public DeleteAllQuestionsAnswersEvent(Object source, Room room) { - super(source, room); + public DeleteAllQuestionsAnswersEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsEvent.java b/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsEvent.java index a6cd9558a..2bf5bac22 100644 --- a/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsEvent.java +++ b/src/main/java/de/thm/arsnova/event/DeleteAllQuestionsEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever all questions of a session are deleted. Note that this implies that all answers are deleted as well, * even though the specific answer events are not fired. @@ -27,8 +25,8 @@ public class DeleteAllQuestionsEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public DeleteAllQuestionsEvent(Object source, Room room) { - super(source, room); + public DeleteAllQuestionsEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/DeleteAnswerEvent.java b/src/main/java/de/thm/arsnova/event/DeleteAnswerEvent.java deleted file mode 100644 index 8a7aa4ba1..000000000 --- a/src/main/java/de/thm/arsnova/event/DeleteAnswerEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a single answer is deleted. - */ -public class DeleteAnswerEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - private final Content content; - - public DeleteAnswerEvent(Object source, Room room, Content content) { - super(source, room); - this.content = content; - } - - public Content getQuestion() { - return content; - } -} diff --git a/src/main/java/de/thm/arsnova/event/DeleteCommentEvent.java b/src/main/java/de/thm/arsnova/event/DeleteCommentEvent.java deleted file mode 100644 index 82ba83d10..000000000 --- a/src/main/java/de/thm/arsnova/event/DeleteCommentEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Comment; -import de.thm.arsnova.model.Room; - -/** - * Fires whenever an comment is deleted. - */ -public class DeleteCommentEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - private final Comment comment; - - public DeleteCommentEvent(Object source, Room room, Comment comment) { - super(source, room); - this.comment = comment; - } - - public Comment getQuestion() { - return comment; - } - -} diff --git a/src/main/java/de/thm/arsnova/event/DeleteQuestionEvent.java b/src/main/java/de/thm/arsnova/event/DeleteQuestionEvent.java deleted file mode 100644 index bfafb5fe7..000000000 --- a/src/main/java/de/thm/arsnova/event/DeleteQuestionEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a content is deleted. - */ -public class DeleteQuestionEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - private final Content content; - - public DeleteQuestionEvent(Object source, Room room, Content content) { - super(source, room); - this.content = content; - } - - public Content getQuestion() { - return this.content; - } - -} diff --git a/src/main/java/de/thm/arsnova/event/DeleteRoomEvent.java b/src/main/java/de/thm/arsnova/event/DeleteRoomEvent.java deleted file mode 100644 index a650c51a6..000000000 --- a/src/main/java/de/thm/arsnova/event/DeleteRoomEvent.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a session is deleted. Note that this implies that all related data such as comments, - * lecturer questions, and answers are deleted as well, even though those events are not fired. - */ -public class DeleteRoomEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - public DeleteRoomEvent(Object source, Room room) { - super(source, room); - } - -} diff --git a/src/main/java/de/thm/arsnova/event/FeatureChangeEvent.java b/src/main/java/de/thm/arsnova/event/FeatureChangeEvent.java index 447631a91..790eaea27 100644 --- a/src/main/java/de/thm/arsnova/event/FeatureChangeEvent.java +++ b/src/main/java/de/thm/arsnova/event/FeatureChangeEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever a new session is created. */ @@ -26,8 +24,8 @@ public class FeatureChangeEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public FeatureChangeEvent(Object source, Room room) { - super(source, room); + public FeatureChangeEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/FlipFlashcardsEvent.java b/src/main/java/de/thm/arsnova/event/FlipFlashcardsEvent.java index 5b94f9a21..c33389f1a 100644 --- a/src/main/java/de/thm/arsnova/event/FlipFlashcardsEvent.java +++ b/src/main/java/de/thm/arsnova/event/FlipFlashcardsEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever voting on a question is disabled. */ @@ -26,7 +24,7 @@ public class FlipFlashcardsEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public FlipFlashcardsEvent(Object source, Room room) { - super(source, room); + public FlipFlashcardsEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/LockFeedbackEvent.java b/src/main/java/de/thm/arsnova/event/LockFeedbackEvent.java index 1f907db30..6c50fc4b8 100644 --- a/src/main/java/de/thm/arsnova/event/LockFeedbackEvent.java +++ b/src/main/java/de/thm/arsnova/event/LockFeedbackEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever voting on a question is disabled. */ @@ -26,7 +24,7 @@ public class LockFeedbackEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public LockFeedbackEvent(Object source, Room room) { - super(source, room); + public LockFeedbackEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/LockQuestionEvent.java b/src/main/java/de/thm/arsnova/event/LockQuestionEvent.java index 2b0e38bd4..58d5b6fbf 100644 --- a/src/main/java/de/thm/arsnova/event/LockQuestionEvent.java +++ b/src/main/java/de/thm/arsnova/event/LockQuestionEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; /** * Fires whenever a content is disabled, i.e., it is hidden from students. @@ -29,8 +28,8 @@ public class LockQuestionEvent extends RoomEvent { private final Content content; - public LockQuestionEvent(Object source, Room room, Content content) { - super(source, room); + public LockQuestionEvent(Object source, String roomId, Content content) { + super(source, roomId); this.content = content; } diff --git a/src/main/java/de/thm/arsnova/event/LockQuestionsEvent.java b/src/main/java/de/thm/arsnova/event/LockQuestionsEvent.java index fb27e4e6c..869d0c1a0 100644 --- a/src/main/java/de/thm/arsnova/event/LockQuestionsEvent.java +++ b/src/main/java/de/thm/arsnova/event/LockQuestionsEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.List; @@ -31,8 +30,8 @@ public class LockQuestionsEvent extends RoomEvent { private List<Content> contents; - public LockQuestionsEvent(Object source, Room room, List<Content> contents) { - super(source, room); + public LockQuestionsEvent(Object source, String roomId, List<Content> contents) { + super(source, roomId); this.contents = contents; } diff --git a/src/main/java/de/thm/arsnova/event/LockVoteEvent.java b/src/main/java/de/thm/arsnova/event/LockVoteEvent.java index 07456ac7b..bf3ba2973 100644 --- a/src/main/java/de/thm/arsnova/event/LockVoteEvent.java +++ b/src/main/java/de/thm/arsnova/event/LockVoteEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.HashMap; import java.util.Map; @@ -32,8 +31,8 @@ public class LockVoteEvent extends RoomEvent { private final Content content; - public LockVoteEvent(Object source, Room room, Content content) { - super(source, room); + public LockVoteEvent(Object source, String roomId, Content content) { + super(source, roomId); this.content = content; } diff --git a/src/main/java/de/thm/arsnova/event/LockVotesEvent.java b/src/main/java/de/thm/arsnova/event/LockVotesEvent.java index ebff38234..7595c19a2 100644 --- a/src/main/java/de/thm/arsnova/event/LockVotesEvent.java +++ b/src/main/java/de/thm/arsnova/event/LockVotesEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.List; @@ -31,8 +30,8 @@ public class LockVotesEvent extends RoomEvent { private List<Content> contents; - public LockVotesEvent(Object source, Room room, List<Content> contents) { - super(source, room); + public LockVotesEvent(Object source, String roomId, List<Content> contents) { + super(source, roomId); this.contents = contents; } diff --git a/src/main/java/de/thm/arsnova/event/NewAnswerEvent.java b/src/main/java/de/thm/arsnova/event/NewAnswerEvent.java deleted file mode 100644 index 462494d98..000000000 --- a/src/main/java/de/thm/arsnova/event/NewAnswerEvent.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Answer; -import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a new answer is added. - */ -public class NewAnswerEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - private final Answer answer; - - private final String userId; - - private final Content content; - - public NewAnswerEvent(Object source, Room room, Answer answer, String userId, Content content) { - super(source, room); - this.answer = answer; - this.userId = userId; - this.content = content; - } - - public Answer getAnswer() { - return answer; - } - - public String getUserId() { - return userId; - } - - public Content getContent() { - return content; - } -} diff --git a/src/main/java/de/thm/arsnova/event/NewCommentEvent.java b/src/main/java/de/thm/arsnova/event/NewCommentEvent.java deleted file mode 100644 index 0ccf30272..000000000 --- a/src/main/java/de/thm/arsnova/event/NewCommentEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Comment; -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a new comment is added. - */ -public class NewCommentEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - private final Comment comment; - - public NewCommentEvent(Object source, Room room, Comment comment) { - super(source, room); - this.comment = comment; - } - - public Comment getQuestion() { - return comment; - } - -} diff --git a/src/main/java/de/thm/arsnova/event/NewFeedbackEvent.java b/src/main/java/de/thm/arsnova/event/NewFeedbackEvent.java index d663f2bb5..6a5d7290f 100644 --- a/src/main/java/de/thm/arsnova/event/NewFeedbackEvent.java +++ b/src/main/java/de/thm/arsnova/event/NewFeedbackEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever the feedback changes. */ @@ -26,8 +24,8 @@ public class NewFeedbackEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public NewFeedbackEvent(Object source, Room room) { - super(source, room); + public NewFeedbackEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/NewQuestionEvent.java b/src/main/java/de/thm/arsnova/event/NewQuestionEvent.java deleted file mode 100644 index 53281dcea..000000000 --- a/src/main/java/de/thm/arsnova/event/NewQuestionEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a new content is added. - */ -public class NewQuestionEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - private final Content content; - - public NewQuestionEvent(Object source, Room room, Content content) { - super(source, room); - this.content = content; - } - - public Content getQuestion() { - return content; - } -} diff --git a/src/main/java/de/thm/arsnova/event/NewRoomEvent.java b/src/main/java/de/thm/arsnova/event/NewRoomEvent.java deleted file mode 100644 index 222fa7c0f..000000000 --- a/src/main/java/de/thm/arsnova/event/NewRoomEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * 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.event; - -import de.thm.arsnova.model.Room; - -/** - * Fires whenever a new session is created. - */ -public class NewRoomEvent extends RoomEvent { - - private static final long serialVersionUID = 1L; - - public NewRoomEvent(Object source, Room room) { - super(source, room); - } - -} diff --git a/src/main/java/de/thm/arsnova/event/PiRoundCancelEvent.java b/src/main/java/de/thm/arsnova/event/PiRoundCancelEvent.java index 27cf4351d..73fadca6d 100644 --- a/src/main/java/de/thm/arsnova/event/PiRoundCancelEvent.java +++ b/src/main/java/de/thm/arsnova/event/PiRoundCancelEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; /** * Fires whenever a peer instruction round is canceled. @@ -27,8 +26,8 @@ public class PiRoundCancelEvent extends PiRoundEndEvent { private static final long serialVersionUID = 1L; - public PiRoundCancelEvent(Object source, Room room, Content content) { - super(source, room, content); + public PiRoundCancelEvent(Object source, String roomId, Content content) { + super(source, roomId, content); } } diff --git a/src/main/java/de/thm/arsnova/event/PiRoundDelayedStartEvent.java b/src/main/java/de/thm/arsnova/event/PiRoundDelayedStartEvent.java index 43ac5f59b..c12cc8782 100644 --- a/src/main/java/de/thm/arsnova/event/PiRoundDelayedStartEvent.java +++ b/src/main/java/de/thm/arsnova/event/PiRoundDelayedStartEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.Date; import java.util.HashMap; @@ -37,8 +36,8 @@ public class PiRoundDelayedStartEvent extends RoomEvent { private final String group; private int piRound; - public PiRoundDelayedStartEvent(Object source, Room room, Content content) { - super(source, room); + public PiRoundDelayedStartEvent(Object source, String roomId, Content content) { + super(source, roomId); this.questionId = content.getId(); /* FIXME: Event does not support content with multiple groups */ this.group = content.getGroups().toArray(new String[1])[0]; diff --git a/src/main/java/de/thm/arsnova/event/PiRoundEndEvent.java b/src/main/java/de/thm/arsnova/event/PiRoundEndEvent.java index 064ba458d..8d56a8139 100644 --- a/src/main/java/de/thm/arsnova/event/PiRoundEndEvent.java +++ b/src/main/java/de/thm/arsnova/event/PiRoundEndEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.HashMap; import java.util.Map; @@ -33,8 +32,8 @@ public class PiRoundEndEvent extends RoomEvent { private final String contentId; private final String group; - public PiRoundEndEvent(Object source, Room room, Content content) { - super(source, room); + public PiRoundEndEvent(Object source, String roomId, Content content) { + super(source, roomId); contentId = content.getId(); /* FIXME: Event does not support content with multiple groups */ this.group = content.getGroups().toArray(new String[1])[0]; diff --git a/src/main/java/de/thm/arsnova/event/PiRoundResetEvent.java b/src/main/java/de/thm/arsnova/event/PiRoundResetEvent.java index 4d5d773ea..2b4cd5325 100644 --- a/src/main/java/de/thm/arsnova/event/PiRoundResetEvent.java +++ b/src/main/java/de/thm/arsnova/event/PiRoundResetEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.HashMap; import java.util.Map; @@ -33,8 +32,8 @@ public class PiRoundResetEvent extends RoomEvent { private final String contentId; private final String group; - public PiRoundResetEvent(Object source, Room room, Content content) { - super(source, room); + public PiRoundResetEvent(Object source, String roomId, Content content) { + super(source, roomId); contentId = content.getId(); /* FIXME: Event does not support content with multiple groups */ this.group = content.getGroups().toArray(new String[1])[0]; diff --git a/src/main/java/de/thm/arsnova/event/RoomEvent.java b/src/main/java/de/thm/arsnova/event/RoomEvent.java index eb32f2aaa..62577df7a 100644 --- a/src/main/java/de/thm/arsnova/event/RoomEvent.java +++ b/src/main/java/de/thm/arsnova/event/RoomEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Base class for all {@link ArsnovaEvent}s that are related to a room. */ @@ -26,14 +24,14 @@ public abstract class RoomEvent extends ArsnovaEvent { private static final long serialVersionUID = 1L; - private final Room room; + private final String roomId; - public RoomEvent(Object source, Room room) { + public RoomEvent(Object source, String roomId) { super(source); - this.room = room; + this.roomId = roomId; } - public Room getRoom() { - return room; + public String getRoomId() { + return roomId; } } diff --git a/src/main/java/de/thm/arsnova/event/StatusRoomEvent.java b/src/main/java/de/thm/arsnova/event/StatusRoomEvent.java index d91026fde..d7307cd79 100644 --- a/src/main/java/de/thm/arsnova/event/StatusRoomEvent.java +++ b/src/main/java/de/thm/arsnova/event/StatusRoomEvent.java @@ -17,8 +17,6 @@ */ package de.thm.arsnova.event; -import de.thm.arsnova.model.Room; - /** * Fires whenever the status of a session changes, i.e., it is enabled or disabled. */ @@ -26,8 +24,8 @@ public class StatusRoomEvent extends RoomEvent { private static final long serialVersionUID = 1L; - public StatusRoomEvent(Object source, Room room) { - super(source, room); + public StatusRoomEvent(Object source, String roomId) { + super(source, roomId); } } diff --git a/src/main/java/de/thm/arsnova/event/UnlockQuestionEvent.java b/src/main/java/de/thm/arsnova/event/UnlockQuestionEvent.java index 3a53ff442..deddf45f1 100644 --- a/src/main/java/de/thm/arsnova/event/UnlockQuestionEvent.java +++ b/src/main/java/de/thm/arsnova/event/UnlockQuestionEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; /** * Fires whenever a content is enabled, i.e., it becomes visible to students. @@ -29,8 +28,8 @@ public class UnlockQuestionEvent extends RoomEvent { private final Content content; - public UnlockQuestionEvent(Object source, Room room, Content content) { - super(source, room); + public UnlockQuestionEvent(Object source, String roomId, Content content) { + super(source, roomId); this.content = content; } diff --git a/src/main/java/de/thm/arsnova/event/UnlockQuestionsEvent.java b/src/main/java/de/thm/arsnova/event/UnlockQuestionsEvent.java index 50c66f05a..81f38cc60 100644 --- a/src/main/java/de/thm/arsnova/event/UnlockQuestionsEvent.java +++ b/src/main/java/de/thm/arsnova/event/UnlockQuestionsEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.List; @@ -31,8 +30,8 @@ public class UnlockQuestionsEvent extends RoomEvent { private List<Content> contents; - public UnlockQuestionsEvent(Object source, Room room, List<Content> contents) { - super(source, room); + public UnlockQuestionsEvent(Object source, String roomId, List<Content> contents) { + super(source, roomId); this.contents = contents; } diff --git a/src/main/java/de/thm/arsnova/event/UnlockVoteEvent.java b/src/main/java/de/thm/arsnova/event/UnlockVoteEvent.java index d6206d6db..3dd6996e3 100644 --- a/src/main/java/de/thm/arsnova/event/UnlockVoteEvent.java +++ b/src/main/java/de/thm/arsnova/event/UnlockVoteEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.HashMap; import java.util.Map; @@ -32,8 +31,8 @@ public class UnlockVoteEvent extends RoomEvent { private final Content content; - public UnlockVoteEvent(Object source, Room room, Content content) { - super(source, room); + public UnlockVoteEvent(Object source, String roomId, Content content) { + super(source, roomId); this.content = content; } diff --git a/src/main/java/de/thm/arsnova/event/UnlockVotesEvent.java b/src/main/java/de/thm/arsnova/event/UnlockVotesEvent.java index cf5fe5f2c..85cf1d06f 100644 --- a/src/main/java/de/thm/arsnova/event/UnlockVotesEvent.java +++ b/src/main/java/de/thm/arsnova/event/UnlockVotesEvent.java @@ -18,7 +18,6 @@ package de.thm.arsnova.event; import de.thm.arsnova.model.Content; -import de.thm.arsnova.model.Room; import java.util.List; @@ -31,8 +30,8 @@ public class UnlockVotesEvent extends RoomEvent { private List<Content> contents; - public UnlockVotesEvent(Object source, Room room, List<Content> contents) { - super(source, room); + public UnlockVotesEvent(Object source, String roomId, List<Content> contents) { + super(source, roomId); this.contents = contents; } diff --git a/src/main/java/de/thm/arsnova/service/AnswerServiceImpl.java b/src/main/java/de/thm/arsnova/service/AnswerServiceImpl.java index 93e7c1bfd..fdbe22ff3 100644 --- a/src/main/java/de/thm/arsnova/service/AnswerServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/AnswerServiceImpl.java @@ -17,8 +17,8 @@ */ package de.thm.arsnova.service; -import de.thm.arsnova.event.DeleteAnswerEvent; -import de.thm.arsnova.event.NewAnswerEvent; +import de.thm.arsnova.event.AfterCreationEvent; +import de.thm.arsnova.event.BeforeCreationEvent; import de.thm.arsnova.model.Answer; import de.thm.arsnova.model.AnswerStatistics; import de.thm.arsnova.model.ChoiceQuestionContent; @@ -95,11 +95,12 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> implemen elements.add(entry); } try { + for (AnswerQueueElement e : elements) { + this.eventPublisher.publishEvent(new BeforeCreationEvent<>(e.getAnswer())); + } answerRepository.saveAll(answerList); - - // Send NewAnswerEvents ... for (AnswerQueueElement e : elements) { - this.eventPublisher.publishEvent(new NewAnswerEvent(this, e.getRoom(), e.getAnswer(), e.getUserId(), e.getQuestion())); + this.eventPublisher.publishEvent(new AfterCreationEvent<>(e.getAnswer())); } } catch (final DbAccessException e) { logger.error("Could not bulk save answers from queue.", e); @@ -352,6 +353,7 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> implemen return answer; } + /* FIXME: Remove, this should be handled by EntityService! */ @Override @PreAuthorize("isAuthenticated()") @CacheEvict(value = "answerlists", allEntries = true) @@ -373,12 +375,14 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> implemen answer.setCreatorId(user.getId()); answer.setContentId(content.getId()); answer.setRoomId(room.getId()); + this.eventPublisher.publishEvent(new BeforeCreationEvent<>(realAnswer)); answerRepository.save(realAnswer); - this.eventPublisher.publishEvent(new NewAnswerEvent(this, room, answer, user.getId(), content)); + this.eventPublisher.publishEvent(new AfterCreationEvent<>(realAnswer)); return answer; } + /* FIXME: Remove, this should be handled by EntityService! */ @Override @PreAuthorize("isAuthenticated()") @CacheEvict(value = "answerlists", allEntries = true) @@ -392,9 +396,9 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> implemen if (user == null || room == null || !room.getOwnerId().equals(user.getId())) { throw new UnauthorizedException(); } + //this.eventPublisher.publishEvent(new BeforeDeletionEvent<>(answer)); answerRepository.deleteById(answerId); - - this.eventPublisher.publishEvent(new DeleteAnswerEvent(this, room, content)); + //this.eventPublisher.publishEvent(new AfterDeletionEvent<>(answer)); } /* diff --git a/src/main/java/de/thm/arsnova/service/CommentServiceImpl.java b/src/main/java/de/thm/arsnova/service/CommentServiceImpl.java index 8fbab006c..48f055635 100644 --- a/src/main/java/de/thm/arsnova/service/CommentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/CommentServiceImpl.java @@ -1,6 +1,7 @@ package de.thm.arsnova.service; -import de.thm.arsnova.event.DeleteCommentEvent; +import de.thm.arsnova.event.AfterDeletionEvent; +import de.thm.arsnova.event.BeforeDeletionEvent; import de.thm.arsnova.model.Comment; import de.thm.arsnova.model.Room; import de.thm.arsnova.model.migration.v2.CommentReadingCount; @@ -56,6 +57,7 @@ public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implem /* TODO: fire event */ } + /* FIXME: Remove, EntityService should handle this! */ @Override @PreAuthorize("hasPermission(#commentId, 'comment', 'owner')") public void delete(final String commentId) { @@ -63,11 +65,9 @@ public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implem if (comment == null) { throw new NotFoundException(); } + eventPublisher.publishEvent(new BeforeDeletionEvent<>(comment)); commentRepository.delete(comment); - - final Room room = roomRepository.findOne(comment.getRoomId()); - final DeleteCommentEvent event = new DeleteCommentEvent(this, room, comment); - this.eventPublisher.publishEvent(event); + eventPublisher.publishEvent(new AfterDeletionEvent<>(comment)); } @Override diff --git a/src/main/java/de/thm/arsnova/service/ContentServiceImpl.java b/src/main/java/de/thm/arsnova/service/ContentServiceImpl.java index ea65cbe35..f905d2b1a 100644 --- a/src/main/java/de/thm/arsnova/service/ContentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/ContentServiceImpl.java @@ -194,10 +194,9 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem newGroup.setContentIds(newContentIds); room.getContentGroups().add(newGroup); } + eventPublisher.publishEvent(new BeforeCreationEvent<>(content)); roomRepository.save(room); - - final NewQuestionEvent event = new NewQuestionEvent(this, room, content); - this.eventPublisher.publishEvent(event); + eventPublisher.publishEvent(new AfterCreationEvent<>(content)); } @Override @@ -290,14 +289,13 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem try { final int count = answerRepository.deleteByContentId(contentId); + eventPublisher.publishEvent(new BeforeDeletionEvent<>(content)); contentRepository.deleteById(contentId); + eventPublisher.publishEvent(new AfterDeletionEvent<>(content)); dbLogger.log("delete", "type", "content", "answerCount", count); } catch (final IllegalArgumentException e) { logger.error("Could not delete content {}.", contentId, e); } - - final DeleteQuestionEvent event = new DeleteQuestionEvent(this, room, content); - this.eventPublisher.publishEvent(event); } @PreAuthorize("hasPermission(#session, 'owner')") @@ -320,7 +318,7 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem dbLogger.log("delete", "type", "question", "questionCount", contentCount); dbLogger.log("delete", "type", "answer", "answerCount", answerCount); - final DeleteAllQuestionsEvent event = new DeleteAllQuestionsEvent(this, room); + final DeleteAllQuestionsEvent event = new DeleteAllQuestionsEvent(this, room.getId()); this.eventPublisher.publishEvent(event); } @@ -367,9 +365,9 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem } ArsnovaEvent event; if (disableVoting) { - event = new LockVoteEvent(this, room, content); + event = new LockVoteEvent(this, room.getId(), content); } else { - event = new UnlockVoteEvent(this, room, content); + event = new UnlockVoteEvent(this, room.getId(), content); } this.eventPublisher.publishEvent(event); } @@ -397,9 +395,9 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem List<Content> list = new ArrayList<>(); contents.forEach(list::add); if (disableVoting) { - event = new LockVotesEvent(this, room, list); + event = new LockVotesEvent(this, room.getId(), list); } else { - event = new UnlockVotesEvent(this, room, list); + event = new UnlockVotesEvent(this, room.getId(), list); } this.eventPublisher.publishEvent(event); } catch (IOException e) { @@ -498,9 +496,9 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem List<Content> list = new ArrayList<>(); contents.forEach(list::add); if (publish) { - event = new UnlockQuestionsEvent(this, room, list); + event = new UnlockQuestionsEvent(this, room.getId(), list); } else { - event = new LockQuestionsEvent(this, room, list); + event = new LockQuestionsEvent(this, room.getId(), list); } this.eventPublisher.publishEvent(event); } @@ -521,7 +519,7 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem final List<String> contentIds = contents.stream().map(Content::getId).collect(Collectors.toList()); answerRepository.deleteAllAnswersForQuestions(contentIds); - this.eventPublisher.publishEvent(new DeleteAllQuestionsAnswersEvent(this, room)); + this.eventPublisher.publishEvent(new DeleteAllQuestionsAnswersEvent(this, room.getId())); } /* TODO: Split and move answer part to AnswerService */ @@ -537,7 +535,7 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem final List<String> contentIds = contents.stream().map(Content::getId).collect(Collectors.toList()); answerRepository.deleteAllAnswersForQuestions(contentIds); - this.eventPublisher.publishEvent(new DeleteAllPreparationAnswersEvent(this, room)); + this.eventPublisher.publishEvent(new DeleteAllPreparationAnswersEvent(this, room.getId())); } /* TODO: Split and move answer part to AnswerService */ @@ -553,7 +551,7 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem final List<String> contentIds = contents.stream().map(Content::getId).collect(Collectors.toList()); answerRepository.deleteAllAnswersForQuestions(contentIds); - this.eventPublisher.publishEvent(new DeleteAllLectureAnswersEvent(this, room)); + this.eventPublisher.publishEvent(new DeleteAllLectureAnswersEvent(this, room.getId())); } @Caching(evict = { diff --git a/src/main/java/de/thm/arsnova/service/FeedbackServiceImpl.java b/src/main/java/de/thm/arsnova/service/FeedbackServiceImpl.java index 842322bfa..ea4b87312 100644 --- a/src/main/java/de/thm/arsnova/service/FeedbackServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/FeedbackServiceImpl.java @@ -90,12 +90,12 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub // Send feedback reset event to all affected users for (Map.Entry<String, Set<Room>> entry : affectedSessionsOfUsers.entrySet()) { final String userId = entry.getKey(); - final Set<Room> arsSessions = entry.getValue(); - this.publisher.publishEvent(new DeleteFeedbackForRoomsEvent(this, arsSessions, userId)); + final Set<Room> rooms = entry.getValue(); + this.publisher.publishEvent(new DeleteFeedbackForRoomsEvent(this, rooms, userId)); } // For each session that has deleted feedback, send the new feedback to all clients - for (Room session : deletedFeedbackOfUsersInSession.keySet()) { - this.publisher.publishEvent(new NewFeedbackEvent(this, session)); + for (Room room : deletedFeedbackOfUsersInSession.keySet()) { + this.publisher.publishEvent(new NewFeedbackEvent(this, room.getId())); } } @@ -111,7 +111,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub this.publisher.publishEvent(new DeleteFeedbackForRoomsEvent(this, sessionSet, userId)); } // send the new feedback to all clients in affected session - this.publisher.publishEvent(new NewFeedbackEvent(this, room)); + this.publisher.publishEvent(new NewFeedbackEvent(this, room.getId())); } @Override @@ -163,7 +163,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub } feedbackStorage.save(room, value, userId); - this.publisher.publishEvent(new NewFeedbackEvent(this, room)); + this.publisher.publishEvent(new NewFeedbackEvent(this, room.getId())); return true; } diff --git a/src/main/java/de/thm/arsnova/service/RoomServiceImpl.java b/src/main/java/de/thm/arsnova/service/RoomServiceImpl.java index 4f6e2f96e..9f7de91a1 100644 --- a/src/main/java/de/thm/arsnova/service/RoomServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/RoomServiceImpl.java @@ -19,7 +19,8 @@ package de.thm.arsnova.service; import de.thm.arsnova.connector.client.ConnectorClient; import de.thm.arsnova.connector.model.Course; -import de.thm.arsnova.event.DeleteRoomEvent; +import de.thm.arsnova.event.AfterDeletionEvent; +import de.thm.arsnova.event.BeforeDeletionEvent; import de.thm.arsnova.event.FeatureChangeEvent; import de.thm.arsnova.event.FlipFlashcardsEvent; import de.thm.arsnova.event.LockFeedbackEvent; @@ -403,7 +404,7 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R public Room setActive(final String id, final Boolean lock) { final Room room = roomRepository.findOne(id); room.setClosed(!lock); - this.eventPublisher.publishEvent(new StatusRoomEvent(this, room)); + this.eventPublisher.publishEvent(new StatusRoomEvent(this, room.getId())); roomRepository.save(room); return room; @@ -454,12 +455,12 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R count[2] = commentRepository.deleteByRoomId(room.getId()); count[1] = answerRepository.deleteByContentIds(contentIds); count[0] = contentRepository.deleteByRoomId(room.getId()); + this.eventPublisher.publishEvent(new BeforeDeletionEvent<>(room)); roomRepository.delete(room); + this.eventPublisher.publishEvent(new AfterDeletionEvent<>(room)); logger.debug("Deleted room document {} and related data.", room.getId()); dbLogger.log("delete", "type", "session", "id", room.getId()); - this.eventPublisher.publishEvent(new DeleteRoomEvent(this, room)); - return count; } @@ -518,7 +519,7 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R public Room.Settings updateFeatures(String id, Room.Settings settings) { final Room room = roomRepository.findOne(id); room.setSettings(settings); - this.eventPublisher.publishEvent(new FeatureChangeEvent(this, room)); + this.eventPublisher.publishEvent(new FeatureChangeEvent(this, room.getId())); roomRepository.save(room); return room.getSettings(); @@ -533,7 +534,7 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R } room.getSettings().setFeedbackLocked(lock); - this.eventPublisher.publishEvent(new LockFeedbackEvent(this, room)); + this.eventPublisher.publishEvent(new LockFeedbackEvent(this, room.getId())); roomRepository.save(room); return room.getSettings().isFeedbackLocked(); @@ -543,7 +544,7 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R @PreAuthorize("hasPermission(#id, 'room', 'owner')") public boolean flipFlashcards(String id, Boolean flip) { final Room room = roomRepository.findOne(id); - this.eventPublisher.publishEvent(new FlipFlashcardsEvent(this, room)); + this.eventPublisher.publishEvent(new FlipFlashcardsEvent(this, room.getId())); return flip; } diff --git a/src/main/java/de/thm/arsnova/service/TimerServiceImpl.java b/src/main/java/de/thm/arsnova/service/TimerServiceImpl.java index 263ef8caa..386a49c3b 100644 --- a/src/main/java/de/thm/arsnova/service/TimerServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/TimerServiceImpl.java @@ -51,7 +51,7 @@ public class TimerServiceImpl implements TimerService, ApplicationEventPublisher updateRoundManagementState(content); contentRepository.save(content); - this.publisher.publishEvent(new PiRoundEndEvent(this, room, content)); + this.publisher.publishEvent(new PiRoundEndEvent(this, room.getId(), content)); } @Override @@ -67,7 +67,7 @@ public class TimerServiceImpl implements TimerService, ApplicationEventPublisher updateRoundStartVariables(content, date, endDate); contentRepository.save(content); - this.publisher.publishEvent(new PiRoundDelayedStartEvent(this, room, content)); + this.publisher.publishEvent(new PiRoundDelayedStartEvent(this, room.getId(), content)); timerList.put(contentId, timer); timer.schedule(new TimerTask() { @@ -93,7 +93,7 @@ public class TimerServiceImpl implements TimerService, ApplicationEventPublisher content.getState().setRoundEndTimestamp(null); contentRepository.save(content); - this.publisher.publishEvent(new PiRoundCancelEvent(this, room, content)); + this.publisher.publishEvent(new PiRoundCancelEvent(this, room.getId(), content)); } @Override @@ -124,7 +124,7 @@ public class TimerServiceImpl implements TimerService, ApplicationEventPublisher resetRoundManagementState(content); answerRepository.deleteByContentId(content.getId()); contentRepository.save(content); - this.publisher.publishEvent(new PiRoundResetEvent(this, room, content)); + this.publisher.publishEvent(new PiRoundResetEvent(this, room.getId(), content)); } private void updateRoundStartVariables(final Content content, final Date start, final Date end) { diff --git a/src/main/java/de/thm/arsnova/service/score/ScoreCalculatorFactoryImpl.java b/src/main/java/de/thm/arsnova/service/score/ScoreCalculatorFactoryImpl.java index d8267dfae..46a50546d 100644 --- a/src/main/java/de/thm/arsnova/service/score/ScoreCalculatorFactoryImpl.java +++ b/src/main/java/de/thm/arsnova/service/score/ScoreCalculatorFactoryImpl.java @@ -18,6 +18,8 @@ package de.thm.arsnova.service.score; import de.thm.arsnova.event.*; +import de.thm.arsnova.model.Answer; +import de.thm.arsnova.model.Content; import de.thm.arsnova.persistence.SessionStatisticsRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -53,80 +55,80 @@ public class ScoreCalculatorFactoryImpl implements ScoreCalculatorFactory, Appli @CacheEvict(value = "score", key = "#event.Room") @EventListener - public void handleNewQuestion(NewQuestionEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + public void handleAfterContentCreation(AfterCreationEvent<Content> event) { + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getSource().getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleUnlockQuestion(UnlockQuestionEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleUnlockQuestions(UnlockQuestionsEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleLockQuestion(LockQuestionEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleLockQuestions(LockQuestionsEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener - public void handleNewAnswer(NewAnswerEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + public void handleNewAnswer(AfterCreationEvent<Answer> event) { + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getSource().getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener - public void handleDeleteAnswer(DeleteAnswerEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + public void handleDeleteAnswer(AfterDeletionEvent<Answer> event) { + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getSource().getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener - public void handleDeleteQuestion(DeleteQuestionEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + public void handleDeleteQuestion(AfterDeletionEvent<Content> event) { + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getSource().getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleDeleteAllQuestions(DeleteAllQuestionsEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleDeleteAllQuestionsAnswers(DeleteAllQuestionsAnswersEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleDeleteAllPreparationAnswers(DeleteAllPreparationAnswersEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handleDeleteAllLectureAnswers(DeleteAllLectureAnswersEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @CacheEvict(value = "score", key = "#event.Room") @EventListener public void handlePiRoundReset(PiRoundResetEvent event) { - this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoom())); + this.publisher.publishEvent(new ChangeScoreEvent(this, event.getRoomId())); } @Override diff --git a/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java b/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java index d17fd69b5..8ec0ac075 100644 --- a/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java +++ b/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java @@ -29,6 +29,7 @@ import com.corundumstudio.socketio.listener.DisconnectListener; import com.corundumstudio.socketio.protocol.Packet; import com.corundumstudio.socketio.protocol.PacketType; import de.thm.arsnova.event.*; +import de.thm.arsnova.model.Answer; import de.thm.arsnova.model.Comment; import de.thm.arsnova.model.ScoreOptions; import de.thm.arsnova.model.migration.ToV2Migrator; @@ -491,61 +492,62 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { } @EventListener - public void handleNewQuestion(NewQuestionEvent event) { - this.reportContentAvailable(event.getRoom().getId(), Collections.singletonList(event.getQuestion())); + public void handleAfterContentCreation(AfterCreationEvent<de.thm.arsnova.model.Content> event) { + this.reportContentAvailable(event.getSource().getId(), Collections.singletonList(event.getSource())); } @EventListener public void handleUnlockQuestion(UnlockQuestionEvent event) { - this.reportContentAvailable(event.getRoom().getId(), Collections.singletonList(event.getQuestion())); + this.reportContentAvailable(event.getRoomId(), Collections.singletonList(event.getQuestion())); } @EventListener public void handleLockQuestion(LockQuestionEvent event) { - this.reportContentsLocked(event.getRoom().getId(), Collections.singletonList(event.getQuestion())); + this.reportContentsLocked(event.getRoomId(), Collections.singletonList(event.getQuestion())); } @EventListener public void handleUnlockQuestions(UnlockQuestionsEvent event) { - this.reportContentAvailable(event.getRoom().getId(), event.getQuestions()); + this.reportContentAvailable(event.getRoomId(), event.getQuestions()); } @EventListener public void handleLockQuestions(LockQuestionsEvent event) { - this.reportContentsLocked(event.getRoom().getId(), event.getQuestions()); + this.reportContentsLocked(event.getRoomId(), event.getQuestions()); } @EventListener - public void handleNewComment(NewCommentEvent event) { - this.reportCommentAvailable(event.getRoom().getId(), event.getQuestion().getId()); + public void handleAfterCommentCreation(AfterCreationEvent<Comment> event) { + this.reportCommentAvailable(event.getSource().getId(), event.getSource().getId()); } @Async @EventListener @Timed - public void handleNewAnswer(NewAnswerEvent event) { - final String roomId = event.getRoom().getId(); - this.reportAnswersToContentAvailable(event.getRoom().getId(), event.getContent().getId()); - broadcastInRoom(roomId, "countQuestionAnswersByQuestionId", answerService.countAnswersAndAbstentionsInternal(event.getContent().getId())); + public void handleNewAnswer(AfterCreationEvent<Answer> event) { + final String roomId = event.getSource().getRoomId(); + this.reportAnswersToContentAvailable(event.getSource().getRoomId(), event.getSource().getContentId()); + broadcastInRoom(roomId, "countQuestionAnswersByQuestionId", answerService.countAnswersAndAbstentionsInternal(event.getSource().getContentId())); /* FIXME: Content variant is ignored for now */ broadcastInRoom(roomId, "countLectureQuestionAnswers", answerService.countTotalAnswersByRoomId(roomId)); broadcastInRoom(roomId, "countPreparationQuestionAnswers", answerService.countTotalAnswersByRoomId(roomId)); // Update the unanswered count for the content variant that was answered. - final de.thm.arsnova.model.Content content = event.getContent(); - if (content.getGroups().contains("lecture")) { - sendToUser(event.getUserId(), "unansweredLecturerQuestions", contentService.getUnAnsweredLectureContentIds(roomId, event.getUserId())); - } else if (content.getGroups().contains("preparation")) { - sendToUser(event.getUserId(), "unansweredPreparationQuestions", contentService.getUnAnsweredPreparationContentIds(roomId, event.getUserId())); - } + /* Is this still relevant? */ +// final de.thm.arsnova.model.Content content = // event.getSource().getContentId(); +// if (content.getGroups().contains("lecture")) { +// sendToUser(event.getSource().getCreatorId(), "unansweredLecturerQuestions", contentService.getUnAnsweredLectureContentIds(roomId, event.getSource().getCreatorId())); +// } else if (content.getGroups().contains("preparation")) { +// sendToUser(event.getSource().getCreatorId(), "unansweredPreparationQuestions", contentService.getUnAnsweredPreparationContentIds(roomId, event.getSource().getCreatorId())); +// } } @Async @EventListener @Timed - public void handleDeleteAnswer(DeleteAnswerEvent event) { - final String roomId = event.getRoom().getId(); - this.reportAnswersToContentAvailable(event.getRoom().getId(), event.getQuestion().getId()); + public void handleAfterAnswerDeletion(AfterDeletionEvent<Answer> event) { + final String roomId = event.getSource().getRoomId(); + this.reportAnswersToContentAvailable(event.getSource().getRoomId(), event.getSource().getContentId()); // We do not know which user's answer was deleted, so we can't update his 'unanswered' list of questions... /* FIXME: Content variant is ignored for now */ broadcastInRoom(roomId, "countLectureQuestionAnswers", answerService.countTotalAnswersByRoomId(roomId)); @@ -556,7 +558,7 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { @EventListener @Timed public void handlePiRoundDelayedStart(PiRoundDelayedStartEvent event) { - final String roomId = event.getRoom().getId(); + final String roomId = event.getRoomId(); broadcastInRoom(roomId, "startDelayedPiRound", event.getPiRoundInformations()); } @@ -564,7 +566,7 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { @EventListener @Timed public void handlePiRoundEnd(PiRoundEndEvent event) { - final String roomId = event.getRoom().getId(); + final String roomId = event.getRoomId(); broadcastInRoom(roomId, "endPiRound", event.getPiRoundEndInformations()); } @@ -572,25 +574,25 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { @EventListener @Timed public void handlePiRoundCancel(PiRoundCancelEvent event) { - final String roomId = event.getRoom().getId(); + final String roomId = event.getRoomId(); broadcastInRoom(roomId, "cancelPiRound", event.getContentId()); } @EventListener public void handlePiRoundReset(PiRoundResetEvent event) { - final String roomId = event.getRoom().getId(); + final String roomId = event.getRoomId(); broadcastInRoom(roomId, "resetPiRound", event.getPiRoundResetInformations()); } @EventListener public void handleLockVote(LockVoteEvent event) { - final String roomId = event.getRoom().getId(); + final String roomId = event.getRoomId(); broadcastInRoom(roomId, "lockVote", event.getVotingAdmission()); } @EventListener public void handleUnlockVote(UnlockVoteEvent event) { - final String roomId = event.getRoom().getId(); + final String roomId = event.getRoomId(); broadcastInRoom(roomId, "unlockVote", event.getVotingAdmission()); } @@ -600,7 +602,7 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { for (de.thm.arsnova.model.Content q : event.getQuestions()) { contents.add(new Content(q)); } - broadcastInRoom(event.getRoom().getId(), "lockVotes", contents); + broadcastInRoom(event.getRoomId(), "lockVotes", contents); } @EventListener @@ -609,24 +611,24 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { for (de.thm.arsnova.model.Content q : event.getQuestions()) { contents.add(new Content(q)); } - broadcastInRoom(event.getRoom().getId(), "unlockVotes", contents); + broadcastInRoom(event.getRoomId(), "unlockVotes", contents); } @EventListener public void handleFeatureChange(FeatureChangeEvent event) { - final String roomId = event.getRoom().getId(); - final de.thm.arsnova.model.Room.Settings settings = event.getRoom().getSettings(); - broadcastInRoom(roomId, "featureChange", toV2Migrator.migrate(settings)); - - if (settings.isFlashcardsEnabled()) { - broadcastInRoom(roomId, "countFlashcards", contentService.countFlashcardsForUserInternal(roomId)); +// final String roomId = event.getRoomId(); +// final de.thm.arsnova.model.Room.Settings settings = event.getRoom().getSettings(); +// broadcastInRoom(roomId, "featureChange", toV2Migrator.migrate(settings)); +// +// if (settings.isFlashcardsEnabled()) { +// broadcastInRoom(roomId, "countFlashcards", contentService.countFlashcardsForUserInternal(roomId)); // broadcastInRoom(roomId, "flipFlashcards", event.getRoom().getFlipFlashcards()); - } +// } } @EventListener public void handleLockFeedback(LockFeedbackEvent event) { - broadcastInRoom(event.getRoom().getId(), "lockFeedback", event.getRoom().getSettings().isFeedbackLocked()); +// broadcastInRoom(event.getRoomId(), "lockFeedback", event.getRoom().getSettings().isFeedbackLocked()); } @EventListener @@ -636,7 +638,7 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { @EventListener public void handleNewFeedback(NewFeedbackEvent event) { - this.reportUpdatedFeedbackForRoom(event.getRoom().getId()); + this.reportUpdatedFeedbackForRoom(event.getRoomId()); } @EventListener @@ -647,11 +649,11 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer { @EventListener public void handleStatusRoom(StatusRoomEvent event) { - this.reportRoomStatus(event.getRoom().getId(), !event.getRoom().isClosed()); +// this.reportRoomStatus(event.getRoomId(), !event.getRoom().isClosed()); } @EventListener public void handleChangeScore(ChangeScoreEvent event) { - broadcastInRoom(event.getRoom().getId(), "learningProgressChange", null); + broadcastInRoom(event.getRoomId(), "learningProgressChange", null); } } -- GitLab