Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General: Add cleanup service for admins #9296

Open
wants to merge 142 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 134 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
c5df40e
add cleanup service skeleton
dmytropolityka Sep 2, 2024
a817dbe
update AdminOldDataCleanUpResource.java
coolchock Sep 5, 2024
c099bb1
update OldDataCleanUpRepository
coolchock Sep 5, 2024
1e1a790
update OldDataCleanupService
coolchock Sep 5, 2024
d941086
create cleanup-service components
coolchock Sep 5, 2024
b1188de
update admin routes
coolchock Sep 5, 2024
0d31a8c
add cleanup operation model
coolchock Sep 5, 2024
c9b81d1
add declaration in the admin module
coolchock Sep 5, 2024
508a2fe
add cleanup requests
coolchock Sep 5, 2024
7b8527c
add translations
coolchock Sep 5, 2024
b0aa22c
update navbar
coolchock Sep 5, 2024
36aefe6
add TODO
coolchock Sep 5, 2024
28b050d
add TODO
coolchock Sep 5, 2024
9d2e83e
remove button
coolchock Sep 5, 2024
6b4ce82
update navbar.component.html
coolchock Sep 5, 2024
a7704d4
add validation
coolchock Sep 5, 2024
eeedc44
extend date-time-picker
coolchock Sep 5, 2024
8e7ab57
fix queries to support date from; remove dates for orphans; save exec…
dmytropolityka Sep 6, 2024
5fdc5d6
implement last executed date, refactor queries
dmytropolityka Sep 7, 2024
4153025
include master xml
dmytropolityka Sep 7, 2024
e2d4cae
prettier
coolchock Sep 7, 2024
25315ab
add cleanup-service.service.spec.ts
coolchock Sep 7, 2024
b1f4416
rename method
coolchock Sep 7, 2024
138716c
remove console log
coolchock Sep 7, 2024
bc461aa
add cleanup-service.component.spec.ts
coolchock Sep 7, 2024
06f2778
remove unused icons
coolchock Sep 7, 2024
58b7e99
fix types
coolchock Sep 7, 2024
76d5f7e
add missing profiles
coolchock Sep 7, 2024
5b1c77f
add missing profiles
coolchock Sep 7, 2024
bbdc74f
change prefilled dates
coolchock Sep 7, 2024
a377eac
add integration tests
dmytropolityka Sep 8, 2024
c9bc1bf
adapt tests and queries
dmytropolityka Sep 9, 2024
81bc8e4
further integration tests
dmytropolityka Sep 11, 2024
8f66d9b
add final tests
dmytropolityka Sep 12, 2024
b8eeb32
javadoc
dmytropolityka Sep 12, 2024
ac10b3f
Update src/main/java/de/tum/in/www1/artemis/service/cleanup/DataClean…
dmytropolityka Sep 13, 2024
65a6046
Update src/main/webapp/app/admin/cleanup-service/cleanup-service.serv…
dmytropolityka Sep 13, 2024
1c90659
Update src/main/webapp/app/admin/cleanup-service/cleanup-service.serv…
dmytropolityka Sep 13, 2024
9ce8122
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 13, 2024
8621379
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 13, 2024
9e84ee8
merge develop + merge conflicts
dmytropolityka Sep 13, 2024
842198a
fix an issue in cleanup service
dmytropolityka Sep 13, 2024
adf5757
change request type
dmytropolityka Sep 13, 2024
fba9300
fix pr checks
dmytropolityka Sep 14, 2024
c71a0c7
spotless
dmytropolityka Sep 14, 2024
40b1fd2
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 14, 2024
ffa1fac
fix other tests
dmytropolityka Sep 14, 2024
b599a12
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 14, 2024
761302c
pr comments of Patrik
dmytropolityka Sep 14, 2024
8cc8e91
prettier, spotless and other comments
dmytropolityka Sep 14, 2024
7f3bdea
fix type
dmytropolityka Sep 14, 2024
b2f618c
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 14, 2024
52b298d
disable all cleanup related tests for debugging purposes
dmytropolityka Sep 14, 2024
e0fa881
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 14, 2024
5ab1c67
fix enum labels
dmytropolityka Sep 14, 2024
24b5a77
reenable a test
dmytropolityka Sep 14, 2024
b91bb26
make the component standalone
coolchock Sep 14, 2024
fa071ae
remove component declaration from module
coolchock Sep 14, 2024
082ba6d
enable further test, fix standalone component test
dmytropolityka Sep 14, 2024
c71f732
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 15, 2024
87b034e
rollback after test
dmytropolityka Sep 15, 2024
bf4129e
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 15, 2024
40ed1bd
reenable tests
dmytropolityka Sep 15, 2024
dfd4b66
Revert "reenable tests"
dmytropolityka Sep 15, 2024
9103e5c
change base test class
dmytropolityka Sep 15, 2024
3861328
change base test class
dmytropolityka Sep 15, 2024
c8c8775
use signals
coolchock Sep 15, 2024
da1523f
set exercises for test participant scores
dmytropolityka Sep 15, 2024
afdb376
adjust test for signals
coolchock Sep 15, 2024
0a83b12
add new translation keys
coolchock Sep 15, 2024
d0fe4ad
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
coolchock Sep 15, 2024
97a03d9
set participants for test participant scores
dmytropolityka Sep 15, 2024
7927292
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 15, 2024
6bd0198
move endpoints to another level
dmytropolityka Sep 16, 2024
f7f232c
Update src/main/java/de/tum/cit/aet/artemis/core/repository/cleanup/C…
dmytropolityka Sep 19, 2024
a46d6ad
CR of Johannes
dmytropolityka Sep 19, 2024
58829af
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 19, 2024
93ff187
fix npe in test
dmytropolityka Sep 19, 2024
bfa380b
fix client build error
dmytropolityka Sep 19, 2024
f973427
rollback
dmytropolityka Sep 19, 2024
c64a5b4
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 20, 2024
550189c
use left joins for plagiarism comparisons
dmytropolityka Sep 20, 2024
5ab8960
use left joins for results
dmytropolityka Sep 20, 2024
2c215b9
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
dmytropolityka Sep 20, 2024
1ec0def
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 20, 2024
2467089
change the query for plagiarism comparisons
dmytropolityka Sep 20, 2024
1b54fa0
prettier
dmytropolityka Sep 20, 2024
cb0fd7f
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 20, 2024
9ab61c6
adjust comment
coolchock Sep 21, 2024
a50a874
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Sep 23, 2024
9e3d5dd
change api
dmytropolityka Sep 30, 2024
fc8e334
Merge remote-tracking branch 'origin/develop' into feature/general/cl…
dmytropolityka Sep 30, 2024
f10e985
move queries to respective repositories
dmytropolityka Oct 1, 2024
36a6f3f
fix some style issues
dmytropolityka Oct 1, 2024
68e668a
fix some style issues
dmytropolityka Oct 1, 2024
3e9cccd
fix repository formatting
dmytropolityka Oct 2, 2024
b362ce1
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Oct 2, 2024
b44fac9
reformat, add javadocs
dmytropolityka Oct 2, 2024
9ca67e1
fix test
dmytropolityka Oct 2, 2024
4d4eb98
Update src/main/java/de/tum/cit/aet/artemis/assessment/repository/Tex…
dmytropolityka Oct 2, 2024
43e369d
fix style
dmytropolityka Oct 2, 2024
587c748
remove empty line
dmytropolityka Oct 2, 2024
2e29729
adjust javadoc
dmytropolityka Oct 2, 2024
b9ca3c6
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Oct 3, 2024
31fc02e
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Oct 3, 2024
cf41472
comments of Johannes
dmytropolityka Oct 4, 2024
1afaff4
remove text from span
dmytropolityka Oct 4, 2024
1339ca2
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Oct 10, 2024
3b00bea
Merge branch 'develop' into feature/general/cleanup-service
krusche Oct 13, 2024
6465473
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Oct 16, 2024
f53d83d
Merge branch 'develop' into feature/general/cleanup-service
krusche Oct 18, 2024
509271b
Merge branch 'develop' into feature/general/cleanup-service
krusche Oct 19, 2024
9b1c3fa
improve code quality
krusche Oct 19, 2024
18b11e0
use cleanup repositories in DataCleanupService
coolchock Oct 21, 2024
116cc43
add TextBlockCleanupRepository
coolchock Oct 21, 2024
11ce805
add TeamScoreCleanupRepository
coolchock Oct 21, 2024
b7fbdf4
add StudentScoreCleanupRepository
coolchock Oct 21, 2024
ea6e41c
add PlagiarismComparisonCleanupRepository
coolchock Oct 21, 2024
cea2cb1
add TextBlockRepository
coolchock Oct 21, 2024
a990f9c
remove cleanup methods from TeamScoreRepository
coolchock Oct 21, 2024
7b9579e
remove cleanup methods from StudentScoreRepository
coolchock Oct 21, 2024
52869bc
remove cleanup methods from ResultCleanupRepository
coolchock Oct 21, 2024
6ce9c4b
remove cleanup methods from PlagiarismComparisonRepository
coolchock Oct 21, 2024
27f5550
remove cleanup methods from FeedbackCleanupRepository
coolchock Oct 21, 2024
e25a086
fix style issues
coolchock Oct 21, 2024
494f520
adjust CleanupIntegrationTest
coolchock Oct 21, 2024
9ab7cbb
Merge branch 'develop' into feature/general/cleanup-service
dmytropolityka Oct 24, 2024
8b5eb3d
spotless
dmytropolityka Oct 24, 2024
df5565d
Merge branch 'develop' into feature/general/cleanup-service
krusche Oct 27, 2024
ff94897
fix query (formatting) issues
krusche Oct 27, 2024
510a0ca
remove redundant new line
coolchock Oct 28, 2024
d2e6962
fix formatting in deleteNonLatestRatedResultsWhereCourseDateBetween
coolchock Oct 28, 2024
25af449
Merge remote-tracking branch 'origin/feature/general/cleanup-service'…
coolchock Oct 28, 2024
ab28dd2
Merge branch 'refs/heads/develop' into feature/general/cleanup-service
coolchock Oct 28, 2024
a03e853
make mysql test pass
dmytropolityka Oct 29, 2024
00a1a1a
Revert "make mysql test pass"
dmytropolityka Oct 29, 2024
86c32b3
revert previous fix; implement a more performant mysql fix; reformat …
dmytropolityka Oct 30, 2024
ec82065
spotless
dmytropolityka Oct 30, 2024
9e0e807
fix arch test
dmytropolityka Oct 30, 2024
6d75d51
update documentation
dmytropolityka Oct 31, 2024
8dcec86
fix an issue in the docu
dmytropolityka Nov 2, 2024
7de5b13
underline title
dmytropolityka Nov 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public interface FeedbackRepository extends ArtemisJpaRepository<Feedback, Long>

