Skip to content

Commit

Permalink
Development: Fix issues with admin cleanup service and improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Nov 10, 2024
1 parent 110d047 commit b932844
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 68 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ module.exports = {
coverageThreshold: {
global: {
// TODO: in the future, the following values should increase to at least 90%
statements: 87.55,
branches: 73.68,
functions: 82.12,
lines: 87.61,
statements: 87.67,
branches: 73.81,
functions: 82.17,
lines: 87.72X,
},
},
coverageReporters: ['clover', 'json', 'lcov', 'text-summary'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface FeedbackCleanupRepository extends ArtemisJpaRepository<Feedback

/**
* Deletes {@link Feedback} entries where the associated {@link Result} has no submission and no participation.
*
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -39,18 +41,20 @@ WHERE f.result IN (
AND r.participation IS NULL
)
""")
void deleteFeedbackForOrphanResults();
int deleteFeedbackForOrphanResults();

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

/**
* Deletes {@link Feedback} entries associated with rated {@link Result} that are not the latest rated result
Expand All @@ -60,6 +64,7 @@ WHERE f.result IN (
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -82,7 +87,7 @@ SELECT MAX(r2.id)
AND c.startDate > :deleteFrom
)
""")
void deleteOldFeedbackThatAreNotLatestRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteOldFeedbackThatAreNotLatestRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);

/**
* Deletes non-rated {@link Feedback} entries that are not the latest non-rated result, where the associated course's start and end dates
Expand All @@ -92,6 +97,7 @@ SELECT MAX(r2.id)
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -113,5 +119,5 @@ SELECT MAX(r2.id)
AND c.startDate > :deleteFrom
)
""")
void deleteOldNonRatedFeedbackWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteOldNonRatedFeedbackWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface LongFeedbackTextCleanupRepository extends ArtemisJpaRepository<
/**
* Deletes {@link LongFeedbackText} entries linked to {@link Feedback} where the associated
* {@link Result} has no participation and no submission.
*
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -40,10 +42,12 @@ WHERE lft.feedback.id IN (
AND f.result.submission IS NULL
)
""")
void deleteLongFeedbackTextForOrphanResult();
int deleteLongFeedbackTextForOrphanResult();

/**
* Deletes {@link LongFeedbackText} linked to {@link Feedback} with a {@code null} result.
*
* @return the number of deleted {@link LongFeedbackText} entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -55,7 +59,7 @@ WHERE lft.feedback IN (
WHERE f.result IS NULL
)
""")
void deleteLongFeedbackTextForOrphanedFeedback();
int deleteLongFeedbackTextForOrphanedFeedback();

/**
* Deletes {@link LongFeedbackText} entries associated with rated {@link Result} that are not the latest rated result
Expand All @@ -65,6 +69,7 @@ WHERE lft.feedback IN (
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -88,7 +93,7 @@ SELECT MAX(r2.id)
AND r.rated = TRUE
)
""")
void deleteLongFeedbackTextForRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteLongFeedbackTextForRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);

/**
* Deletes {@link LongFeedbackText} entries linked to non-rated {@link Feedback} that are not the latest non-rated result where the associated course's start
Expand All @@ -98,6 +103,7 @@ SELECT MAX(r2.id)
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -121,5 +127,5 @@ SELECT MAX(r2.id)
AND c.startDate > :deleteFrom
)
""")
void deleteLongFeedbackTextForNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteLongFeedbackTextForNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface ParticipantScoreCleanupRepository extends ArtemisJpaRepository<
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -54,7 +55,7 @@ SELECT MAX(r2.id)
AND c.startDate > :deleteFrom
)
""")
void deleteParticipantScoresForNonLatestLastResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteParticipantScoresForNonLatestLastResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);

/**
* Deletes {@link ParticipantScore} entries where the associated last rated {@link Result} is not the latest rated result
Expand All @@ -64,6 +65,7 @@ SELECT MAX(r2.id)
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -86,7 +88,7 @@ SELECT MAX(r2.id)
AND c.startDate > :deleteFrom
)
""")
void deleteParticipantScoresForNonLatestLastRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteParticipantScoresForNonLatestLastRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);

/**
* Deletes {@link ParticipantScore} entries where the associated {@link Result} is not the latest result and is non-rated,
Expand All @@ -96,6 +98,7 @@ SELECT MAX(r2.id)
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -117,7 +120,7 @@ SELECT MAX(r2.id)
AND c.endDate < :deleteTo
AND c.startDate > :deleteFrom )
""")
void deleteParticipantScoresForLatestNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteParticipantScoresForLatestNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);

/**
* Deletes {@link ParticipantScore} entries where the associated {@link Result} is not latest and is non-rated, even though
Expand All @@ -128,6 +131,7 @@ SELECT MAX(r2.id)
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -150,5 +154,5 @@ SELECT MAX(r2.id)
AND c.startDate > :deleteFrom
)
""")
void deleteParticipantScoresForNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteParticipantScoresForNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,48 @@ public interface PlagiarismComparisonCleanupRepository extends ArtemisJpaReposit

@Modifying
@Transactional // ok because of delete
void deleteByIdIn(List<Long> ids);
@Query("""
DELETE
FROM PlagiarismComparison pc
WHERE pc.id IN :ids
""")
int deleteByIdsIn(@Param("ids") List<Long> ids);

@Modifying
@Transactional // ok because of delete
@Query("""
DELETE
FROM PlagiarismSubmissionElement e
WHERE e.plagiarismSubmission.plagiarismComparison.id IN :ids
""")
int deletePlagiarismSubmissionElementsByComparisonIdsIn(@Param("ids") List<Long> ids);

@Modifying
@Transactional // ok because of delete
@Query("""
DELETE
FROM PlagiarismSubmission s
WHERE s.plagiarismComparison.id IN :ids
""")
int deletePlagiarismSubmissionsByComparisonIdsIn(@Param("ids") List<Long> ids);

@Modifying
@Transactional // ok because of modifying
@Query("""
UPDATE PlagiarismComparison pc
SET pc.submissionA = NULL, pc.submissionB = NULL
WHERE pc.id IN :ids
""")
int setPlagiarismSubmissionsToNullInComparisonsWithIds(@Param("ids") List<Long> ids);

@Modifying
@Transactional // ok because of delete
@Query(nativeQuery = true, value = """
DELETE
FROM plagiarism_comparison_matches m
WHERE m.plagiarism_comparison_id IN :ids
""")
int deletePlagiarismComparisonMatchesByComparisonIdsIn(@Param("ids") List<Long> ids);

/**
* Retrieves a list of unnecessary plagiarism comparison IDs based on the associated course's date range.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface RatingCleanupRepository extends ArtemisJpaRepository<Rating, Lo

/**
* Deletes {@link Rating} entries where the associated {@link Result} has no submission and no participation.
*
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -35,5 +37,5 @@ WHERE rt.result IN (
AND r.participation IS NULL
)
""")
void deleteOrphanRating();
int deleteOrphanRating();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface ResultCleanupRepository extends ArtemisJpaRepository<Result, Lo

/**
* Deletes {@link Result} entries that have no participation and no submission.
*
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -35,7 +37,7 @@ public interface ResultCleanupRepository extends ArtemisJpaRepository<Result, Lo
WHERE r.participation IS NULL
AND r.submission IS NULL
""")
void deleteResultWithoutParticipationAndSubmission();
int deleteResultWithoutParticipationAndSubmission();

/**
* Deletes non-rated {@link Result} entries that are not the latest result where the associated {@link Participation} and {@link Exercise} are not null,
Expand All @@ -45,6 +47,7 @@ public interface ResultCleanupRepository extends ArtemisJpaRepository<Result, Lo
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -71,7 +74,7 @@ SELECT MAX(r2.id) AS max_id
)
)
""")
void deleteNonLatestNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteNonLatestNonRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);

/**
* Deletes rated {@link Result} entries that are not the latest rated result for a {@link Participation}, within courses
Expand All @@ -81,6 +84,7 @@ SELECT MAX(r2.id) AS max_id
*
* @param deleteFrom the start date for selecting courses
* @param deleteTo the end date for selecting courses
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
Expand All @@ -107,5 +111,5 @@ SELECT MAX(r2.id) AS max_id
)
)
""")
void deleteNonLatestRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
int deleteNonLatestRatedResultsWhereCourseDateBetween(@Param("deleteFrom") ZonedDateTime deleteFrom, @Param("deleteTo") ZonedDateTime deleteTo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public interface StudentScoreCleanupRepository extends ArtemisJpaRepository<Stud

/**
* Deletes {@link StudentScore} entries where the associated user is {@code null}.
*
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM StudentScore ps
WHERE ps.user IS NULL
""")
void deleteOrphanStudentScore();
int deleteOrphanStudentScore();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public interface TeamScoreCleanupRepository extends ArtemisJpaRepository<TeamSco

/**
* Deletes {@link TeamScore} entries where the associated team is {@code null}.
*
* @return the number of deleted entities
*/
@Modifying
@Transactional // ok because of delete
@Query("""
DELETE FROM TeamScore ps
WHERE ps.team IS NULL
""")
void deleteOrphanTeamScore();
int deleteOrphanTeamScore();
}
Loading

0 comments on commit b932844

Please sign in to comment.