diff --git a/src/main/java/de/thm/arsnova/cache/CacheBusterImpl.java b/src/main/java/de/thm/arsnova/cache/CacheBusterImpl.java index 32f2b858b699fb432601668b1ec160def3d1ef84..ab506f7b02e9824ff80488b7da197b258ae31242 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/AfterCreationEvent.java b/src/main/java/de/thm/arsnova/event/AfterCreationEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..5267b6d2efc083b58ba032e451df41817a739ad4 --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/AfterCreationEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class AfterCreationEvent<E extends Entity> extends CrudEvent<E> { + public AfterCreationEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/AfterDeletionEvent.java b/src/main/java/de/thm/arsnova/event/AfterDeletionEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..34115a7442a128dbdcca848318017f1b1001dc3b --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/AfterDeletionEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class AfterDeletionEvent<E extends Entity> extends CrudEvent<E> { + public AfterDeletionEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/AfterPatchEvent.java b/src/main/java/de/thm/arsnova/event/AfterPatchEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..4b73660d36aef3cb763d09f099dbc81535c8a700 --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/AfterPatchEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class AfterPatchEvent<E extends Entity> extends AfterUpdateEvent<E> { + public AfterPatchEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/AfterUpdateEvent.java b/src/main/java/de/thm/arsnova/event/AfterUpdateEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..702173630447bc819fe8bf66771a64c56e8b584d --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/AfterUpdateEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class AfterUpdateEvent<E extends Entity> extends CrudEvent<E> { + public AfterUpdateEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/BeforeCreationEvent.java b/src/main/java/de/thm/arsnova/event/BeforeCreationEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..7235cb4c7518b5e01c70c5a1b146d03756386e11 --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/BeforeCreationEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class BeforeCreationEvent<E extends Entity> extends CrudEvent<E> { + public BeforeCreationEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/BeforeDeletionEvent.java b/src/main/java/de/thm/arsnova/event/BeforeDeletionEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..fac150106ed5900eaa743d038a82f138e8fc9042 --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/BeforeDeletionEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class BeforeDeletionEvent<E extends Entity> extends CrudEvent<E> { + public BeforeDeletionEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/BeforePatchEvent.java b/src/main/java/de/thm/arsnova/event/BeforePatchEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..82eee8540dd42629a35834dbb7f365e962599fb5 --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/BeforePatchEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class BeforePatchEvent<E extends Entity> extends BeforeUpdateEvent<E> { + public BeforePatchEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/BeforeUpdateEvent.java b/src/main/java/de/thm/arsnova/event/BeforeUpdateEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..65fc96e1009ca9a1423fbe596049af898124617f --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/BeforeUpdateEvent.java @@ -0,0 +1,9 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; + +public class BeforeUpdateEvent<E extends Entity> extends CrudEvent<E> { + public BeforeUpdateEvent(final Object source, final E entity) { + super(source, entity); + } +} diff --git a/src/main/java/de/thm/arsnova/event/ChangeScoreEvent.java b/src/main/java/de/thm/arsnova/event/ChangeScoreEvent.java index 46cbaf639c533957e6b98b6c6adb4f267a8af75b..3e2014db5aa2ae43fa9503592b97b6c23d34ad5e 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/CrudEvent.java b/src/main/java/de/thm/arsnova/event/CrudEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..e95cdea65db2b1a6aa4e7dfea2e6ecee74eadd15 --- /dev/null +++ b/src/main/java/de/thm/arsnova/event/CrudEvent.java @@ -0,0 +1,24 @@ +package de.thm.arsnova.event; + +import de.thm.arsnova.model.Entity; +import org.springframework.context.ApplicationEvent; +import org.springframework.core.ResolvableType; +import org.springframework.core.ResolvableTypeProvider; + +public abstract class CrudEvent<E extends Entity> extends ApplicationEvent implements ResolvableTypeProvider { + private E entity; + + public CrudEvent(final Object source, final E entity) { + super(source); + this.entity = entity; + } + + public E getEntity() { + return entity; + } + + @Override + public ResolvableType getResolvableType() { + return ResolvableType.forClassWithGenerics(getClass(), source.getClass()); + } +} diff --git a/src/main/java/de/thm/arsnova/event/DeleteAllLectureAnswersEvent.java b/src/main/java/de/thm/arsnova/event/DeleteAllLectureAnswersEvent.java index 3ed09bb704b4ebaa347e8ef6c1e909e51f327522..0ad169a83f106857f86abfcde7e31bceed8600ab 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 a85f12e2f988013b1e0e170b48d794fbb24c6392..49a8d9342797071f7ebd37b6c75afcdcb9f47f78 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 bf7142ed628ab77fa9bb6d2b2196b42730bc509f..aa671783fd1f776fa34607ad8827a497102149b7 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 a6cd9558a2adeab4c0d9b89e283a072c60bbb805..2bf5bac225a909d0076af155c12c37a03123e581 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 8a7aa4ba1a3cf2ffc752fedd71b7be19f7cb9eec..0000000000000000000000000000000000000000 --- 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 82ba83d101334b36facfb53fe06b0070771780e5..0000000000000000000000000000000000000000 --- 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 bfafb5fe706c94fb3a1b292d20562435a25ea482..0000000000000000000000000000000000000000 --- 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 a650c51a6d55a17273df313b4e5b86f81e2ca556..0000000000000000000000000000000000000000 --- 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 447631a91ab42bddf8a90f2c253ff45931952d53..790eaea277ef8862e588493afcf92f45d842c5ac 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 5b94f9a21e4d3f1c2448fc3199d16ee263aaed8c..c33389f1a8e472624db56141f7779a019b1cd264 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 1f907db30dd45109f78d841af905703dff368a6b..6c50fc4b8cad526d36ed7f5c30b68390515c7a2b 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 2b0e38bd4c261b7af20efa8b31f1effd1b23e0f5..58d5b6fbf60e9fc0dd3d53591e1f36c2bc6c4f4a 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 fb27e4e6cf5c31cba98dadb4ddafef2b2f40d475..869d0c1a0071a765140c5b277ecbb0e8947c5cbb 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 07456ac7b7f52605f596df1375088eb402c1db18..bf3ba29733e2fde71e0da5b6b701ef34f5847721 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 ebff38234b700147bbdd1957e78c1e488ad5d3a6..7595c19a2ebc14b46bdb4429fd7e011548e9dc04 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 462494d9854ce5dc609f7bce65bef97e640cc378..0000000000000000000000000000000000000000 --- 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 0ccf30272328b99e76767b984d9fea397295683a..0000000000000000000000000000000000000000 --- 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 d663f2bb5d0607366800fa91b04e0bd2ce5a9d65..6a5d7290fb1daaa91be63a7ae4cc42091d4e095e 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 53281dceaaea6ad74dc49dd769509f22cf0ae821..0000000000000000000000000000000000000000 --- 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 222fa7c0fdc7c16f55483e9299dc9780cd79f43e..0000000000000000000000000000000000000000 --- 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 27cf4351d875d413fe5f037e803943f1c2e5b51f..73fadca6db1e3a9379dea4ebc691cbb59097d01b 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 43ac5f59bf4eb4e4681dd9effdc975f86ac451c9..c12cc8782616ad96191c46ab3fe592a2b06f79cd 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 064ba458d611d2b9dd0f4567073f73e265ed4078..8d56a813950b1292eff2818bb6b5a54b2cc6d024 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 4d5d773ea302d36a4bdf5661242793e7d4f5f1c5..2b4cd53254f022f33241402c0e13cf595b455eb5 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 eb32f2aaa923c64b342da10300ce938bfdeac1fe..62577df7a272ec5f316fc92c86f700bf64ce500f 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 d91026fde9c00daaab7fc1347e9f684e96581102..d7307cd7919c8fd161e5e1fd3522dc31b101338b 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 3a53ff4427d17f2c6a746e8287c26b674e1fc8e0..deddf45f1f18a762ae3650fd6e8ebd817d967db3 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 50c66f05acd183039a483eb19198349e7d67b6b8..81f38cc60c40641ccd22223e26d0f4a6b80fdc47 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 d6206d6db140b09396f8a159b590e91fa8f1ae4b..3dd6996e3fd8cad2810ce3fd887088864d4a056f 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 cf5fe5f2c95e3c9575eb1b908e167c0d75e14de1..85cf1d06f9a8ce5b55c3fd48b9cc6a0c4dc005bf 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 c7dd6e56127317c99c602a35f4e96a89736aaa51..bc0b146cb937bee6a1dca389b4c634e046b42a5c 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; @@ -37,8 +37,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cache.annotation.CacheEvict; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.access.prepost.PreAuthorize; @@ -55,14 +53,11 @@ import java.util.concurrent.ConcurrentLinkedQueue; * Performs all answer related operations. */ @Service -public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> - implements AnswerService, ApplicationEventPublisherAware { +public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> implements AnswerService { private static final Logger logger = LoggerFactory.getLogger(ContentServiceImpl.class); private final Queue<AnswerQueueElement> answerQueue = new ConcurrentLinkedQueue<>(); - private ApplicationEventPublisher publisher; - private RoomRepository roomRepository; private ContentRepository contentRepository; private AnswerRepository answerRepository; @@ -100,11 +95,12 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> elements.add(entry); } try { + for (AnswerQueueElement e : elements) { + this.eventPublisher.publishEvent(new BeforeCreationEvent<>(this, e.getAnswer())); + } answerRepository.saveAll(answerList); - - // Send NewAnswerEvents ... for (AnswerQueueElement e : elements) { - this.publisher.publishEvent(new NewAnswerEvent(this, e.getRoom(), e.getAnswer(), e.getUserId(), e.getQuestion())); + this.eventPublisher.publishEvent(new AfterCreationEvent<>(this, e.getAnswer())); } } catch (final DbAccessException e) { logger.error("Could not bulk save answers from queue.", e); @@ -357,6 +353,7 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> return answer; } + /* FIXME: Remove, this should be handled by EntityService! */ @Override @PreAuthorize("isAuthenticated()") @CacheEvict(value = "answerlists", allEntries = true) @@ -378,12 +375,14 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> answer.setCreatorId(user.getId()); answer.setContentId(content.getId()); answer.setRoomId(room.getId()); + this.eventPublisher.publishEvent(new BeforeCreationEvent<>(this, realAnswer)); answerRepository.save(realAnswer); - this.publisher.publishEvent(new NewAnswerEvent(this, room, answer, user.getId(), content)); + this.eventPublisher.publishEvent(new AfterCreationEvent<>(this, realAnswer)); return answer; } + /* FIXME: Remove, this should be handled by EntityService! */ @Override @PreAuthorize("isAuthenticated()") @CacheEvict(value = "answerlists", allEntries = true) @@ -397,9 +396,9 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> if (user == null || room == null || !room.getOwnerId().equals(user.getId())) { throw new UnauthorizedException(); } + //this.eventPublisher.publishEvent(new BeforeDeletionEvent<>(answer)); answerRepository.deleteById(answerId); - - this.publisher.publishEvent(new DeleteAnswerEvent(this, room, content)); + //this.eventPublisher.publishEvent(new AfterDeletionEvent<>(answer)); } /* @@ -447,9 +446,4 @@ public class AnswerServiceImpl extends DefaultEntityServiceImpl<Answer> public int countPreparationQuestionAnswersInternal(final String roomId) { return answerRepository.countByRoomIdOnlyPreparationVariant(roomRepository.findOne(roomId).getId()); } - - @Override - public void setApplicationEventPublisher(final ApplicationEventPublisher applicationEventPublisher) { - this.publisher = applicationEventPublisher; - } } diff --git a/src/main/java/de/thm/arsnova/service/CommentServiceImpl.java b/src/main/java/de/thm/arsnova/service/CommentServiceImpl.java index 725b1bc35b72dc67a4503060a43461e473a91969..91e7708ef82922b67b44d8a33183f1af1c6d83f8 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; @@ -11,8 +12,6 @@ import de.thm.arsnova.web.exceptions.ForbiddenException; import de.thm.arsnova.web.exceptions.NotFoundException; import de.thm.arsnova.web.exceptions.UnauthorizedException; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; @@ -27,15 +26,13 @@ import java.util.Map; * Performs all comment related operations. */ @Service -public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implements CommentService, ApplicationEventPublisherAware { +public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implements CommentService { private UserService userService; private CommentRepository commentRepository; private RoomRepository roomRepository; - private ApplicationEventPublisher publisher; - public CommentServiceImpl( CommentRepository repository, RoomRepository roomRepository, @@ -47,11 +44,6 @@ public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implem this.userService = userService; } - @Override - public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { - this.publisher = applicationEventPublisher; - } - @Override @PreAuthorize("isAuthenticated()") public void prepareCreate(final Comment comment) { @@ -65,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) { @@ -72,11 +65,9 @@ public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implem if (comment == null) { throw new NotFoundException(); } + eventPublisher.publishEvent(new BeforeDeletionEvent<>(this, comment)); commentRepository.delete(comment); - - final Room room = roomRepository.findOne(comment.getRoomId()); - final DeleteCommentEvent event = new DeleteCommentEvent(this, room, comment); - this.publisher.publishEvent(event); + eventPublisher.publishEvent(new AfterDeletionEvent<>(this, 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 1b0aee13578d7e734743eb2b82d9acb71e721903..fab8488d6ad775b45a585c0331539fa647ecaa8f 100644 --- a/src/main/java/de/thm/arsnova/service/ContentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/ContentServiceImpl.java @@ -34,8 +34,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; @@ -54,7 +52,7 @@ import java.util.stream.Collectors; * Performs all content related operations. */ @Service -public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implements ContentService, ApplicationEventPublisherAware { +public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implements ContentService { private UserService userService; private LogEntryRepository dbLogger; @@ -65,8 +63,6 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem private AnswerRepository answerRepository; - private ApplicationEventPublisher publisher; - private static final Logger logger = LoggerFactory.getLogger(ContentServiceImpl.class); public ContentServiceImpl( @@ -198,10 +194,9 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem newGroup.setContentIds(newContentIds); room.getContentGroups().add(newGroup); } + eventPublisher.publishEvent(new BeforeCreationEvent<>(this, content)); roomRepository.save(room); - - final NewQuestionEvent event = new NewQuestionEvent(this, room, content); - this.publisher.publishEvent(event); + eventPublisher.publishEvent(new AfterCreationEvent<>(this, content)); } @Override @@ -294,14 +289,13 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem try { final int count = answerRepository.deleteByContentId(contentId); + eventPublisher.publishEvent(new BeforeDeletionEvent<>(this, content)); contentRepository.deleteById(contentId); + eventPublisher.publishEvent(new AfterDeletionEvent<>(this, 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.publisher.publishEvent(event); } @PreAuthorize("hasPermission(#session, 'owner')") @@ -324,8 +318,8 @@ 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); - this.publisher.publishEvent(event); + final DeleteAllQuestionsEvent event = new DeleteAllQuestionsEvent(this, room.getId()); + this.eventPublisher.publishEvent(event); } @Override @@ -371,11 +365,11 @@ 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.publisher.publishEvent(event); + this.eventPublisher.publishEvent(event); } @Override @@ -401,11 +395,11 @@ 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.publisher.publishEvent(event); + this.eventPublisher.publishEvent(event); } catch (IOException e) { logger.error("Patching of contents failed", e); } @@ -502,11 +496,11 @@ 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.publisher.publishEvent(event); + this.eventPublisher.publishEvent(event); } /* TODO: Split and move answer part to AnswerService */ @@ -525,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.publisher.publishEvent(new DeleteAllQuestionsAnswersEvent(this, room)); + this.eventPublisher.publishEvent(new DeleteAllQuestionsAnswersEvent(this, room.getId())); } /* TODO: Split and move answer part to AnswerService */ @@ -541,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.publisher.publishEvent(new DeleteAllPreparationAnswersEvent(this, room)); + this.eventPublisher.publishEvent(new DeleteAllPreparationAnswersEvent(this, room.getId())); } /* TODO: Split and move answer part to AnswerService */ @@ -557,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.publisher.publishEvent(new DeleteAllLectureAnswersEvent(this, room)); + this.eventPublisher.publishEvent(new DeleteAllLectureAnswersEvent(this, room.getId())); } @Caching(evict = { @@ -574,9 +568,4 @@ public class ContentServiceImpl extends DefaultEntityServiceImpl<Content> implem } contentRepository.saveAll(contents); } - - @Override - public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { - this.publisher = publisher; - } } diff --git a/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java b/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java index 9f11f884ba0477dc8facf99bd70416357a3bf461..7767771a5bab29d30cb83cf5d9be39af4dac1629 100644 --- a/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java +++ b/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java @@ -20,9 +20,18 @@ package de.thm.arsnova.service; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; +import de.thm.arsnova.event.AfterCreationEvent; +import de.thm.arsnova.event.AfterPatchEvent; +import de.thm.arsnova.event.AfterUpdateEvent; +import de.thm.arsnova.event.BeforeCreationEvent; +import de.thm.arsnova.event.BeforeDeletionEvent; +import de.thm.arsnova.event.BeforePatchEvent; +import de.thm.arsnova.event.BeforeUpdateEvent; import de.thm.arsnova.model.Entity; import de.thm.arsnova.model.serialization.View; import de.thm.arsnova.persistence.CrudRepository; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreFilter; @@ -38,9 +47,10 @@ import java.util.function.Function; * @param <T> Entity type * @author Daniel Gerhardt */ -public class DefaultEntityServiceImpl<T extends Entity> implements EntityService<T> { +public class DefaultEntityServiceImpl<T extends Entity> implements EntityService<T>, ApplicationEventPublisherAware { protected Class<T> type; protected CrudRepository<T, String> repository; + protected ApplicationEventPublisher eventPublisher; private ObjectMapper objectMapper; public DefaultEntityServiceImpl(Class<T> type, CrudRepository<T, String> repository, ObjectMapper objectMapper) { @@ -82,7 +92,9 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService entity.setCreationTimestamp(new Date()); prepareCreate(entity); + eventPublisher.publishEvent(new BeforeCreationEvent<>(this, entity)); final T createdEntity = repository.save(entity); + eventPublisher.publishEvent(new AfterCreationEvent<>(this, createdEntity)); finalizeCreate(entity); return createdEntity; @@ -117,7 +129,9 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService newEntity.setUpdateTimestamp(new Date()); prepareUpdate(newEntity); + eventPublisher.publishEvent(new BeforeUpdateEvent<>(this, newEntity)); final T updatedEntity = repository.save(newEntity); + eventPublisher.publishEvent(new AfterUpdateEvent<>(this, updatedEntity)); finalizeUpdate(updatedEntity); return updatedEntity; @@ -156,8 +170,11 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService reader.readValue(tree); entity.setUpdateTimestamp(new Date()); preparePatch(entity); + eventPublisher.publishEvent(new BeforePatchEvent<>(this, entity)); + final T patchedEntity = repository.save(entity); + eventPublisher.publishEvent(new AfterPatchEvent<>(this, entity)); - return repository.save(entity); + return patchedEntity; } @Override @@ -176,6 +193,7 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService reader.readValue(tree); entity.setUpdateTimestamp(new Date()); preparePatch(entity); + eventPublisher.publishEvent(new BeforePatchEvent<>(this, entity)); } return repository.saveAll(entities); @@ -194,7 +212,9 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService @Override @PreAuthorize("hasPermission(#entity, 'delete')") public void delete(final T entity) { + eventPublisher.publishEvent(new BeforeDeletionEvent<>(this, entity)); repository.delete(entity); + eventPublisher.publishEvent(new AfterUpdateEvent<>(this, entity)); } /** @@ -209,4 +229,9 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService public String getTypeName() { return type.getSimpleName().toLowerCase(); } + + @Override + public void setApplicationEventPublisher(final ApplicationEventPublisher applicationEventPublisher) { + this.eventPublisher = applicationEventPublisher; + } } diff --git a/src/main/java/de/thm/arsnova/service/FeedbackServiceImpl.java b/src/main/java/de/thm/arsnova/service/FeedbackServiceImpl.java index 842322bfa14a2b490ee5bca5426e09ef2a83eda3..ea4b87312625056348c3d7d38f5bdc3c9916b396 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 f5d566f3f05ba6441b1374d7d2713452d00a222e..83b06681be2f48bf1340ce33d184be14ecb77552 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; @@ -47,8 +48,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.access.prepost.PreAuthorize; @@ -67,7 +66,7 @@ import java.util.stream.Collectors; * Performs all room related operations. */ @Service -public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements RoomService, ApplicationEventPublisherAware { +public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements RoomService { private static final long ROOM_INACTIVITY_CHECK_INTERVAL_MS = 30 * 60 * 1000L; private static final Logger logger = LoggerFactory.getLogger(RoomServiceImpl.class); @@ -96,8 +95,6 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R @Value("${pp.logofilesize_b}") private int uploadFileSizeByte; - private ApplicationEventPublisher publisher; - public RoomServiceImpl( RoomRepository repository, ContentRepository contentRepository, @@ -407,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.publisher.publishEvent(new StatusRoomEvent(this, room)); + this.eventPublisher.publishEvent(new StatusRoomEvent(this, room.getId())); roomRepository.save(room); return room; @@ -458,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<>(this, room)); roomRepository.delete(room); + this.eventPublisher.publishEvent(new AfterDeletionEvent<>(this, room)); logger.debug("Deleted room document {} and related data.", room.getId()); dbLogger.log("delete", "type", "session", "id", room.getId()); - this.publisher.publishEvent(new DeleteRoomEvent(this, room)); - return count; } @@ -511,11 +508,6 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R return roomRepository.importRoom(user.getId(), temp); } - @Override - public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { - this.publisher = publisher; - } - @Override @PreAuthorize("hasPermission(#id, 'room', 'read')") public Room.Settings getFeatures(String id) { @@ -527,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.publisher.publishEvent(new FeatureChangeEvent(this, room)); + this.eventPublisher.publishEvent(new FeatureChangeEvent(this, room.getId())); roomRepository.save(room); return room.getSettings(); @@ -542,7 +534,7 @@ public class RoomServiceImpl extends DefaultEntityServiceImpl<Room> implements R } room.getSettings().setFeedbackLocked(lock); - this.publisher.publishEvent(new LockFeedbackEvent(this, room)); + this.eventPublisher.publishEvent(new LockFeedbackEvent(this, room.getId())); roomRepository.save(room); return room.getSettings().isFeedbackLocked(); @@ -552,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.publisher.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 263ef8caa95e706227d99e16df7e8e1718e01d86..386a49c3b26c196792d92c1a1592917e88b1985d 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 d8267dfae9c16a03901dc4b08d97df4faa37613e..4f29f03e70d65cb86e4acf9ba50a31d3e76d5443 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.getEntity().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.getEntity().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.getEntity().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.getEntity().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 d17fd69b5d656925cc31233131586b886c26bf20..8e99eca9e25362342d03d708d78117842626bf9c 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.getEntity().getId(), Collections.singletonList(event.getEntity())); } @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.getEntity().getId(), event.getEntity().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.getEntity().getRoomId(); + this.reportAnswersToContentAvailable(event.getEntity().getRoomId(), event.getEntity().getContentId()); + broadcastInRoom(roomId, "countQuestionAnswersByQuestionId", answerService.countAnswersAndAbstentionsInternal(event.getEntity().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.getEntity().getRoomId(); + this.reportAnswersToContentAvailable(event.getEntity().getRoomId(), event.getEntity().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); } } diff --git a/src/test/java/de/thm/arsnova/service/DefaultEntityServiceImplTest.java b/src/test/java/de/thm/arsnova/service/DefaultEntityServiceImplTest.java index 7af352356079ee807e99d0cd7ac24183bacc5d4a..90cd9d197c34495a3c83c8ab433531e74bd5cb40 100644 --- a/src/test/java/de/thm/arsnova/service/DefaultEntityServiceImplTest.java +++ b/src/test/java/de/thm/arsnova/service/DefaultEntityServiceImplTest.java @@ -12,6 +12,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; @@ -39,6 +40,9 @@ public class DefaultEntityServiceImplTest { @Qualifier("defaultJsonMessageConverter") private MappingJackson2HttpMessageConverter jackson2HttpMessageConverter; + @Autowired + private ApplicationEventPublisher eventPublisher; + @Autowired private RoomRepository roomRepository; @@ -47,6 +51,7 @@ public class DefaultEntityServiceImplTest { public void testPatch() throws IOException { final ObjectMapper objectMapper = jackson2HttpMessageConverter.getObjectMapper(); final DefaultEntityServiceImpl<Room> entityService = new DefaultEntityServiceImpl<>(Room.class, roomRepository, objectMapper); + entityService.setApplicationEventPublisher(eventPublisher); when(roomRepository.save(any(Room.class))).then(returnsFirstArg()); @@ -80,6 +85,7 @@ public class DefaultEntityServiceImplTest { public void testPatchWithList() throws IOException { final ObjectMapper objectMapper = jackson2HttpMessageConverter.getObjectMapper(); final DefaultEntityServiceImpl<Room> entityService = new DefaultEntityServiceImpl<>(Room.class, roomRepository, objectMapper); + entityService.setApplicationEventPublisher(eventPublisher); when(roomRepository.save(any(Room.class))).then(returnsFirstArg());