@Query("""
SELECT feedback
FROM Feedback feedback
WHERE feedback.gradingInstruction.id IN :gradingInstructionsIds
FROM Feedback feedback
WHERE feedback.gradingInstruction.id IN :gradingInstructionsIds
""")
List<Feedback> findFeedbackByGradingInstructionIds(@Param("gradingInstructionsIds") List<Long> gradingInstructionsIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ public interface StudentScoreRepository extends ArtemisJpaRepository<StudentScor
@Transactional // ok because of delete
@Modifying
void deleteByExerciseAndUser(Exercise exercise, User user);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package de.tum.cit.aet.artemis.assessment.repository.cleanup;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.time.ZonedDateTime;

import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.assessment.domain.Feedback;
import de.tum.cit.aet.artemis.assessment.domain.Result;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.exercise.domain.participation.Participation;

/**
* Spring Data JPA repository for cleaning up old and orphaned feedback entries.
* THE FOLLOWING METHODS ARE USED FOR CLEANUP PURPOSES AND SHOULD NOT BE USED IN OTHER CASES
*/
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
@Profile(PROFILE_CORE)
@Repository
public interface FeedbackCleanupRepository extends ArtemisJpaRepository<Feedback, Long> {

/**
* Deletes {@link Feedback} entries where the associated {@link Result} has no submission and no participation.
*/
@Modifying
@Transactional // ok because of delete
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
// Subquery ok
@Query("""
DELETE FROM Feedback f
WHERE f.result IN (
SELECT r
FROM Result r
WHERE r.submission IS NULL
AND r.participation IS NULL
)
""")
void deleteFeedbackForOrphanResults();
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link Feedback} entries with a {@code null} result.
* Returns {@code void}
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM Feedback f
WHERE f.result IS NULL
""")
void deleteOrphanFeedback();

/**
* Deletes {@link Feedback} entries associated with rated {@link Result} that are not the latest rated result
* for a {@link Participation}, within courses conducted between the specified date range.
* This query removes old feedback entries that are not part of the latest rated results, for courses whose
* end date is before {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM Feedback f
WHERE f.result IN (
SELECT r
FROM Result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE r.id NOT IN (
SELECT MAX(r2.id)
FROM Result r2
WHERE r2.participation.id = p.id
AND r2.rated = TRUE
)
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
)
""")
void deleteOldFeedbackThatAreNotLatestRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
coolchock marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes non-rated {@link Feedback} entries that are not the latest non-rated result, where the associated course's start and end dates
* are between the specified date range.
* This query removes old feedback entries that are not part of the latest non-rated result within courses whose end date is before
* {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM Feedback f
WHERE f.result IN (
SELECT r
FROM Result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE r.id NOT IN (
SELECT MAX(r2.id)
FROM Result r2
WHERE r2.participation.id = p.id)
AND r.rated = FALSE
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
)
""")
void deleteOldNonRatedFeedbackWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package de.tum.cit.aet.artemis.assessment.repository.cleanup;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.time.ZonedDateTime;

import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.assessment.domain.Feedback;
import de.tum.cit.aet.artemis.assessment.domain.LongFeedbackText;
import de.tum.cit.aet.artemis.assessment.domain.Result;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.exercise.domain.participation.Participation;

/**
* Spring Data JPA repository for cleaning up old and orphaned long feedback text entries.
* THE FOLLOWING METHODS ARE USED FOR CLEANUP PURPOSES AND SHOULD NOT BE USED IN OTHER CASES
*/
@Profile(PROFILE_CORE)
@Repository
public interface LongFeedbackTextCleanupRepository extends ArtemisJpaRepository<LongFeedbackText, Long> {

/**
* Deletes {@link LongFeedbackText} entries linked to {@link Feedback} where the associated
* {@link Result} has no participation and no submission.
*/
@Modifying
@Transactional // ok because of delete
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
@Query("""
DELETE FROM LongFeedbackText lft
WHERE lft.feedback.id IN (
SELECT f.id
FROM Feedback f
WHERE f.result.participation IS NULL
AND f.result.submission IS NULL
)
""")
void deleteLongFeedbackTextForOrphanResult();
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link LongFeedbackText} linked to {@link Feedback} with a {@code null} result.
* Returns {@code void}
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM LongFeedbackText lft
WHERE lft.feedback IN (
SELECT f
FROM Feedback f
WHERE f.result IS NULL
)
""")
void deleteLongFeedbackTextForOrphanedFeedback();
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link LongFeedbackText} entries associated with rated {@link Result} that are not the latest rated result
* for a {@link Participation}, within courses conducted between the specified date range.
* This query removes old long feedback text that is not part of the latest rated results, for courses whose
* end date is before {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM LongFeedbackText lft
WHERE lft.feedback IN (
SELECT f
FROM Feedback f
LEFT JOIN f.result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE f.result.id NOT IN (
SELECT MAX(r2.id)
FROM Result r2
WHERE r2.participation.id = p.id
AND r2.rated = TRUE
)
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
)
""")
void deleteLongFeedbackTextForRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link LongFeedbackText} entries linked to non-rated {@link Feedback} that are not the latest rated result where the associated course's start
* and end dates are between the specified date range.
* This query deletes long feedback text for feedback associated with non-rated results, within courses whose
* end date is before {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM LongFeedbackText lft
WHERE lft.feedback IN (
SELECT f
FROM Feedback f
LEFT JOIN f.result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE f.result.id NOT IN (
SELECT MAX(r2.id)
FROM Result r2
WHERE r2.participation.id = p.id
AND r2.rated = FALSE
)
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
)
""")
void deleteLongFeedbackTextForNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package de.tum.cit.aet.artemis.assessment.repository.cleanup;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.time.ZonedDateTime;

