Skip to content

Commit

Permalink
Development: Adjust server tests to restructuring into modules (#9314)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAnzinger authored Sep 28, 2024
1 parent 85fc9b7 commit c7ccd42
Show file tree
Hide file tree
Showing 632 changed files with 4,315 additions and 3,725 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.springframework.context.annotation.Profile;
Expand All @@ -25,8 +24,6 @@
@Repository
public interface ComplaintResponseRepository extends ArtemisJpaRepository<ComplaintResponse, Long> {

Optional<ComplaintResponse> findByComplaint_Id(Long complaintId);

/**
* This magic method counts the number of complaints responses by complaint type associated to a course id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public interface ExampleSubmissionRepository extends ArtemisJpaRepository<Exampl
""")
Optional<ExampleSubmission> findByIdWithResultsAndFeedback(@Param("exampleSubmissionId") long exampleSubmissionId);

Optional<ExampleSubmission> findBySubmissionId(long submissionId);

@EntityGraph(type = LOAD, attributePaths = { "submission", "submission.results" })
Optional<ExampleSubmission> findWithResultsBySubmissionId(long submissionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@ default Optional<Result> findFirstWithSubmissionAndFeedbacksAndTestCasesByPartic
@EntityGraph(type = LOAD, attributePaths = "submission")
Optional<Result> findResultWithSubmissionsById(long resultId);

/**
* Finds the first result by participation ID, including its submissions, ordered by completion date in descending order.
* This method avoids in-memory paging by retrieving the first result directly from the database.
*
* @param participationId the ID of the participation to find the result for
* @return an {@code Optional} containing the first {@code Result} with submissions, ordered by completion date in descending order,
* or an empty {@code Optional} if no result is found
*/
default Optional<Result> findFirstWithSubmissionsByParticipationIdOrderByCompletionDateDesc(long participationId) {
var resultOptional = findFirstByParticipationIdOrderByCompletionDateDesc(participationId);
if (resultOptional.isEmpty()) {
return Optional.empty();
}
var id = resultOptional.get().getId();
return findResultWithSubmissionsById(id);
}

Optional<Result> findFirstByParticipationIdAndRatedOrderByCompletionDateDesc(long participationId, boolean rated);

/**
Expand All @@ -184,11 +167,6 @@ default Optional<Result> findFirstByParticipationIdAndRatedWithSubmissionOrderBy
return findResultWithSubmissionsById(id);
}

Optional<Result> findDistinctBySubmissionId(long submissionId);

@EntityGraph(type = LOAD, attributePaths = "feedbacks")
Optional<Result> findDistinctWithFeedbackBySubmissionId(long submissionId);

@Query("""
SELECT r
FROM Result r
Expand All @@ -208,8 +186,6 @@ default Optional<Result> findFirstByParticipationIdAndRatedWithSubmissionOrderBy
""")
Optional<Result> findByIdWithEagerFeedbacksAndAssessor(@Param("resultId") long resultId);

Set<Result> findAllByParticipationExerciseId(long exerciseId);

/**
* Load a result from the database by its id together with the associated submission, the list of feedback items, its assessor and assessment note.
*
Expand Down Expand Up @@ -352,9 +328,6 @@ SELECT COUNT(r.id)
""")
List<Long> countNumberOfFinishedAssessmentsByExamIdIgnoreTestRuns(@Param("examId") long examId);

@EntityGraph(type = LOAD, attributePaths = { "feedbacks" })
Set<Result> findAllWithEagerFeedbackByAssessorIsNotNullAndParticipation_ExerciseIdAndCompletionDateIsNotNull(long exerciseId);

@Query("""
SELECT COUNT(DISTINCT p)
FROM Participation p
Expand Down Expand Up @@ -802,10 +775,6 @@ default Optional<Result> findLatestResultWithFeedbacksForParticipation(long part
}
}

default Result findFirstWithFeedbacksByParticipationIdOrderByCompletionDateDescElseThrow(long participationId) {
return getValueElseThrow(findFirstWithFeedbacksTestCasesByParticipationIdOrderByCompletionDateDesc(participationId));
}

default Result findWithBidirectionalSubmissionAndFeedbackAndAssessorAndAssessmentNoteAndTeamStudentsByIdElseThrow(long resultId) {
return getValueElseThrow(findWithBidirectionalSubmissionAndFeedbackAndAssessorAndAssessmentNoteAndTeamStudentsById(resultId), resultId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.assessment.domain.TutorParticipation;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.exercise.domain.Exercise;
Expand All @@ -24,8 +23,6 @@
@Repository
public interface TutorParticipationRepository extends ArtemisJpaRepository<TutorParticipation, Long> {

List<TutorParticipation> findByAssessedExercise(Exercise assessedExercise);

@EntityGraph(type = LOAD, attributePaths = { "trainedExampleSubmissions", "trainedExampleSubmissions.submission.results" })
TutorParticipation findWithEagerExampleSubmissionAndResultsByAssessedExerciseAndTutor(Exercise assessedExercise, User tutor);

Expand All @@ -34,8 +31,6 @@ public interface TutorParticipationRepository extends ArtemisJpaRepository<Tutor
@EntityGraph(type = LOAD, attributePaths = { "trainedExampleSubmissions", "trainedExampleSubmissions.submission.results" })
List<TutorParticipation> findAllByAssessedExercise_Course_IdAndTutor_Id(long courseId, long tutorId);

List<TutorParticipation> findAllByAssessedExercise_Course(Course course);

@EntityGraph(type = LOAD, attributePaths = { "trainedExampleSubmissions", "trainedExampleSubmissions.submission.results" })
List<TutorParticipation> findAllByAssessedExercise_ExerciseGroup_Exam_IdAndTutor_Id(long examId, long tutorId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public interface CompetencyProgressRepository extends ArtemisJpaRepository<Compe
""")
Optional<CompetencyProgress> findByCompetencyIdAndUserId(@Param("competencyId") long competencyId, @Param("userId") long userId);

default CompetencyProgress findByCompetencyIdAndUserIdOrElseThrow(long competencyId, long userId) {
return getValueElseThrow(findByCompetencyIdAndUserId(competencyId, userId));
}

@Query("""
SELECT cp
FROM CompetencyProgress cp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ default LearningPath findWithEagerUserByIdElseThrow(long learningPathId) {
@EntityGraph(type = LOAD, attributePaths = { "competencies" })
Optional<LearningPath> findWithEagerCompetenciesByCourseIdAndUserId(long courseId, long userId);

default LearningPath findWithEagerCompetenciesByCourseIdAndUserIdElseThrow(long courseId, long userId) {
return getValueElseThrow(findWithEagerCompetenciesByCourseIdAndUserId(courseId, userId));
}

@EntityGraph(type = LOAD, attributePaths = { "course", "competencies" })
Optional<LearningPath> findWithEagerCourseAndCompetenciesById(long learningPathId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.atlas.domain.science.ScienceEvent;
import de.tum.cit.aet.artemis.atlas.domain.science.ScienceEventType;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

/**
Expand All @@ -22,8 +21,6 @@
@Repository
public interface ScienceEventRepository extends ArtemisJpaRepository<ScienceEvent, Long> {

Set<ScienceEvent> findAllByType(ScienceEventType type);

@Transactional // ok because of modifying query
@Modifying
@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.atlas.web;
package de.tum.cit.aet.artemis.atlas.web.admin;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public interface ConversationParticipantRepository extends ArtemisJpaRepository<

Optional<ConversationParticipant> findConversationParticipantByConversationIdAndUserId(Long conversationId, Long userId);

default ConversationParticipant findConversationParticipantByConversationIdAndUserIdElseThrow(Long conversationId, Long userId) {
return getValueElseThrow(findConversationParticipantByConversationIdAndUserId(conversationId, userId));
}

@Query("""
SELECT DISTINCT conversationParticipant
FROM ConversationParticipant conversationParticipant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ public interface PostRepository extends ArtemisJpaRepository<Post, Long>, JpaSpe

List<Post> findPostsByAuthorId(long authorId);

/**
* find all posts of a user in a course
* currently only used for testing
*
* @param authorId id of the user
* @param courseId id of the course
* @return a list of posts
*/
@Query("""
SELECT p
FROM Post p
WHERE p.author.id =:authorId
AND p.conversation.course.id = :courseId
""")
List<Post> findPostsByAuthorIdAndCourseId(@Param("authorId") long authorId, @Param("courseId") long courseId);

@Transactional // ok because of delete
@Modifying
void deleteAllByConversationId(Long conversationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@
@Repository
public interface ReactionRepository extends ArtemisJpaRepository<Reaction, Long> {

List<Reaction> findReactionsByPostId(Long postId);

List<Reaction> findReactionsByUserId(long userId);

List<Reaction> findReactionsByAnswerPostId(Long answerPostId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public interface ChannelRepository extends ArtemisJpaRepository<Channel, Long> {
""")
List<Channel> findChannelsOfUser(@Param("courseId") Long courseId, @Param("userId") Long userId);

@Query("""
SELECT DISTINCT channel
FROM Channel channel
WHERE channel.course.id = :courseId
AND channel.isCourseWide = TRUE
ORDER BY channel.name
""")
List<Channel> findCourseWideChannelsInCourse(@Param("courseId") long courseId);

@Query("""
SELECT DISTINCT channel
FROM Channel channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public interface ConversationRepository extends ArtemisJpaRepository<Conversatio
@Modifying
void deleteAllByCourseId(long courseId);

// This is used only for testing purposes
List<Conversation> findAllByCourseId(long courseId);

@EntityGraph(type = LOAD, attributePaths = { "conversationParticipants" })
Optional<Conversation> findWithParticipantsById(long conversationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.communication.domain.conversation.OneToOneChat;
import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

@Profile(PROFILE_CORE)
Expand Down Expand Up @@ -73,15 +72,5 @@ AND EXISTS (
// one-to-one chats userA has in that specific course.
Optional<OneToOneChat> findWithParticipantsAndUserGroupsInCourseBetweenUsers(@Param("courseId") Long courseId, @Param("userIdA") Long userIdA, @Param("userIdB") Long userIdB);

@Query("""
SELECT DISTINCT oneToOneChat
FROM OneToOneChat oneToOneChat
LEFT JOIN FETCH oneToOneChat.conversationParticipants p
LEFT JOIN FETCH p.user u
LEFT JOIN FETCH u.groups
WHERE oneToOneChat.id = :oneToOneChatId
""")
Optional<OneToOneChat> findByIdWithConversationParticipantsAndUserGroups(@Param("oneToOneChatId") Long oneToOneChatId) throws EntityNotFoundException;

Integer countByCreatorIdAndCourseId(Long creatorId, Long courseId);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.communication.web;
package de.tum.cit.aet.artemis.communication.web.admin;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties
}
config.getMapConfigs().put("default", initializeDefaultMapConfig(jHipsterProperties));
config.getMapConfigs().put("files", initializeFilesMapConfig(jHipsterProperties));
// TODO Ole: investigate if the following * in artemis.*.domain works for database entity caching or if we need to specify all module domain paths here
config.getMapConfigs().put("de.tum.cit.aet.artemis.*.domain.*", initializeDomainMapConfig(jHipsterProperties));

// Configure split brain protection if the cluster was split at some point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ SELECT COUNT(c) > 0
""")
Optional<Course> findWithEagerLearningPathsAndLearningPathCompetencies(@Param("courseId") long courseId);

@EntityGraph(type = LOAD, attributePaths = { "competencies", "prerequisites", "learningPaths", "learningPaths.competencies" })
Optional<Course> findWithEagerLearningPathsAndCompetenciesAndPrerequisitesById(long courseId);

// Note: we load attachments directly because otherwise, they will be loaded in subsequent DB calls due to the EAGER relationship
@EntityGraph(type = LOAD, attributePaths = { "lectures", "lectures.attachments" })
Optional<Course> findWithEagerLecturesById(long courseId);
Expand Down Expand Up @@ -488,11 +485,6 @@ default Course findWithEagerLearningPathsAndLearningPathCompetenciesByIdElseThro
return getValueElseThrow(findWithEagerLearningPathsAndLearningPathCompetencies(courseId), courseId);
}

@NotNull
default Course findWithEagerLearningPathsAndCompetenciesAndPrerequisitesByIdElseThrow(long courseId) {
return getValueElseThrow(findWithEagerLearningPathsAndCompetenciesAndPrerequisitesById(courseId), courseId);
}

Page<Course> findByTitleIgnoreCaseContaining(String partialTitle, Pageable pageable);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,4 @@ public interface DataExportRepository extends ArtemisJpaRepository<DataExport, L
ORDER BY dataExport.createdDate DESC
""")
List<DataExport> findAllDataExportsByUserIdOrderByRequestDateDesc(@Param("userId") long userId);

@Query("""
SELECT dataExport
FROM DataExport dataExport
WHERE dataExport.dataExportState = 2
""")
Set<DataExport> findAllSuccessfullyCreatedDataExports();
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ public interface UserRepository extends ArtemisJpaRepository<User, Long>, JpaSpe
@EntityGraph(type = LOAD, attributePaths = { "groups", "authorities", "guidedTourSettings", "irisAccepted" })
Optional<User> findOneWithGroupsAndAuthoritiesAndGuidedTourSettingsAndIrisAcceptedTimestampByLogin(String login);

@EntityGraph(type = LOAD, attributePaths = { "learningPaths" })
Optional<User> findOneWithLearningPathsByLogin(String login);

@EntityGraph(type = LOAD, attributePaths = { "learningPaths" })
Optional<User> findWithLearningPathsById(long userId);

Long countByIsDeletedIsFalseAndGroupsContains(String groupName);

@Query("""
Expand Down Expand Up @@ -684,40 +678,6 @@ default Page<User> searchAllWithGroupsByLoginOrNameInCourseAndReturnPage(Pageabl
return new PageImpl<>(users, pageable, total);
}

@Query("""
SELECT user.id
FROM User user
WHERE user.isDeleted = FALSE
""")
List<Long> findUserIdsByIsDeletedIsFalse(Pageable pageable);

@Query("""
SELECT COUNT(user)
FROM User user
WHERE user.isDeleted = FALSE
""")
long countUsersByIsDeletedIsFalse();

/**
* Retrieves a paginated list of {@link User} entities that are not marked as deleted,
* with their associated groups.
*
* @param pageable the pagination information.
* @return a paginated list of {@link User} entities that are not marked as deleted. If no entities are found, returns an empty page.
*/
default Page<User> findAllWithGroupsByIsDeletedIsFalse(Pageable pageable) {
List<Long> ids = findUserIdsByIsDeletedIsFalse(pageable);
if (ids.isEmpty()) {
return Page.empty(pageable);
}
List<User> users = findUsersWithGroupsByIdIn(ids);
long total = countUsersByIsDeletedIsFalse();
return new PageImpl<>(users, pageable, total);
}

@EntityGraph(type = LOAD, attributePaths = { "groups", "authorities" })
Set<User> findAllWithGroupsAndAuthoritiesByIsDeletedIsFalse();

@Modifying
@Transactional // ok because of modifying query
@Query("""
Expand Down Expand Up @@ -1035,17 +995,6 @@ default User findByIdWithGroupsAndAuthoritiesAndOrganizationsElseThrow(long user
return getValueElseThrow(findOneWithGroupsAndAuthoritiesAndOrganizationsById(userId), userId);
}

/**
* Find user with eagerly loaded learning paths by its id
*
* @param userId the id of the user to find
* @return the user with learning paths if it exists, else throw exception
*/
@NotNull
default User findWithLearningPathsByIdElseThrow(long userId) {
return getValueElseThrow(findWithLearningPathsById(userId), userId);
}

/**
* Get students by given course
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.core.web;
package de.tum.cit.aet.artemis.core.web.admin;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;
import static tech.jhipster.web.util.PaginationUtil.generatePaginationHttpHeaders;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.core.web;
package de.tum.cit.aet.artemis.core.web.admin;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.core.web;
package de.tum.cit.aet.artemis.core.web.admin;

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

Expand Down
Loading

0 comments on commit c7ccd42

Please sign in to comment.