From 74a3d4d17153596eaedaef16e7434012c738ad38 Mon Sep 17 00:00:00 2001 From: Paul Rangger Date: Mon, 23 Dec 2024 16:37:43 +0100 Subject: [PATCH] Remove warning --- .../artemis/communication/domain/AnswerPost.java | 13 ------------- .../cit/aet/artemis/communication/domain/Post.java | 13 ------------- .../repository/ConversationMessageRepository.java | 1 - .../repository/SavedPostRepository.java | 10 ++++++++++ .../communication/service/AnswerMessageService.java | 5 +++++ .../service/ConversationMessagingService.java | 5 +++++ .../service/SavedPostScheduleService.java | 2 +- 7 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/domain/AnswerPost.java b/src/main/java/de/tum/cit/aet/artemis/communication/domain/AnswerPost.java index 9469d9e6d818..bcb3218eb621 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/domain/AnswerPost.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/domain/AnswerPost.java @@ -14,7 +14,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.SQLRestriction; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -39,13 +38,6 @@ public class AnswerPost extends Posting { @OneToMany(mappedBy = "answerPost", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER) private Set reactions = new HashSet<>(); - /*** - * The value 1 represents an answer post, given by the enum {{@link PostingType}} - */ - @OneToMany(mappedBy = "postId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.LAZY) - @SQLRestriction("post_type = 1") - private Set savedPosts = new HashSet<>(); - @ManyToOne @JsonIncludeProperties({ "id", "exercise", "lecture", "course", "courseWideContext", "conversation", "author" }) private Post post; @@ -90,11 +82,6 @@ public void setPost(Post post) { this.post = post; } - @JsonIgnore - public Set getSavedPosts() { - return savedPosts; - } - @JsonProperty("isSaved") public boolean getIsSaved() { return isSaved; diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java b/src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java index 3bb92cb6a540..f6511017f1c6 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java @@ -21,7 +21,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.SQLRestriction; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -57,13 +56,6 @@ public class Post extends Posting { @OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER) private Set answers = new HashSet<>(); - /*** - * The value 0 represents a post, given by the enum {{@link PostingType}} - */ - @OneToMany(mappedBy = "postId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.LAZY) - @SQLRestriction("post_type = 0") - private Set savedPosts = new HashSet<>(); - @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "post_tag", joinColumns = @JoinColumn(name = "post_id")) @Column(name = "text") @@ -235,11 +227,6 @@ public void setVoteCount(Integer voteCount) { this.voteCount = voteCount != null ? voteCount : 0; } - @JsonIgnore - public Set getSavedPosts() { - return savedPosts; - } - @JsonProperty("isSaved") public boolean getIsSaved() { return isSaved; diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java b/src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java index 16c5be3aedc8..2952c5213432 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java @@ -114,7 +114,6 @@ private PageImpl findPostsWithSpecification(Pageable pageable, Specificati LEFT JOIN FETCH p.conversation LEFT JOIN FETCH p.reactions LEFT JOIN FETCH p.tags - LEFT JOIN FETCH p.savedPosts LEFT JOIN FETCH p.answers a LEFT JOIN FETCH a.reactions LEFT JOIN FETCH a.post diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java b/src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java index e0a00a5896aa..f490650f4fc4 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java @@ -46,6 +46,16 @@ public interface SavedPostRepository extends ArtemisJpaRepository findSavedPostByPostIdAndPostType(Long postId, PostingType postType); + /*** * Query all post ids that a user has saved by a certain posting type. Cached by user id and post type. * diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java index f7645c202f63..d195ef870d7a 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java @@ -12,6 +12,7 @@ import de.tum.cit.aet.artemis.communication.domain.AnswerPost; import de.tum.cit.aet.artemis.communication.domain.Post; +import de.tum.cit.aet.artemis.communication.domain.PostingType; import de.tum.cit.aet.artemis.communication.domain.conversation.Channel; import de.tum.cit.aet.artemis.communication.domain.conversation.Conversation; import de.tum.cit.aet.artemis.communication.domain.notification.SingleUserNotification; @@ -209,6 +210,10 @@ public void deleteAnswerMessageById(Long courseId, Long answerMessageId) { answerPostRepository.deleteById(answerMessageId); preparePostForBroadcast(updatedMessage); + // Delete all connected saved posts + var savedPosts = savedPostRepository.findSavedPostByPostIdAndPostType(answerMessageId, PostingType.ANSWER); + savedPostRepository.deleteAll(savedPosts); + broadcastForPost(new PostDTO(updatedMessage, MetisCrudAction.UPDATE), course.getId(), null, null); } diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java index 06f9409bddc0..9f66ebb10a21 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java @@ -27,6 +27,7 @@ import de.tum.cit.aet.artemis.communication.domain.DisplayPriority; import de.tum.cit.aet.artemis.communication.domain.NotificationType; import de.tum.cit.aet.artemis.communication.domain.Post; +import de.tum.cit.aet.artemis.communication.domain.PostingType; import de.tum.cit.aet.artemis.communication.domain.conversation.Channel; import de.tum.cit.aet.artemis.communication.domain.conversation.Conversation; import de.tum.cit.aet.artemis.communication.domain.conversation.GroupChat; @@ -371,6 +372,10 @@ public void deleteMessageById(Long courseId, Long postId) { conversationParticipantRepository.decrementUnreadMessagesCountOfParticipants(conversation.getId(), user.getId()); conversation = conversationService.getConversationById(conversation.getId()); + // Delete all connected saved posts + var savedPosts = savedPostRepository.findSavedPostByPostIdAndPostType(postId, PostingType.POST); + savedPostRepository.deleteAll(savedPosts); + conversationService.notifyAllConversationMembersAboutUpdate(conversation); preparePostForBroadcast(post); broadcastForPost(new PostDTO(post, MetisCrudAction.DELETE), course.getId(), null, null); diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/SavedPostScheduleService.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/SavedPostScheduleService.java index 25e5922031f5..e2487b77e887 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/SavedPostScheduleService.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/SavedPostScheduleService.java @@ -45,7 +45,7 @@ public void cleanupArchivedSavedPosts() { /** * Cleans up all saved posts where the post entity does not exist anymore */ - @Scheduled(cron = "0 0 0 * * *") + @Scheduled(cron = "0 5 0 * * *") public void cleanupOrphanedSavedPosts() { List orphanedPosts = savedPostRepository.findOrphanedPostReferences(); if (!orphanedPosts.isEmpty()) {