import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.assessment.domain.ParticipantScore;
import de.tum.cit.aet.artemis.assessment.domain.Result;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.exercise.domain.participation.Participation;

/**
* Spring Data JPA repository for cleaning up old and orphaned participant scores.
* THE FOLLOWING METHODS ARE USED FOR CLEANUP PURPOSES AND SHOULD NOT BE USED IN OTHER CASES
*/
@Profile(PROFILE_CORE)
@Repository
public interface ParticipantScoreCleanupRepository extends ArtemisJpaRepository<ParticipantScore, Long> {

/**
* Deletes {@link ParticipantScore} entries where the associated {@link Result} is not the latest rated result
* for a {@link Participation}, within courses conducted between the specified date range.
* This query removes participant scores linked to results that are not the most recent rated results, for courses
* whose end date is before {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
@Query("""
DELETE FROM ParticipantScore ps
WHERE ps.lastResult IN (
SELECT r
FROM Result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
WHERE r.id NOT IN (
SELECT MAX(r2.id)
FROM Result r2
WHERE r2.participation.id = p.id
AND r2.rated = TRUE
)
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
)
""")
void deleteParticipantScoresForNonLatestLastResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link ParticipantScore} entries where the associated last rated {@link Result} is not the latest rated result
* for a {@link Participation}, within courses conducted between the specified date range.
* This query removes participant scores linked to rated results that are not the most recent rated results, for courses
* whose end date is before {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM ParticipantScore ps
WHERE ps.lastRatedResult IN (
SELECT r
FROM Result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE r.id NOT IN (
SELECT MAX(r2.id)
FROM Result r2
WHERE r2.participation.id = p.id
AND r2.rated = TRUE
)
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
)
""")
void deleteParticipantScoresForNonLatestLastRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link ParticipantScore} entries where the associated {@link Result} is the latest result and is non-rated,
* and the course's start and end dates are between the specified date range.
* This query deletes participant scores for non-rated results within courses whose end date is before
* {@code deleteTo} and start date is after {@code deleteFrom}.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM ParticipantScore ps
WHERE ps.lastResult IN (
SELECT r
FROM Result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE r.rated = FALSE
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom )
""")
void deleteParticipantScoresForLatestNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes {@link ParticipantScore} entries where the associated {@link Result} is non-rated, even though
* it is marked as the last rated result, to prevent potential integrity violations.
* The deletion is based on courses whose start and end dates fall within the specified range.
* This scenario should not normally occur, as non-rated results cannot be marked as rated, but the
* method ensures cleanup in case of any potential integrity issues.
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM ParticipantScore ps
WHERE ps.lastRatedResult IN (
SELECT r
FROM Result r
LEFT JOIN r.participation p
LEFT JOIN p.exercise e
LEFT JOIN e.course c
WHERE r.rated = FALSE
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom
)
""")
void deleteParticipantScoresForNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
dmytropolityka marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading