diff --git a/docs/dev/guidelines/criteria-builder.rst b/docs/dev/guidelines/criteria-builder.rst index 1e5e7e17cb7b..5a51d9e75b6e 100644 --- a/docs/dev/guidelines/criteria-builder.rst +++ b/docs/dev/guidelines/criteria-builder.rst @@ -32,7 +32,7 @@ In order to use Criteria Builder and benefit from Specifications, we need to adj .. code-block:: java @Repository - public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { + public interface UserRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { } 3. **(Optional) Show queries:** To ease debugging, generated queries can be displayed by enabling the output of executed SQL probes. diff --git a/docs/dev/guidelines/server.rst b/docs/dev/guidelines/server.rst index 07ed30cefd92..9e5a8ce068de 100644 --- a/docs/dev/guidelines/server.rst +++ b/docs/dev/guidelines/server.rst @@ -343,8 +343,8 @@ An example for a simple method is finding a single entity by ID: .. code-block:: java - default StudentExam findByIdElseThrow(Long studentExamId) throws EntityNotFoundException { - return findById(studentExamId).orElseThrow(() -> new EntityNotFoundException("Student Exam", studentExamId)); + default Course findByIdWithLecturesElseThrow(long courseId) { + return getValueElseThrow(findWithEagerLecturesById(courseId), courseId); } diff --git a/src/main/java/de/tum/in/www1/artemis/config/DatabaseConfiguration.java b/src/main/java/de/tum/in/www1/artemis/config/DatabaseConfiguration.java index a32648ad8f52..8e7ddf1266dd 100644 --- a/src/main/java/de/tum/in/www1/artemis/config/DatabaseConfiguration.java +++ b/src/main/java/de/tum/in/www1/artemis/config/DatabaseConfiguration.java @@ -8,9 +8,11 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.transaction.annotation.EnableTransactionManagement; +import de.tum.in.www1.artemis.repository.base.RepositoryImpl; + @Profile(PROFILE_CORE) @Configuration -@EnableJpaRepositories(basePackages = "de.tum.in.www1.artemis.repository") +@EnableJpaRepositories(basePackages = "de.tum.in.www1.artemis.repository", repositoryBaseClass = RepositoryImpl.class) @EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware") @EnableTransactionManagement public class DatabaseConfiguration { diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ApollonDiagramRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ApollonDiagramRepository.java index e41d72f6b4b7..3a25025dbd92 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ApollonDiagramRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ApollonDiagramRepository.java @@ -4,24 +4,21 @@ import java.util.List; -import jakarta.validation.constraints.NotNull; - import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.modeling.ApollonDiagram; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ApollonDiagram entity. */ @Profile(PROFILE_CORE) @Repository -public interface ApollonDiagramRepository extends JpaRepository { +public interface ApollonDiagramRepository extends ArtemisJpaRepository { List findDiagramsByCourseId(Long courseId); @@ -38,9 +35,4 @@ public interface ApollonDiagramRepository extends JpaRepository new EntityNotFoundException("ApollonDiagram", apollonDiagramId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/AttachmentRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/AttachmentRepository.java index 83fd57799fd8..56110b822491 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/AttachmentRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/AttachmentRepository.java @@ -5,12 +5,12 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Attachment; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -18,7 +18,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface AttachmentRepository extends JpaRepository { +public interface AttachmentRepository extends ArtemisJpaRepository { @Query(""" SELECT a diff --git a/src/main/java/de/tum/in/www1/artemis/repository/AttachmentUnitRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/AttachmentUnitRepository.java index 70effc681294..4869b15aad8c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/AttachmentUnitRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/AttachmentUnitRepository.java @@ -7,13 +7,13 @@ import jakarta.validation.constraints.NotNull; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.enumeration.AttachmentType; import de.tum.in.www1.artemis.domain.lecture.AttachmentUnit; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -21,7 +21,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface AttachmentUnitRepository extends JpaRepository { +public interface AttachmentUnitRepository extends ArtemisJpaRepository { @Query(""" SELECT lectureUnit @@ -61,10 +61,4 @@ default List findAllByLectureIdAndAttachmentTypeElseThrow(Long l WHERE attachmentUnit.id = :attachmentUnitId """) AttachmentUnit findOneWithSlides(@Param("attachmentUnitId") long attachmentUnitId); - - @NotNull - default AttachmentUnit findByIdElseThrow(Long attachmentUnitId) throws EntityNotFoundException { - return findById(attachmentUnitId).orElseThrow(() -> new EntityNotFoundException("AttachmentUnit", attachmentUnitId)); - } - } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/AuthorityRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/AuthorityRepository.java index 16b3b75c1fe2..a1e1e8e9477f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/AuthorityRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/AuthorityRepository.java @@ -2,14 +2,13 @@ import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; - import de.tum.in.www1.artemis.domain.Authority; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Authority entity. */ -public interface AuthorityRepository extends JpaRepository { +public interface AuthorityRepository extends ArtemisJpaRepository { /** * @return an unmodifiable list of all the authorities diff --git a/src/main/java/de/tum/in/www1/artemis/repository/AuxiliaryRepositoryRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/AuxiliaryRepositoryRepository.java index 06abb2e6ebbd..cd3a3836a12e 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/AuxiliaryRepositoryRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/AuxiliaryRepositoryRepository.java @@ -5,17 +5,17 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.AuxiliaryRepository; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the AuxiliaryRepository entity. */ @Profile(PROFILE_CORE) @Repository -public interface AuxiliaryRepositoryRepository extends JpaRepository { +public interface AuxiliaryRepositoryRepository extends ArtemisJpaRepository { List findByExerciseId(Long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/BonusRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/BonusRepository.java index e1ac308f28bb..a2636ab20c06 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/BonusRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/BonusRepository.java @@ -5,24 +5,19 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Bonus; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Bonus entity */ @Profile(PROFILE_CORE) @Repository -public interface BonusRepository extends JpaRepository { - - default Bonus findByIdElseThrow(long bonusId) throws EntityNotFoundException { - return findById(bonusId).orElseThrow(() -> new EntityNotFoundException("Bonus", bonusId)); - } +public interface BonusRepository extends ArtemisJpaRepository { @Query(""" SELECT gs.bonusFrom diff --git a/src/main/java/de/tum/in/www1/artemis/repository/BuildJobRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/BuildJobRepository.java index 7db400379b78..52bbbe0b90da 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/BuildJobRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/BuildJobRepository.java @@ -12,7 +12,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -21,12 +20,13 @@ import de.tum.in.www1.artemis.domain.BuildJob; import de.tum.in.www1.artemis.domain.Result; import de.tum.in.www1.artemis.domain.enumeration.BuildStatus; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.service.connectors.localci.dto.DockerImageBuild; import de.tum.in.www1.artemis.service.connectors.localci.dto.ResultBuildJob; @Profile(PROFILE_CORE) @Repository -public interface BuildJobRepository extends JpaRepository, JpaSpecificationExecutor { +public interface BuildJobRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { Optional findFirstByParticipationIdOrderByBuildStartDateDesc(Long participationId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/BuildLogEntryRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/BuildLogEntryRepository.java index e3e2a264d44a..0d6be87736a0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/BuildLogEntryRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/BuildLogEntryRepository.java @@ -3,19 +3,19 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.BuildLogEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the BuildLogEntry entity. */ @Profile(PROFILE_CORE) @Repository -public interface BuildLogEntryRepository extends JpaRepository { +public interface BuildLogEntryRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying diff --git a/src/main/java/de/tum/in/www1/artemis/repository/BuildLogStatisticsEntryRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/BuildLogStatisticsEntryRepository.java index f19394bacefa..b9311bab166d 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/BuildLogStatisticsEntryRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/BuildLogStatisticsEntryRepository.java @@ -4,7 +4,6 @@ import static de.tum.in.www1.artemis.domain.statistics.BuildLogStatisticsEntry.BuildJobPartDuration; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,6 +13,7 @@ import de.tum.in.www1.artemis.domain.ProgrammingExercise; import de.tum.in.www1.artemis.domain.ProgrammingSubmission; import de.tum.in.www1.artemis.domain.statistics.BuildLogStatisticsEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.BuildLogStatisticsDTO; /** @@ -21,7 +21,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface BuildLogStatisticsEntryRepository extends JpaRepository { +public interface BuildLogStatisticsEntryRepository extends ArtemisJpaRepository { @Query(""" SELECT new de.tum.in.www1.artemis.web.rest.dto.BuildLogStatisticsDTO( diff --git a/src/main/java/de/tum/in/www1/artemis/repository/BuildPlanRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/BuildPlanRepository.java index d93acbded006..da544f29b80b 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/BuildPlanRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/BuildPlanRepository.java @@ -5,15 +5,15 @@ import java.util.Optional; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.BuildPlan; import de.tum.in.www1.artemis.domain.ProgrammingExercise; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; -public interface BuildPlanRepository extends JpaRepository { +public interface BuildPlanRepository extends ArtemisJpaRepository { @Query(""" SELECT buildPlan diff --git a/src/main/java/de/tum/in/www1/artemis/repository/CompetencyProgressRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/CompetencyProgressRepository.java index f7ce1651927c..f86876bf8b97 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/CompetencyProgressRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/CompetencyProgressRepository.java @@ -8,7 +8,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -17,11 +16,12 @@ import de.tum.in.www1.artemis.domain.competency.Competency; import de.tum.in.www1.artemis.domain.competency.CompetencyProgress; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface CompetencyProgressRepository extends JpaRepository { +public interface CompetencyProgressRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying diff --git a/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRelationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRelationRepository.java index 794e7ef2520f..fca433daa2bb 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRelationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRelationRepository.java @@ -5,7 +5,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,13 +13,14 @@ import de.tum.in.www1.artemis.domain.competency.CompetencyRelation; import de.tum.in.www1.artemis.domain.competency.RelationType; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Competency Relation entity. */ @Profile(PROFILE_CORE) @Repository -public interface CompetencyRelationRepository extends JpaRepository { +public interface CompetencyRelationRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying diff --git a/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRepository.java index 1f778f8abac8..20f6ba12c968 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/CompetencyRepository.java @@ -10,7 +10,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -18,6 +17,7 @@ import de.tum.in.www1.artemis.domain.Course; import de.tum.in.www1.artemis.domain.competency.Competency; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -25,7 +25,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface CompetencyRepository extends JpaRepository, JpaSpecificationExecutor { +public interface CompetencyRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { @Query(""" SELECT c @@ -199,10 +199,6 @@ default Competency findByIdWithConsecutiveCoursesElseThrow(long competencyId) { return findByIdWithConsecutiveCourses(competencyId).orElseThrow(() -> new EntityNotFoundException("Competency", competencyId)); } - default Competency findByIdElseThrow(long competencyId) { - return findById(competencyId).orElseThrow(() -> new EntityNotFoundException("Competency", competencyId)); - } - default Competency findWithLectureUnitsAndExercisesByIdElseThrow(long competencyId) { return findWithLectureUnitsAndExercisesById(competencyId).orElseThrow(() -> new EntityNotFoundException("Competency", competencyId)); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ComplaintRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ComplaintRepository.java index 1cd745e83b88..50eb024e1591 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ComplaintRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ComplaintRepository.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -23,14 +22,14 @@ import de.tum.in.www1.artemis.domain.leaderboard.tutor.TutorLeaderboardComplaintResponses; import de.tum.in.www1.artemis.domain.leaderboard.tutor.TutorLeaderboardComplaints; import de.tum.in.www1.artemis.domain.leaderboard.tutor.TutorLeaderboardMoreFeedbackRequests; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Complaint entity. */ @Profile(PROFILE_CORE) @Repository -public interface ComplaintRepository extends JpaRepository { +public interface ComplaintRepository extends ArtemisJpaRepository { @Query(""" SELECT c @@ -522,7 +521,7 @@ SELECT COUNT(c) """) List findTutorLeaderboardAnsweredMoreFeedbackRequestsByExerciseId(@Param("exerciseId") long exerciseId); - default Complaint findByIdElseThrow(Long complaintId) { - return findByIdWithEagerAssessor(complaintId).orElseThrow(() -> new EntityNotFoundException("Complaint", complaintId)); + default Complaint findWithEagerAssessorByIdElseThrow(Long complaintId) { + return getValueElseThrow(findByIdWithEagerAssessor(complaintId), complaintId); } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ComplaintResponseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ComplaintResponseRepository.java index 77f52eda18c1..484274fcd5a1 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ComplaintResponseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ComplaintResponseRepository.java @@ -7,7 +7,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -17,14 +16,14 @@ import de.tum.in.www1.artemis.domain.ComplaintResponse; import de.tum.in.www1.artemis.domain.assessment.dashboard.ExerciseMapEntry; import de.tum.in.www1.artemis.domain.enumeration.ComplaintType; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ComplaintResponse entity. */ @Profile(PROFILE_CORE) @Repository -public interface ComplaintResponseRepository extends JpaRepository { +public interface ComplaintResponseRepository extends ArtemisJpaRepository { Optional findByComplaint_Id(Long complaintId); @@ -112,8 +111,4 @@ List countComplaintsByExerciseIdsAndComplaintComplaintTypeIgno @Transactional // ok because of delete @Modifying void deleteByComplaint_Result_Id(long resultId); - - default ComplaintResponse findByIdElseThrow(Long complaintResponseId) { - return findById(complaintResponseId).orElseThrow(() -> new EntityNotFoundException("ComplaintResponse", complaintResponseId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ConductAgreementRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ConductAgreementRepository.java index d3eb9f5e7a61..22462b219347 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ConductAgreementRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ConductAgreementRepository.java @@ -5,20 +5,20 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.ConductAgreement; import de.tum.in.www1.artemis.domain.ConductAgreementId; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the Code of Conduct Agreement entity. */ @Profile(PROFILE_CORE) @Repository -public interface ConductAgreementRepository extends JpaRepository { +public interface ConductAgreementRepository extends ArtemisJpaRepository { /** * Find the user's agreement to a course's code of conduct. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/CourseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/CourseRepository.java index 9e173ad9cd67..a662d908e75a 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/CourseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/CourseRepository.java @@ -17,7 +17,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -32,6 +31,7 @@ import de.tum.in.www1.artemis.domain.enumeration.CourseInformationSharingConfiguration; import de.tum.in.www1.artemis.domain.modeling.ModelingExercise; import de.tum.in.www1.artemis.domain.statistics.StatisticsEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -39,7 +39,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface CourseRepository extends JpaRepository { +public interface CourseRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT course.instructorGroupName @@ -355,11 +355,6 @@ SELECT COUNT(DISTINCT ug.userId) """) Page findByTitleInCoursesWhereInstructorOrEditor(@Param("partialTitle") String partialTitle, @Param("groups") Set groups, Pageable pageable); - @NotNull - default Course findByIdElseThrow(long courseId) throws EntityNotFoundException { - return findById(courseId).orElseThrow(() -> new EntityNotFoundException("Course", courseId)); - } - default Course findByIdWithEagerExercisesElseThrow(long courseId) throws EntityNotFoundException { return Optional.ofNullable(findWithEagerExercisesById(courseId)).orElseThrow(() -> new EntityNotFoundException("Course", courseId)); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/DataExportRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/DataExportRepository.java index 99c71cf9c9f6..bfab5c59a8fc 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/DataExportRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/DataExportRepository.java @@ -7,31 +7,19 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.DataExport; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for a data export entity. */ @Profile(PROFILE_CORE) @Repository -public interface DataExportRepository extends JpaRepository { - - /** - * Find a data export by its ID and throw an {@link EntityNotFoundException} if it could not be found. - * - * @param dataExportId the id of the data export to find - * @return the data export for the given id - * @throws EntityNotFoundException if the data export could not be found - */ - default DataExport findByIdElseThrow(long dataExportId) { - return findById(dataExportId).orElseThrow(() -> new EntityNotFoundException("Could not find data export with id: " + dataExportId)); - } +public interface DataExportRepository extends ArtemisJpaRepository { /** * Find all data exports that need to be created. This includes all data exports that are currently in the state IN_CREATION (the export was not completed then) or diff --git a/src/main/java/de/tum/in/www1/artemis/repository/DragAndDropMappingRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/DragAndDropMappingRepository.java index 148817fcaf27..1aa940303ce6 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/DragAndDropMappingRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/DragAndDropMappingRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.DragAndDropMapping; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the DragAndDropMapping entity. */ @Profile(PROFILE_CORE) @Repository -public interface DragAndDropMappingRepository extends JpaRepository { +public interface DragAndDropMappingRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/DragItemRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/DragItemRepository.java index 408fe2a4666c..b6f1986f3473 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/DragItemRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/DragItemRepository.java @@ -6,10 +6,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.DragItem; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -17,12 +17,12 @@ */ @Profile(PROFILE_CORE) @Repository -public interface DragItemRepository extends JpaRepository { +public interface DragItemRepository extends ArtemisJpaRepository { @EntityGraph(type = EntityGraph.EntityGraphType.LOAD, attributePaths = "question") Optional findWithEagerQuestionById(Long id); - default DragItem findByIdElseThrow(Long dragItemId) { + default DragItem findWithEagerQuestionByIdElseThrow(Long dragItemId) { return findWithEagerQuestionById(dragItemId).orElseThrow(() -> new EntityNotFoundException("DragItem", dragItemId)); } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExamLiveEventRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExamLiveEventRepository.java index e3d8d864069a..87fa90d5c67c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExamLiveEventRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExamLiveEventRepository.java @@ -5,20 +5,20 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; 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.in.www1.artemis.domain.exam.event.ExamLiveEvent; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ExamLiveEvent entity. */ @Profile(PROFILE_CORE) @Repository -public interface ExamLiveEventRepository extends JpaRepository { +public interface ExamLiveEventRepository extends ArtemisJpaRepository { /** * Find all events for the given student exam plus all global events for the exam in reverse creation order. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExamRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExamRepository.java index 7c05bc7c8f4e..1cd446b7cb78 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExamRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExamRepository.java @@ -19,7 +19,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -27,6 +26,7 @@ import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.exam.Exam; import de.tum.in.www1.artemis.domain.exam.ExerciseGroup; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.CourseContentCount; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -35,7 +35,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ExamRepository extends JpaRepository { +public interface ExamRepository extends ArtemisJpaRepository { List findByCourseId(long courseId); @@ -399,11 +399,6 @@ SELECT COUNT(studentExam) @Cacheable(cacheNames = "examTitle", key = "#examId", unless = "#result == null") String getExamTitle(@Param("examId") long examId); - @NotNull - default Exam findByIdElseThrow(long examId) throws EntityNotFoundException { - return findById(examId).orElseThrow(() -> new EntityNotFoundException("Exam", examId)); - } - /** * Get one exam by id with exercise groups. * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExamSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExamSessionRepository.java index 40ac95aab4b3..b86b9ea3abc3 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExamSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExamSessionRepository.java @@ -5,19 +5,19 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.exam.ExamSession; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ExamSession entity. */ @Profile(PROFILE_CORE) @Repository -public interface ExamSessionRepository extends JpaRepository { +public interface ExamSessionRepository extends ArtemisJpaRepository { @Query(""" SELECT COUNT(es.id) diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExamUserRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExamUserRepository.java index 72cf0f7704f7..a84d91539709 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExamUserRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExamUserRepository.java @@ -9,17 +9,17 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.exam.ExamUser; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.ExamUserAttendanceCheckDTO; @Profile(PROFILE_CORE) @Repository -public interface ExamUserRepository extends JpaRepository { +public interface ExamUserRepository extends ArtemisJpaRepository { @Query(""" SELECT eu diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExampleSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExampleSubmissionRepository.java index 7579503e28a6..1607d19937b4 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExampleSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExampleSubmissionRepository.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -17,6 +16,7 @@ import de.tum.in.www1.artemis.domain.ExampleSubmission; import de.tum.in.www1.artemis.domain.Feedback; import de.tum.in.www1.artemis.domain.Result; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -24,7 +24,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ExampleSubmissionRepository extends JpaRepository { +public interface ExampleSubmissionRepository extends ArtemisJpaRepository { Long countAllByExerciseId(long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExerciseGroupRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExerciseGroupRepository.java index ff23c1aa89f9..6ba090f904fa 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExerciseGroupRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExerciseGroupRepository.java @@ -10,12 +10,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.exam.ExerciseGroup; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -23,7 +23,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ExerciseGroupRepository extends JpaRepository { +public interface ExerciseGroupRepository extends ArtemisJpaRepository { @EntityGraph(type = LOAD, attributePaths = { "exercises" }) Optional findWithExercisesById(Long exerciseGroupId); @@ -40,18 +40,6 @@ ORDER BY INDEX(eg) // INDEX() is used to retrieve the order saved by @OrderColumn, see https://en.wikibooks.org/wiki/Java_Persistence/JPQL#Special_Operators List findWithExamAndExercisesByExamId(@Param("examId") Long examId); - /** - * Get one exerciseGroup by id with the corresponding exam. - * - * @param exerciseGroupId the id of the entity - * @return the entity - */ - @NotNull - default ExerciseGroup findByIdElseThrow(long exerciseGroupId) { - // Note: exam is loaded eagerly anyway - return findById(exerciseGroupId).orElseThrow(() -> new EntityNotFoundException("ExerciseGroup", exerciseGroupId)); - } - /** * Get one exerciseGroup by id with all exercises. * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExerciseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExerciseRepository.java index 5200c1285a47..9481d09119bc 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExerciseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExerciseRepository.java @@ -15,7 +15,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -24,6 +23,7 @@ import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.metrics.ExerciseTypeMetricsEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -31,7 +31,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ExerciseRepository extends JpaRepository { +public interface ExerciseRepository extends ArtemisJpaRepository { @Query(""" SELECT e @@ -481,11 +481,6 @@ SELECT COUNT(DISTINCT p.team.id) """) Long getTeamParticipationCountById(@Param("exerciseId") Long exerciseId); - @NotNull - default Exercise findByIdElseThrow(Long exerciseId) throws EntityNotFoundException { - return findById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Exercise", exerciseId)); - } - @NotNull default Exercise findWithCompetenciesByIdElseThrow(long exerciseId) throws EntityNotFoundException { return findWithCompetenciesById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Exercise", exerciseId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ExerciseUnitRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ExerciseUnitRepository.java index 38f422a075f4..c18fd99d0021 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ExerciseUnitRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ExerciseUnitRepository.java @@ -5,19 +5,19 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.ExerciseUnit; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Exercise Unit entity. */ @Profile(PROFILE_CORE) @Repository -public interface ExerciseUnitRepository extends JpaRepository { +public interface ExerciseUnitRepository extends ArtemisJpaRepository { @Query(""" SELECT eu diff --git a/src/main/java/de/tum/in/www1/artemis/repository/FeedbackRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/FeedbackRepository.java index 577bc1cbde5c..34ec357f4b57 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/FeedbackRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/FeedbackRepository.java @@ -8,7 +8,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -18,13 +17,14 @@ import de.tum.in.www1.artemis.domain.GradingCriterion; import de.tum.in.www1.artemis.domain.GradingInstruction; import de.tum.in.www1.artemis.domain.Result; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Feedback entity. */ @Profile(PROFILE_CORE) @Repository -public interface FeedbackRepository extends JpaRepository { +public interface FeedbackRepository extends ArtemisJpaRepository { List findByResult(Result result); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/FileUploadExerciseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/FileUploadExerciseRepository.java index 3497a1ed2339..bc9c5a5814b1 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/FileUploadExerciseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/FileUploadExerciseRepository.java @@ -6,25 +6,22 @@ import java.util.List; import java.util.Optional; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.FileUploadExercise; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the FileUploadExercise entity. */ @Profile(PROFILE_CORE) @Repository -public interface FileUploadExerciseRepository extends JpaRepository, JpaSpecificationExecutor { +public interface FileUploadExerciseRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { @Query(""" SELECT DISTINCT e FROM FileUploadExercise e @@ -35,15 +32,4 @@ public interface FileUploadExerciseRepository extends JpaRepository findWithEagerTeamAssignmentConfigAndCategoriesAndCompetenciesById(Long exerciseId); - - /** - * Get one file upload exercise by id. - * - * @param exerciseId the id of the entity - * @return the entity - */ - @NotNull - default FileUploadExercise findByIdElseThrow(Long exerciseId) { - return findById(exerciseId).orElseThrow(() -> new EntityNotFoundException("File Upload Exercise", exerciseId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/FileUploadSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/FileUploadSubmissionRepository.java index e5518b8f77dc..598edc56dcfc 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/FileUploadSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/FileUploadSubmissionRepository.java @@ -9,12 +9,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.FileUploadSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -22,7 +22,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface FileUploadSubmissionRepository extends JpaRepository { +public interface FileUploadSubmissionRepository extends ArtemisJpaRepository { /** * @param submissionId the submission id we are interested in @@ -86,17 +86,6 @@ default FileUploadSubmission findByIdWithEagerResultAndFeedbackAndAssessorAndAss .orElseThrow(() -> new EntityNotFoundException("File Upload Submission", submissionId)); } - /** - * Get the file upload submission with the given id from the database. Throws an EntityNotFoundException if no submission could be found for the given id. - * - * @param submissionId the id of the submission that should be loaded from the database - * @return the file upload submission with the given id - */ - @NotNull - default FileUploadSubmission findByIdElseThrow(long submissionId) { - return findById(submissionId).orElseThrow(() -> new EntityNotFoundException("File Upload Submission", submissionId)); - } - /** * Get the file upload submission with the given id from the database. The submission is loaded together with its participation and the team of the participation. Throws an * EntityNotFoundException if no submission could be found for the given id. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/GradeStepRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/GradeStepRepository.java index 7109129ed239..6e43a3b8c7b6 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/GradeStepRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/GradeStepRepository.java @@ -3,20 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.GradeStep; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA Repository for the GradeStep entity */ @Profile(PROFILE_CORE) @Repository -public interface GradeStepRepository extends JpaRepository { +public interface GradeStepRepository extends ArtemisJpaRepository { - default GradeStep findByIdElseThrow(long gradeStepId) { - return findById(gradeStepId).orElseThrow(() -> new EntityNotFoundException("GradeStep", gradeStepId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/GradingCriterionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/GradingCriterionRepository.java index fbf1c6b65910..a8876d64fb36 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/GradingCriterionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/GradingCriterionRepository.java @@ -5,19 +5,19 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.GradingCriterion; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the GradingCriteria entity. */ @Profile(PROFILE_CORE) @Repository -public interface GradingCriterionRepository extends JpaRepository { +public interface GradingCriterionRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT criterion diff --git a/src/main/java/de/tum/in/www1/artemis/repository/GradingInstructionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/GradingInstructionRepository.java index 6d375eb70821..41b1393a4712 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/GradingInstructionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/GradingInstructionRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.GradingInstruction; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the GradingInstruction entity. */ @Profile(PROFILE_CORE) @Repository -public interface GradingInstructionRepository extends JpaRepository { +public interface GradingInstructionRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/GradingScaleRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/GradingScaleRepository.java index 81d77602c2ce..44acc706fcf8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/GradingScaleRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/GradingScaleRepository.java @@ -15,13 +15,13 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.GradeStep; import de.tum.in.www1.artemis.domain.GradingScale; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -30,7 +30,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface GradingScaleRepository extends JpaRepository { +public interface GradingScaleRepository extends ArtemisJpaRepository { /** * Find a grading scale for course by id diff --git a/src/main/java/de/tum/in/www1/artemis/repository/GroupNotificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/GroupNotificationRepository.java index e895289d8a91..8abebc5ea5d0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/GroupNotificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/GroupNotificationRepository.java @@ -5,17 +5,17 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.notification.GroupNotification; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the Notification entity. */ @Profile(PROFILE_CORE) @Repository -public interface GroupNotificationRepository extends JpaRepository { +public interface GroupNotificationRepository extends ArtemisJpaRepository { List findAllByCourseId(Long courseId); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/GuidedTourSettingsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/GuidedTourSettingsRepository.java index 4bf93cde940e..deb7d7a90e7a 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/GuidedTourSettingsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/GuidedTourSettingsRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.GuidedTourSetting; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the GuidedTourSetting entity. */ @Profile(PROFILE_CORE) @Repository -public interface GuidedTourSettingsRepository extends JpaRepository { +public interface GuidedTourSettingsRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/LearningPathRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/LearningPathRepository.java index 32f7f97479a6..ba5d0865feb6 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/LearningPathRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/LearningPathRepository.java @@ -9,17 +9,17 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.competency.LearningPath; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface LearningPathRepository extends JpaRepository { +public interface LearningPathRepository extends ArtemisJpaRepository { Optional findByCourseIdAndUserId(long courseId, long userId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/LectureRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/LectureRepository.java index 3fbb00520a51..ee8927eb7ae9 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/LectureRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/LectureRepository.java @@ -12,12 +12,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Lecture; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.CourseContentCount; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -26,7 +26,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface LectureRepository extends JpaRepository { +public interface LectureRepository extends ArtemisJpaRepository { @Query(""" SELECT lecture @@ -137,11 +137,6 @@ Page findByTitleInLectureOrCourseAndUserHasAccessToCourse(@Param("parti @Cacheable(cacheNames = "lectureTitle", key = "#lectureId", unless = "#result == null") String getLectureTitle(@Param("lectureId") Long lectureId); - @NotNull - default Lecture findByIdElseThrow(long lectureId) { - return findById(lectureId).orElseThrow(() -> new EntityNotFoundException("Lecture", lectureId)); - } - @NotNull default Lecture findByIdWithLectureUnitsAndCompetenciesElseThrow(Long lectureId) { return findByIdWithLectureUnitsAndCompetencies(lectureId).orElseThrow(() -> new EntityNotFoundException("Lecture", lectureId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitCompletionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitCompletionRepository.java index b3dc9255579a..ec2650fe051a 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitCompletionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitCompletionRepository.java @@ -7,17 +7,17 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.LectureUnit; import de.tum.in.www1.artemis.domain.lecture.LectureUnitCompletion; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface LectureUnitCompletionRepository extends JpaRepository { +public interface LectureUnitCompletionRepository extends ArtemisJpaRepository { @Query(""" SELECT lectureUnitCompletion diff --git a/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitRepository.java index cf67c34f797a..c909b0017ded 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/LectureUnitRepository.java @@ -6,12 +6,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.LectureUnit; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -19,7 +19,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface LectureUnitRepository extends JpaRepository { +public interface LectureUnitRepository extends ArtemisJpaRepository { @Query(""" SELECT lu diff --git a/src/main/java/de/tum/in/www1/artemis/repository/LongFeedbackTextRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/LongFeedbackTextRepository.java index 25079d9a1451..e48f7fdfaa47 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/LongFeedbackTextRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/LongFeedbackTextRepository.java @@ -3,14 +3,14 @@ import java.util.List; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.LongFeedbackText; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; -public interface LongFeedbackTextRepository extends JpaRepository { +public interface LongFeedbackTextRepository extends ArtemisJpaRepository { @Query(""" SELECT longFeedback diff --git a/src/main/java/de/tum/in/www1/artemis/repository/Lti13ResourceLaunchRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/Lti13ResourceLaunchRepository.java index c065368b097b..184bf01fdb4e 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/Lti13ResourceLaunchRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/Lti13ResourceLaunchRepository.java @@ -5,13 +5,12 @@ import jakarta.validation.constraints.NotNull; -import org.springframework.data.jpa.repository.JpaRepository; - import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.lti.LtiResourceLaunch; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; -public interface Lti13ResourceLaunchRepository extends JpaRepository { +public interface Lti13ResourceLaunchRepository extends ArtemisJpaRepository { Optional findByIssAndSubAndDeploymentIdAndResourceLinkId(@NotNull String iss, @NotNull String sub, @NotNull String deploymentId, @NotNull String resourceLinkId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/LtiPlatformConfigurationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/LtiPlatformConfigurationRepository.java index 2f2d28a0e18a..21d3bcba217e 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/LtiPlatformConfigurationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/LtiPlatformConfigurationRepository.java @@ -9,10 +9,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.LtiPlatformConfiguration; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -20,7 +20,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface LtiPlatformConfigurationRepository extends JpaRepository { +public interface LtiPlatformConfigurationRepository extends ArtemisJpaRepository { /** * Finds an LTI platform configuration by its registration ID. @@ -30,18 +30,6 @@ public interface LtiPlatformConfigurationRepository extends JpaRepository findByRegistrationId(String registrationId); - /** - * Finds an LTI platform configuration by ID or throws EntityNotFoundException if not found. - * - * @param platformId The ID of the configuration. - * @return LtiPlatformConfiguration if found. - * @throws EntityNotFoundException if not found. - */ - @NotNull - default LtiPlatformConfiguration findByIdElseThrow(Long platformId) throws EntityNotFoundException { - return findById(platformId).orElseThrow(() -> new EntityNotFoundException("LtiPlatformConfiguration", platformId)); - } - /** * Fetches an {@link LtiPlatformConfiguration} with its associated online courses eagerly loaded. * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/MigrationChangeRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/MigrationChangeRepository.java index e8bc27341e49..84125b806ebb 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/MigrationChangeRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/MigrationChangeRepository.java @@ -1,8 +1,7 @@ package de.tum.in.www1.artemis.repository; -import org.springframework.data.jpa.repository.JpaRepository; - import de.tum.in.www1.artemis.domain.MigrationChangelog; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; -public interface MigrationChangeRepository extends JpaRepository { +public interface MigrationChangeRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ModelClusterRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ModelClusterRepository.java index b0bad4100bec..dd4924abd278 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ModelClusterRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ModelClusterRepository.java @@ -5,19 +5,19 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.modeling.ModelCluster; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ModelCluster entity. */ @Profile(PROFILE_CORE) @Repository -public interface ModelClusterRepository extends JpaRepository { +public interface ModelClusterRepository extends ArtemisJpaRepository { @Query(""" SELECT COUNT (DISTINCT cluster) diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ModelElementRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ModelElementRepository.java index 636cc275ed47..94a11fde7e15 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ModelElementRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ModelElementRepository.java @@ -5,19 +5,19 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.modeling.ModelElement; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ModelElement entity. */ @Profile(PROFILE_CORE) @Repository -public interface ModelElementRepository extends JpaRepository { +public interface ModelElementRepository extends ArtemisJpaRepository { List findByModelElementIdIn(List elementIds); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ModelingExerciseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ModelingExerciseRepository.java index c0de473d6c30..d867cd2536a2 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ModelingExerciseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ModelingExerciseRepository.java @@ -11,13 +11,13 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.modeling.ModelingExercise; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -25,7 +25,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ModelingExerciseRepository extends JpaRepository, JpaSpecificationExecutor { +public interface ModelingExerciseRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { @Query(""" SELECT DISTINCT e @@ -92,11 +92,6 @@ public interface ModelingExerciseRepository extends JpaRepository findWithStudentParticipationsSubmissionsResultsById(Long exerciseId); - @NotNull - default ModelingExercise findByIdElseThrow(long exerciseId) { - return findById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Modeling Exercise", exerciseId)); - } - @NotNull default ModelingExercise findWithEagerExampleSubmissionsAndCompetenciesByIdElseThrow(long exerciseId) { return findWithEagerExampleSubmissionsAndCompetenciesById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Modeling Exercise", exerciseId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ModelingSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ModelingSubmissionRepository.java index a5e6690bfd52..e713e9feb200 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ModelingSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ModelingSubmissionRepository.java @@ -8,12 +8,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.modeling.ModelingSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -21,7 +21,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ModelingSubmissionRepository extends JpaRepository { +public interface ModelingSubmissionRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT submission @@ -65,16 +65,6 @@ public interface ModelingSubmissionRepository extends JpaRepository findSubmittedByExerciseIdWithEagerResultsAndFeedback(@Param("exerciseId") Long exerciseId); - /** - * Get the modeling submission with the given id from the database. Throws an EntityNotFoundException if no submission could be found for the given id. - * - * @param submissionId the id of the submission that should be loaded from the database - * @return the modeling submission with the given id - */ - default ModelingSubmission findByIdElseThrow(Long submissionId) { - return findById(submissionId).orElseThrow(() -> new EntityNotFoundException("Modeling Submission", submissionId)); - } - /** * Get the modeling submission with the given id from the database. The submission is loaded together with its result, the feedback of the result and the assessor of the * result. Throws an EntityNotFoundException if no submission could be found for the given id. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/NotificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/NotificationRepository.java index ca9e54992efd..134b24cac7af 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/NotificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/NotificationRepository.java @@ -10,19 +10,19 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.notification.Notification; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the Notification entity. */ @Profile(PROFILE_CORE) @Repository -public interface NotificationRepository extends JpaRepository { +public interface NotificationRepository extends ArtemisJpaRepository { @Query(""" SELECT notification diff --git a/src/main/java/de/tum/in/www1/artemis/repository/NotificationSettingRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/NotificationSettingRepository.java index d2e7c523b3d1..261877b584a9 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/NotificationSettingRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/NotificationSettingRepository.java @@ -7,20 +7,20 @@ import java.util.stream.Collectors; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.NotificationSetting; import de.tum.in.www1.artemis.domain.User; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the NotificationSetting entity. */ @Profile(PROFILE_CORE) @Repository -public interface NotificationSettingRepository extends JpaRepository { +public interface NotificationSettingRepository extends ArtemisJpaRepository { @Query(""" SELECT notificationSetting diff --git a/src/main/java/de/tum/in/www1/artemis/repository/OnlineCourseConfigurationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/OnlineCourseConfigurationRepository.java index 581d7c114aeb..0e42428f1009 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/OnlineCourseConfigurationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/OnlineCourseConfigurationRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.OnlineCourseConfiguration; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the OnlineCourseConfiguration entity. */ @Profile(PROFILE_CORE) @Repository -public interface OnlineCourseConfigurationRepository extends JpaRepository { +public interface OnlineCourseConfigurationRepository extends ArtemisJpaRepository { // This interface is intentionally left blank. Spring Data JPA generates the implementation at runtime. } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/OnlineUnitRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/OnlineUnitRepository.java index 03f49b353dce..81b7b9d05cfb 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/OnlineUnitRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/OnlineUnitRepository.java @@ -2,25 +2,17 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.OnlineUnit; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Online Unit entity. */ @Profile(PROFILE_CORE) @Repository -public interface OnlineUnitRepository extends JpaRepository { - - @NotNull - default OnlineUnit findByIdElseThrow(Long onlineUnitId) throws EntityNotFoundException { - return findById(onlineUnitId).orElseThrow(() -> new EntityNotFoundException("OnlineUnit", onlineUnitId)); - } +public interface OnlineUnitRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/OrganizationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/OrganizationRepository.java index 8ebbc9ed4329..bc488d0ca46a 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/OrganizationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/OrganizationRepository.java @@ -12,12 +12,12 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Organization; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -25,7 +25,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface OrganizationRepository extends JpaRepository { +public interface OrganizationRepository extends ArtemisJpaRepository { @Query(""" SELECT organization @@ -129,17 +129,6 @@ default Set getAllMatchingOrganizationsByUserEmail(String userEmai return matchingOrganizations; } - /** - * Get an organization by its id, or else throw exception - * - * @param organizationId the id of the organization to find - * @return the organization entity, if it exists - */ - @NotNull - default Organization findByIdElseThrow(long organizationId) throws EntityNotFoundException { - return findById(organizationId).orElseThrow(() -> new EntityNotFoundException("Organization", organizationId)); - } - /** * Get an organization containing the eagerly loaded list of users and courses * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ParticipantScoreRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ParticipantScoreRepository.java index 73fdba635566..88d4388925ea 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ParticipantScoreRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ParticipantScoreRepository.java @@ -14,7 +14,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -25,13 +24,14 @@ import de.tum.in.www1.artemis.domain.quiz.QuizExercise; import de.tum.in.www1.artemis.domain.scores.ParticipantScore; import de.tum.in.www1.artemis.domain.statistics.ScoreDistribution; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.service.scheduled.ParticipantScoreScheduleService; import de.tum.in.www1.artemis.web.rest.dto.CourseManagementOverviewExerciseStatisticsDTO; import de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation; @Profile(PROFILE_CORE) @Repository -public interface ParticipantScoreRepository extends JpaRepository { +public interface ParticipantScoreRepository extends ArtemisJpaRepository { /** * Find all outdated participant scores where the last result was deleted (and therefore set to null). diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ParticipationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ParticipationRepository.java index a6bda27dcc89..9c4b8a828aab 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ParticipationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ParticipationRepository.java @@ -12,18 +12,18 @@ import jakarta.validation.constraints.NotNull; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.participation.Participation; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface ParticipationRepository extends JpaRepository { +public interface ParticipationRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT p @@ -87,11 +87,6 @@ default Participation findWithEagerSubmissionsByIdWithTeamStudentsElseThrow(long return findWithEagerSubmissionsByIdWithTeamStudents(participationId).orElseThrow(() -> new EntityNotFoundException("Participation", participationId)); } - @NotNull - default Participation findByIdElseThrow(long participationId) { - return findById(participationId).orElseThrow(() -> new EntityNotFoundException("Participation", participationId)); - } - @Query(""" SELECT MAX(p.individualDueDate) FROM Participation p diff --git a/src/main/java/de/tum/in/www1/artemis/repository/PersistenceAuditEventRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/PersistenceAuditEventRepository.java index b0a701c97e78..550b9f360db8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/PersistenceAuditEventRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/PersistenceAuditEventRepository.java @@ -11,14 +11,14 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import de.tum.in.www1.artemis.domain.PersistentAuditEvent; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the PersistentAuditEvent entity. */ -public interface PersistenceAuditEventRepository extends JpaRepository { +public interface PersistenceAuditEventRepository extends ArtemisJpaRepository { @EntityGraph(type = LOAD, attributePaths = { "data" }) List findByPrincipalAndAuditEventDateAfterAndAuditEventType(String principle, Instant after, String type); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseRepository.java index 7fe5e913d084..41cd1ffb5ba5 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseRepository.java @@ -7,7 +7,6 @@ import static org.springframework.data.jpa.repository.EntityGraph.EntityGraphType.LOAD; import java.time.ZonedDateTime; -import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.Set; @@ -480,17 +479,6 @@ SELECT COUNT (DISTINCT p) long countByTitleAndExerciseGroupExamCourse(String shortName, Course course); - /** - * Find a programming exercise by its id and throw an EntityNotFoundException if it cannot be found - * - * @param programmingExerciseId of the programming exercise. - * @return The programming exercise related to the given id - */ - @NotNull - default ProgrammingExercise findByIdElseThrow(long programmingExerciseId) throws EntityNotFoundException { - return findById(programmingExerciseId).orElseThrow(() -> new EntityNotFoundException("Programming Exercise", programmingExerciseId)); - } - /** * Find a programming exercise by its id, with grading criteria loaded, and throw an EntityNotFoundException if it cannot be found * @@ -629,34 +617,7 @@ default ProgrammingExercise findByIdWithTemplateAndSolutionParticipationTeamAssi long programmingExerciseId) throws EntityNotFoundException { Optional programmingExercise = findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesAndCompetenciesAndPlagiarismDetectionConfigById( programmingExerciseId); - return programmingExercise.orElseThrow(() -> new EntityNotFoundException("Programming Exercise", programmingExerciseId)); - } - - /** - * Finds a {@link ProgrammingExercise} by its ID with optional dynamic fetching of associated entities. - * - * @param exerciseId the ID of the programming exercise to find. - * @param fetchOptions a collection of {@link ProgrammingExerciseFetchOptions} indicating which associated entities to fetch. - * @return the {@link ProgrammingExercise} with the specified ID and the associated entities fetched according to the provided options. - * @throws EntityNotFoundException if the programming exercise with the specified ID does not exist. - */ - @NotNull - default ProgrammingExercise findByIdWithDynamicFetchElseThrow(long exerciseId, ProgrammingExerciseFetchOptions... fetchOptions) throws EntityNotFoundException { - return findByIdWithDynamicFetchElseThrow(exerciseId, Set.of(fetchOptions)); - } - - /** - * Finds a {@link ProgrammingExercise} by its ID with optional dynamic fetching of associated entities. - * - * @param exerciseId the ID of the programming exercise to find. - * @param fetchOptions a collection of {@link ProgrammingExerciseFetchOptions} indicating which associated entities to fetch. - * @return the {@link ProgrammingExercise} with the specified ID and the associated entities fetched according to the provided options. - * @throws EntityNotFoundException if the programming exercise with the specified ID does not exist. - */ - @NotNull - default ProgrammingExercise findByIdWithDynamicFetchElseThrow(long exerciseId, Collection fetchOptions) throws EntityNotFoundException { - var specification = getDynamicSpecification(fetchOptions); - return findOneByIdElseThrow(specification, exerciseId, "Programming Exercise"); + return getValueElseThrow(programmingExercise, programmingExerciseId); } /** diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java index 99ad9010b667..77bd22761f83 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java @@ -8,11 +8,8 @@ import java.util.List; import java.util.Optional; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -20,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -27,7 +25,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ProgrammingExerciseStudentParticipationRepository extends JpaRepository { +public interface ProgrammingExerciseStudentParticipationRepository extends ArtemisJpaRepository { @Query(""" SELECT p @@ -169,11 +167,6 @@ Optional findWithSubmissionsByExerciseI @EntityGraph(type = LOAD, attributePaths = "team.students") Optional findWithTeamStudentsById(long participationId); - @NotNull - default ProgrammingExerciseStudentParticipation findByIdElseThrow(long participationId) { - return findById(participationId).orElseThrow(() -> new EntityNotFoundException("Programming Exercise Student Participation", participationId)); - } - default Optional findStudentParticipationWithLatestResultAndFeedbacksAndRelatedSubmissions(long participationId) { return findByIdWithLatestResultAndFeedbacksAndRelatedSubmissions(participationId, ZonedDateTime.now()); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseTestCaseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseTestCaseRepository.java index 77317043e1f9..6725aa96c1b2 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseTestCaseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseTestCaseRepository.java @@ -6,12 +6,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -19,7 +19,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ProgrammingExerciseTestCaseRepository extends JpaRepository { +public interface ProgrammingExerciseTestCaseRepository extends ArtemisJpaRepository { Set findByExerciseId(long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingSubmissionRepository.java index 06cc727111d9..859697f67699 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ProgrammingSubmissionRepository.java @@ -11,12 +11,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.ProgrammingSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -24,18 +24,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ProgrammingSubmissionRepository extends JpaRepository { - - /** - * Load programming submission only - * - * @param submissionId the submissionId - * @return programming submission - */ - @NotNull - default ProgrammingSubmission findByIdElseThrow(long submissionId) { - return findById(submissionId).orElseThrow(() -> new EntityNotFoundException("ProgrammingSubmission", submissionId)); - } +public interface ProgrammingSubmissionRepository extends ArtemisJpaRepository { @Query(""" SELECT s diff --git a/src/main/java/de/tum/in/www1/artemis/repository/PushNotificationDeviceConfigurationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/PushNotificationDeviceConfigurationRepository.java index a68e554758b3..1f8b36b32de3 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/PushNotificationDeviceConfigurationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/PushNotificationDeviceConfigurationRepository.java @@ -6,7 +6,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -17,13 +16,14 @@ import de.tum.in.www1.artemis.domain.push_notification.PushNotificationDeviceConfiguration; import de.tum.in.www1.artemis.domain.push_notification.PushNotificationDeviceConfigurationId; import de.tum.in.www1.artemis.domain.push_notification.PushNotificationDeviceType; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * The Repository used for PushNotificationDeviceConfiguration */ @Profile(PROFILE_CORE) @Repository -public interface PushNotificationDeviceConfigurationRepository extends JpaRepository { +public interface PushNotificationDeviceConfigurationRepository extends ArtemisJpaRepository { /** * @param users a list of users you want the deviceTokens for. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizBatchRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizBatchRepository.java index f0e5d7cbe58e..4859410697c2 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizBatchRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizBatchRepository.java @@ -5,24 +5,21 @@ import java.util.Optional; import java.util.Set; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizBatch; import de.tum.in.www1.artemis.domain.quiz.QuizExercise; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the QuizBatch entity. */ @Profile(PROFILE_CORE) @Repository -public interface QuizBatchRepository extends JpaRepository { +public interface QuizBatchRepository extends ArtemisJpaRepository { Set findAllByQuizExercise(QuizExercise quizExercise); @@ -48,9 +45,4 @@ JOIN TREAT(submission.participation AS StudentParticipation) participation AND participation.student.login = :studentLogin """) Optional findByQuizExerciseAndStudentLogin(@Param("quizExercise") QuizExercise quizExercise, @Param("studentLogin") String studentLogin); - - @NotNull - default QuizBatch findByIdElseThrow(Long quizBatchId) throws EntityNotFoundException { - return findById(quizBatchId).orElseThrow(() -> new EntityNotFoundException("Quiz Batch", quizBatchId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizExerciseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizExerciseRepository.java index 6adb4d9032dc..e1b06708f1bb 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizExerciseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizExerciseRepository.java @@ -12,13 +12,13 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizExercise; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -26,7 +26,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface QuizExerciseRepository extends JpaRepository, JpaSpecificationExecutor { +public interface QuizExerciseRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { @Query(""" SELECT DISTINCT e @@ -79,11 +79,6 @@ public interface QuizExerciseRepository extends JpaRepository findWithEagerBatchesById(Long quizExerciseId); - @NotNull - default QuizExercise findByIdElseThrow(Long quizExerciseId) throws EntityNotFoundException { - return findById(quizExerciseId).orElseThrow(() -> new EntityNotFoundException("Quiz Exercise", quizExerciseId)); - } - @NotNull default QuizExercise findWithEagerQuestionsByIdOrElseThrow(Long quizExerciseId) { return findWithEagerQuestionsById(quizExerciseId).orElseThrow(() -> new EntityNotFoundException("QuizExercise", quizExerciseId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizGroupRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizGroupRepository.java index 68a326b13c20..7ed1ad585377 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizGroupRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizGroupRepository.java @@ -3,10 +3,10 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizGroup; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the QuizGroup entity. @@ -14,5 +14,5 @@ @Profile(PROFILE_CORE) @SuppressWarnings("unused") @Repository -public interface QuizGroupRepository extends JpaRepository { +public interface QuizGroupRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizPointStatisticRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizPointStatisticRepository.java index 0709ca98d157..283849e5d3b4 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizPointStatisticRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizPointStatisticRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizPointStatistic; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the QuizPointStatistic entity. */ @Profile(PROFILE_CORE) @Repository -public interface QuizPointStatisticRepository extends JpaRepository { +public interface QuizPointStatisticRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizPoolRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizPoolRepository.java index 62805a9635f1..4bcd85050d26 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizPoolRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizPoolRepository.java @@ -5,12 +5,12 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizPool; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the QuizPool entity. @@ -18,7 +18,7 @@ @Profile(PROFILE_CORE) @SuppressWarnings("unused") @Repository -public interface QuizPoolRepository extends JpaRepository { +public interface QuizPoolRepository extends ArtemisJpaRepository { @Query(""" SELECT qe diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionRepository.java index bc90d1703974..57b29b6f54c8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionRepository.java @@ -6,13 +6,13 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.DragAndDropQuestion; import de.tum.in.www1.artemis.domain.quiz.QuizQuestion; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -20,7 +20,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface QuizQuestionRepository extends JpaRepository { +public interface QuizQuestionRepository extends ArtemisJpaRepository { Set findByExercise_Id(long id); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionStatisticRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionStatisticRepository.java index fe9f8fd1277b..eec072f1c7fd 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionStatisticRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizQuestionStatisticRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizQuestionStatistic; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the QuizQuestionStatistic entity. */ @Profile(PROFILE_CORE) @Repository -public interface QuizQuestionStatisticRepository extends JpaRepository { +public interface QuizQuestionStatisticRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/QuizSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/QuizSubmissionRepository.java index 423b91a4e845..a7b2a5c1d107 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/QuizSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/QuizSubmissionRepository.java @@ -8,19 +8,19 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.QuizSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the QuizSubmission entity. */ @Profile(PROFILE_CORE) @Repository -public interface QuizSubmissionRepository extends JpaRepository { +public interface QuizSubmissionRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT submission diff --git a/src/main/java/de/tum/in/www1/artemis/repository/RatingRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/RatingRepository.java index d9f7cfaaf8c5..9f71db5c372f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/RatingRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/RatingRepository.java @@ -6,7 +6,6 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -15,13 +14,14 @@ import de.tum.in.www1.artemis.domain.Rating; import de.tum.in.www1.artemis.domain.assessment.dashboard.ExerciseRatingCount; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Rating entity. */ @Profile(PROFILE_CORE) @Repository -public interface RatingRepository extends JpaRepository { +public interface RatingRepository extends ArtemisJpaRepository { Optional findRatingByResultId(long resultId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ResultRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ResultRepository.java index 009af506add7..c05831accdc8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ResultRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ResultRepository.java @@ -16,7 +16,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -33,6 +32,7 @@ import de.tum.in.www1.artemis.domain.assessment.dashboard.ResultCount; import de.tum.in.www1.artemis.domain.enumeration.AssessmentType; import de.tum.in.www1.artemis.domain.leaderboard.tutor.TutorLeaderboardAssessments; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.service.util.RoundingUtil; import de.tum.in.www1.artemis.web.rest.dto.DueDateStat; import de.tum.in.www1.artemis.web.rest.dto.ResultWithPointsPerGradingCriterionDTO; @@ -43,7 +43,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ResultRepository extends JpaRepository { +public interface ResultRepository extends ArtemisJpaRepository { @Query(""" SELECT r @@ -729,16 +729,6 @@ default Result findWithBidirectionalSubmissionAndFeedbackAndAssessorAndAssessmen .orElseThrow(() -> new EntityNotFoundException("Result", resultId)); } - /** - * Get a result from the database by its id, else throws an EntityNotFoundException - * - * @param resultId the id of the result to load from the database - * @return the result - */ - default Result findByIdElseThrow(long resultId) { - return findById(resultId).orElseThrow(() -> new EntityNotFoundException("Result", resultId)); - } - /** * Get a result from the database by its id together with the associated submission and the list of feedback items. * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/ShortAnswerMappingRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/ShortAnswerMappingRepository.java index d2b598f5e7bf..c4fe5287ee9f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/ShortAnswerMappingRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/ShortAnswerMappingRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.quiz.ShortAnswerMapping; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ShortAnswerMapping entity. */ @Profile(PROFILE_CORE) @Repository -public interface ShortAnswerMappingRepository extends JpaRepository { +public interface ShortAnswerMappingRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SingleUserNotificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SingleUserNotificationRepository.java index 2179b430e633..4a1994a11270 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SingleUserNotificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SingleUserNotificationRepository.java @@ -3,15 +3,15 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.notification.SingleUserNotification; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the Notification entity. */ @Profile(PROFILE_CORE) @Repository -public interface SingleUserNotificationRepository extends JpaRepository { +public interface SingleUserNotificationRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SlideRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SlideRepository.java index d935ecf15dfc..7a867f727b50 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SlideRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SlideRepository.java @@ -5,17 +5,17 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.Slide; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Attachment Unit entity. */ @Profile(PROFILE_CORE) @Repository -public interface SlideRepository extends JpaRepository { +public interface SlideRepository extends ArtemisJpaRepository { List findAllByAttachmentUnitId(Long attachmentUnitId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SourceRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SourceRepository.java index 226d1a0b508e..2e370d3555e6 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SourceRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SourceRepository.java @@ -2,24 +2,17 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.competency.Source; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the {@link Source} entity. */ @Profile(PROFILE_CORE) @Repository -public interface SourceRepository extends JpaRepository { +public interface SourceRepository extends ArtemisJpaRepository { - @NotNull - default Source findByIdElseThrow(long sourceId) throws EntityNotFoundException { - return findById(sourceId).orElseThrow(() -> new EntityNotFoundException("Source", sourceId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/StaticCodeAnalysisCategoryRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/StaticCodeAnalysisCategoryRepository.java index d125912e9a69..ce10f9309a61 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/StaticCodeAnalysisCategoryRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/StaticCodeAnalysisCategoryRepository.java @@ -5,17 +5,17 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.StaticCodeAnalysisCategory; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the StaticCodeAnalysisCategory entity. */ @Profile(PROFILE_CORE) @Repository -public interface StaticCodeAnalysisCategoryRepository extends JpaRepository { +public interface StaticCodeAnalysisCategoryRepository extends ArtemisJpaRepository { Set findByExerciseId(long exerciseId); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/StatisticsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/StatisticsRepository.java index 6c26a9a4c105..d931081cbde8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/StatisticsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/StatisticsRepository.java @@ -21,7 +21,6 @@ import jakarta.annotation.Nullable; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -33,13 +32,14 @@ import de.tum.in.www1.artemis.domain.enumeration.StatisticsView; import de.tum.in.www1.artemis.domain.statistics.CourseStatisticsAverageScore; import de.tum.in.www1.artemis.domain.statistics.StatisticsEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the statistics pages */ @Profile(PROFILE_CORE) @Repository -public interface StatisticsRepository extends JpaRepository { +public interface StatisticsRepository extends ArtemisJpaRepository { @Query(""" SELECT new de.tum.in.www1.artemis.domain.statistics.StatisticsEntry( diff --git a/src/main/java/de/tum/in/www1/artemis/repository/StudentExamRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/StudentExamRepository.java index 7d9314a59305..e70b0a721e41 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/StudentExamRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/StudentExamRepository.java @@ -15,7 +15,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -29,6 +28,7 @@ import de.tum.in.www1.artemis.domain.exam.StudentExam; import de.tum.in.www1.artemis.domain.participation.StudentParticipation; import de.tum.in.www1.artemis.domain.quiz.QuizQuestion; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.service.exam.ExamQuizQuestionsGenerator; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -37,7 +37,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface StudentExamRepository extends JpaRepository { +public interface StudentExamRepository extends ArtemisJpaRepository { @EntityGraph(type = LOAD, attributePaths = { "exercises" }) Optional findWithExercisesById(Long studentExamId); @@ -314,11 +314,6 @@ SELECT MAX(se.workingTime) """) void startStudentExam(@Param("studentExamId") Long studentExamId, @Param("startedDate") ZonedDateTime startedDate); - @NotNull - default StudentExam findByIdElseThrow(Long studentExamId) throws EntityNotFoundException { - return findById(studentExamId).orElseThrow(() -> new EntityNotFoundException("Student Exam", studentExamId)); - } - /** * Return the StudentExam of the participation's user, if possible * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/StudentParticipationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/StudentParticipationRepository.java index f8bc5556c2c3..9ac0e5cd8faa 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/StudentParticipationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/StudentParticipationRepository.java @@ -22,7 +22,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -37,6 +36,7 @@ import de.tum.in.www1.artemis.domain.exam.StudentExam; import de.tum.in.www1.artemis.domain.participation.StudentParticipation; import de.tum.in.www1.artemis.domain.quiz.QuizSubmittedAnswerCount; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -44,7 +44,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface StudentParticipationRepository extends JpaRepository { +public interface StudentParticipationRepository extends ArtemisJpaRepository { Set findByExerciseId(long exerciseId); @@ -846,11 +846,6 @@ AND EXISTS ( List findAllByParticipationExerciseIdAndResultAssessorAndCorrectionRoundIgnoreTestRuns(@Param("exerciseId") long exerciseId, @Param("assessor") User assessor); - @NotNull - default StudentParticipation findByIdElseThrow(long studentParticipationId) { - return findById(studentParticipationId).orElseThrow(() -> new EntityNotFoundException("Student Participation", studentParticipationId)); - } - @NotNull default StudentParticipation findByIdWithResultsElseThrow(long participationId) { return findWithEagerResultsById(participationId).orElseThrow(() -> new EntityNotFoundException("StudentParticipation", participationId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/StudentScoreRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/StudentScoreRepository.java index 2cce99028417..04da26cf0a11 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/StudentScoreRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/StudentScoreRepository.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -19,11 +18,12 @@ import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.scores.StudentScore; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.score.StudentScoreSum; @Profile(PROFILE_CORE) @Repository -public interface StudentScoreRepository extends JpaRepository { +public interface StudentScoreRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SubmissionPolicyRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SubmissionPolicyRepository.java index df8f116a59ee..db96f3a3bc35 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SubmissionPolicyRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SubmissionPolicyRepository.java @@ -6,19 +6,19 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the SubmissionPolicy entity. */ @Profile(PROFILE_CORE) @Repository -public interface SubmissionPolicyRepository extends JpaRepository { +public interface SubmissionPolicyRepository extends ArtemisJpaRepository { SubmissionPolicy findByProgrammingExerciseId(Long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SubmissionRepository.java index 7a0f177cfcd8..3ee214c830e4 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SubmissionRepository.java @@ -11,7 +11,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -32,6 +31,7 @@ import de.tum.in.www1.artemis.domain.participation.Participation; import de.tum.in.www1.artemis.domain.quiz.QuizExercise; import de.tum.in.www1.artemis.domain.quiz.QuizSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.DueDateStat; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -40,7 +40,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface SubmissionRepository extends JpaRepository { +public interface SubmissionRepository extends ArtemisJpaRepository { /** * Load submission with eager Results @@ -553,10 +553,6 @@ SELECT MAX(s2.submissionDate) */ Set findByParticipation_ExerciseIdAndSubmittedIsTrue(long exerciseId); - default Submission findByIdElseThrow(long submissionId) { - return findById(submissionId).orElseThrow(() -> new EntityNotFoundException("Submission", submissionId)); - } - /** * GChecks if unassessed Quiz Submissions exist for the given exam * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SubmissionVersionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SubmissionVersionRepository.java index b73204edbb8f..e7926f3c9625 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SubmissionVersionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SubmissionVersionRepository.java @@ -6,19 +6,19 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.SubmissionVersion; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the SubmissionVersion entity. */ @Profile(PROFILE_CORE) @Repository -public interface SubmissionVersionRepository extends JpaRepository { +public interface SubmissionVersionRepository extends ArtemisJpaRepository { @Query(""" SELECT version diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SubmittedAnswerRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SubmittedAnswerRepository.java index b82462b7ae29..713e76585ba7 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SubmittedAnswerRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SubmittedAnswerRepository.java @@ -6,20 +6,20 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.participation.StudentParticipation; import de.tum.in.www1.artemis.domain.quiz.QuizExercise; import de.tum.in.www1.artemis.domain.quiz.QuizSubmission; import de.tum.in.www1.artemis.domain.quiz.SubmittedAnswer; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the SubmittedAnswer entity. */ @Profile(PROFILE_CORE) @Repository -public interface SubmittedAnswerRepository extends JpaRepository { +public interface SubmittedAnswerRepository extends ArtemisJpaRepository { Set findBySubmission(QuizSubmission quizSubmission); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/SystemNotificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/SystemNotificationRepository.java index 4b467782d8d5..f060fdb74f9c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/SystemNotificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/SystemNotificationRepository.java @@ -6,19 +6,19 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.notification.SystemNotification; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the Notification entity. */ @Profile(PROFILE_CORE) @Repository -public interface SystemNotificationRepository extends JpaRepository { +public interface SystemNotificationRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT notification diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TeamRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TeamRepository.java index c27ad71cc6e7..8ae28ba7c922 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TeamRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TeamRepository.java @@ -11,7 +11,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.data.util.Pair; @@ -20,6 +19,7 @@ import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.Team; import de.tum.in.www1.artemis.domain.User; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; import de.tum.in.www1.artemis.web.rest.errors.StudentsAlreadyAssignedException; @@ -28,7 +28,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface TeamRepository extends JpaRepository { +public interface TeamRepository extends ArtemisJpaRepository { @EntityGraph(type = LOAD, attributePaths = "students") List findAllByExerciseId(Long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TeamScoreRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TeamScoreRepository.java index bdaf474eafe2..e3b42a9c57a1 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TeamScoreRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TeamScoreRepository.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -20,11 +19,12 @@ import de.tum.in.www1.artemis.domain.Team; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.scores.TeamScore; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.score.TeamScoreSum; @Profile(PROFILE_CORE) @Repository -public interface TeamScoreRepository extends JpaRepository { +public interface TeamScoreRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TextAssessmentEventRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TextAssessmentEventRepository.java index 3f1704289715..83997008937f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TextAssessmentEventRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TextAssessmentEventRepository.java @@ -7,19 +7,19 @@ import java.util.Map; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.analytics.TextAssessmentEvent; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the TextAssessmentEvent entity. */ @Profile(PROFILE_CORE) @Repository -public interface TextAssessmentEventRepository extends JpaRepository { +public interface TextAssessmentEventRepository extends ArtemisJpaRepository { List findAllByCourseId(long courseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TextBlockRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TextBlockRepository.java index 0677181e7e7c..cf9cfd5e44e0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TextBlockRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TextBlockRepository.java @@ -5,19 +5,19 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.TextBlock; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the TextBlock entity. */ @Profile(PROFILE_CORE) @Repository -public interface TextBlockRepository extends JpaRepository { +public interface TextBlockRepository extends ArtemisJpaRepository { Set findAllBySubmissionId(Long id); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TextExerciseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TextExerciseRepository.java index c0b27636757d..23466f1280c0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TextExerciseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TextExerciseRepository.java @@ -10,13 +10,13 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.TextExercise; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -24,7 +24,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface TextExerciseRepository extends JpaRepository, JpaSpecificationExecutor { +public interface TextExerciseRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { @Query(""" SELECT DISTINCT e @@ -57,11 +57,6 @@ public interface TextExerciseRepository extends JpaRepository findWithStudentParticipationsAndSubmissionsById(long exerciseId); - @NotNull - default TextExercise findByIdElseThrow(long exerciseId) { - return findById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Text Exercise", exerciseId)); - } - @EntityGraph(type = LOAD, attributePaths = { "gradingCriteria" }) Optional findWithGradingCriteriaById(long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TextSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TextSubmissionRepository.java index 20446559d5c1..694eaa6c96b3 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TextSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TextSubmissionRepository.java @@ -10,10 +10,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.TextSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -22,7 +22,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface TextSubmissionRepository extends JpaRepository { +public interface TextSubmissionRepository extends ArtemisJpaRepository { @EntityGraph(type = LOAD, attributePaths = { "results.feedbacks", "results.assessor", "participation.exercise" }) Optional findWithEagerParticipationExerciseResultAssessorById(long submissionId); @@ -30,17 +30,6 @@ public interface TextSubmissionRepository extends JpaRepository findWithEagerParticipationExerciseResultAssessorAssessmentNoteById(long submissionId); - /** - * Load text submission only - * - * @param submissionId the submissionId - * @return optional text submission - */ - @NotNull - default TextSubmission findByIdElseThrow(long submissionId) { - return findById(submissionId).orElseThrow(() -> new EntityNotFoundException("Text Submission", submissionId)); - } - /** * Load text submission with eager Results * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TextUnitRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TextUnitRepository.java index 0c12a57fdef3..5d3b1491437e 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TextUnitRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TextUnitRepository.java @@ -5,19 +5,19 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.TextUnit; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Text Unit entity. */ @Profile(PROFILE_CORE) @Repository -public interface TextUnitRepository extends JpaRepository { +public interface TextUnitRepository extends ArtemisJpaRepository { @Query(""" SELECT tu diff --git a/src/main/java/de/tum/in/www1/artemis/repository/TutorParticipationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/TutorParticipationRepository.java index b9e35a986325..a98e50f2ec8f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/TutorParticipationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/TutorParticipationRepository.java @@ -7,7 +7,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -16,13 +15,14 @@ import de.tum.in.www1.artemis.domain.Exercise; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.participation.TutorParticipation; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the TutorParticipation entity. */ @Profile(PROFILE_CORE) @Repository -public interface TutorParticipationRepository extends JpaRepository { +public interface TutorParticipationRepository extends ArtemisJpaRepository { List findByAssessedExercise(Exercise assessedExercise); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java index efcd1f993bfa..d89fc38b590c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/UserRepository.java @@ -28,7 +28,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -42,6 +41,7 @@ import de.tum.in.www1.artemis.domain.Organization; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.enumeration.SortingOrder; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.security.Role; import de.tum.in.www1.artemis.security.SecurityUtils; import de.tum.in.www1.artemis.service.dto.UserDTO; @@ -59,7 +59,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { +public interface UserRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { String USERS_CACHE = "users"; @@ -951,10 +951,6 @@ default boolean isCurrentUser(String login) { return SecurityUtils.getCurrentUserLogin().map(currentLogin -> currentLogin.equals(login)).orElse(false); } - default User findByIdElseThrow(long userId) throws EntityNotFoundException { - return findById(userId).orElseThrow(() -> new EntityNotFoundException("User", userId)); - } - Optional findBySshPublicKeyHash(String keyString); /** diff --git a/src/main/java/de/tum/in/www1/artemis/repository/VideoUnitRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/VideoUnitRepository.java index 001e1c65c062..6fa8229fb9b3 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/VideoUnitRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/VideoUnitRepository.java @@ -2,25 +2,17 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.VideoUnit; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the Video Unit entity. */ @Profile(PROFILE_CORE) @Repository -public interface VideoUnitRepository extends JpaRepository { - - @NotNull - default VideoUnit findByIdElseThrow(Long videoUnitId) throws EntityNotFoundException { - return findById(videoUnitId).orElseThrow(() -> new EntityNotFoundException("VideoUnit", videoUnitId)); - } +public interface VideoUnitRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/base/ArtemisJpaRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/base/ArtemisJpaRepository.java new file mode 100644 index 000000000000..3077fb94fdc9 --- /dev/null +++ b/src/main/java/de/tum/in/www1/artemis/repository/base/ArtemisJpaRepository.java @@ -0,0 +1,43 @@ +package de.tum.in.www1.artemis.repository.base; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.NoRepositoryBean; + +/** + * A repository that provides methods for fetching entities dynamically using {@link FetchOptions}. + * + * @param the type of the entity + */ +@NoRepositoryBean +public interface ArtemisJpaRepository extends JpaRepository { + + /** + * Get the entity if it exists or throw an EntityNotFoundException. + * Implemented in {@link RepositoryImpl#getValueElseThrow(Optional)}. + * + * @param optional the optional to get the entity from + * @return the entity if it exists + */ + T getValueElseThrow(Optional optional); + + /** + * Get the entity if it exists or throw an EntityNotFoundException. + * Implemented in {@link RepositoryImpl#getValueElseThrow(Optional, ID)}. + * + * @param optional the optional to get the entity from + * @param id the id of the entity to find + * @return the entity if it exists + */ + T getValueElseThrow(Optional optional, ID id); + + /** + * Find an entity by its id or throw an EntityNotFoundException if it does not exist. + * Implemented in {@link RepositoryImpl#findByIdElseThrow(ID)}. + * + * @param id the id of the entity to find + * @return the entity with the given id + */ + T findByIdElseThrow(ID id); +} diff --git a/src/main/java/de/tum/in/www1/artemis/repository/base/DynamicSpecificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/base/DynamicSpecificationRepository.java index 7c2d534b7c0e..03320a58eb25 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/base/DynamicSpecificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/base/DynamicSpecificationRepository.java @@ -1,17 +1,15 @@ package de.tum.in.www1.artemis.repository.base; import java.util.Collection; -import java.util.Optional; +import java.util.List; import jakarta.persistence.criteria.JoinType; import jakarta.validation.constraints.NotNull; import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.NoRepositoryBean; -import de.tum.in.www1.artemis.domain.DomainObject_; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -20,30 +18,44 @@ * @param the type of the entity */ @NoRepositoryBean -public interface DynamicSpecificationRepository extends JpaRepository, JpaSpecificationExecutor { +public interface DynamicSpecificationRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { /** - * Find an entity by its id and given specification. + * Find an entity by its id and given specification or throw an EntityNotFoundException if it does not exist. + * Implemented in {@link RepositoryImpl#findOneByIdElseThrow(Specification, ID)}. * * @param specification the specification to apply * @param id the id of the entity to find * @return the entity with the given id */ - default Optional findOneById(Specification specification, ID id) { - final Specification hasIdSpec = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get(DomainObject_.ID), id); - return findOne(specification.and(hasIdSpec)); + @NotNull + T findOneByIdElseThrow(final Specification specification, ID id); + + /** + * Finds an entity by its ID with optional dynamic fetching of associated entities. + * Throws an {@link EntityNotFoundException} if the entity with the specified ID does not exist. + * + * @param id the ID of the entity to find. + * @param fetchOptions a collection of fetch options specifying the entities to fetch dynamically. + * @return the entity with the specified ID and the associated entities fetched according to the provided options. + */ + @NotNull + default T findByIdWithDynamicFetchElseThrow(ID id, F... fetchOptions) { + return findByIdWithDynamicFetchElseThrow(id, List.of(fetchOptions)); } /** - * Find an entity by its id and given specification or throw an EntityNotFoundException if it does not exist. + * Finds an entity by its ID with optional dynamic fetching of associated entities. + * Throws an {@link EntityNotFoundException} if the entity with the specified ID does not exist. * - * @param specification the specification to apply - * @param id the id of the entity to find - * @param entityName the name of the entity to find - * @return the entity with the given id + * @param id the ID of the entity to find. + * @param fetchOptions a collection of fetch options specifying the entities to fetch dynamically. + * @return the entity with the specified ID and the associated entities fetched according to the provided options. */ - default T findOneByIdElseThrow(Specification specification, ID id, String entityName) { - return findOneById(specification, id).orElseThrow(() -> new EntityNotFoundException(entityName, String.valueOf(id))); + @NotNull + default T findByIdWithDynamicFetchElseThrow(ID id, Collection fetchOptions) { + var specification = getDynamicSpecification(fetchOptions); + return findOneByIdElseThrow(specification, id); } /** diff --git a/src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java b/src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java new file mode 100644 index 000000000000..9824ab09b73b --- /dev/null +++ b/src/main/java/de/tum/in/www1/artemis/repository/base/RepositoryImpl.java @@ -0,0 +1,99 @@ +package de.tum.in.www1.artemis.repository.base; + +import java.util.Optional; + +import jakarta.persistence.EntityManager; +import jakarta.validation.constraints.NotNull; + +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.support.JpaEntityInformation; +import org.springframework.data.jpa.repository.support.JpaEntityInformationSupport; +import org.springframework.data.jpa.repository.support.SimpleJpaRepository; + +import de.tum.in.www1.artemis.domain.DomainObject_; +import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; + +public class RepositoryImpl extends SimpleJpaRepository { + + private final JpaEntityInformation entityInformation; + + /** + * Creates a new {@link SimpleJpaRepository} to manage objects of the given {@link JpaEntityInformation}. + * + * @param entityInformation the information of the entity + * @param entityManager the {@link EntityManager} to be used + */ + public RepositoryImpl(JpaEntityInformation entityInformation, EntityManager entityManager) { + super(entityInformation, entityManager); + this.entityInformation = entityInformation; + } + + /** + * Creates a new {@link SimpleJpaRepository} to manage objects of the given domain type. + * + * @param domainClass the class of the domain type to manage + * @param entityManager the {@link EntityManager} to be used + */ + public RepositoryImpl(Class domainClass, EntityManager entityManager) { + this(JpaEntityInformationSupport.getEntityInformation(domainClass, entityManager), entityManager); + } + + /** + * Find an entity by its id and given specification. + * + * @param specification the specification to apply + * @param id the id of the entity to find + * @return the entity with the given id + */ + @NotNull + Optional findOneById(Specification specification, ID id) { + final Specification hasIdSpec = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get(DomainObject_.ID), id); + return findOne(specification.and(hasIdSpec)); + } + + /** + * Find an entity by its id and given specification or throw an EntityNotFoundException if it does not exist. + * + * @param specification the specification to apply + * @param id the id of the entity to find + * @return the entity with the given id + */ + @NotNull + public T findOneByIdElseThrow(final Specification specification, ID id) { + return this.findOneById(specification, id).orElseThrow(() -> new EntityNotFoundException(entityInformation.getEntityName(), String.valueOf(id))); + } + + /** + * Get the entity if it exists or throw an EntityNotFoundException. + * + * @param optional the optional to get the entity from + * @return the entity if it exists + */ + @NotNull + public T getValueElseThrow(Optional optional) { + return optional.orElseThrow(() -> new EntityNotFoundException(entityInformation.getEntityName())); + } + + /** + * Get the entity if it exists or throw an EntityNotFoundException. + * + * @param optional the optional to get the entity from + * @param id the id of the entity to find + * @return the entity if it exists + */ + @NotNull + public T getValueElseThrow(Optional optional, ID id) { + return optional.orElseThrow(() -> new EntityNotFoundException(entityInformation.getEntityName(), String.valueOf(id))); + } + + /** + * Find an entity by its id or throw an EntityNotFoundException if it does not exist. + * + * @param id the id of the entity to find + * @return the entity with the given id + */ + @NotNull + public T findByIdElseThrow(ID id) { + return getValueElseThrow(findById(id), id); + } +} diff --git a/src/main/java/de/tum/in/www1/artemis/repository/competency/CompetencyJolRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/competency/CompetencyJolRepository.java index 20a4a61b20fd..3a3348dc5046 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/competency/CompetencyJolRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/competency/CompetencyJolRepository.java @@ -6,12 +6,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.competency.CompetencyJol; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.competency.CompetencyJolDTO; /** @@ -19,7 +19,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface CompetencyJolRepository extends JpaRepository { +public interface CompetencyJolRepository extends ArtemisJpaRepository { @Query(""" SELECT jol diff --git a/src/main/java/de/tum/in/www1/artemis/repository/competency/KnowledgeAreaRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/competency/KnowledgeAreaRepository.java index 78d9bc818a24..91e590770e9f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/competency/KnowledgeAreaRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/competency/KnowledgeAreaRepository.java @@ -10,12 +10,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.competency.KnowledgeArea; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -23,7 +23,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface KnowledgeAreaRepository extends JpaRepository { +public interface KnowledgeAreaRepository extends ArtemisJpaRepository { @EntityGraph(type = LOAD, attributePaths = { "children", "competencies" }) Optional findWithChildrenAndCompetenciesById(long knowledgeAreaId); @@ -36,11 +36,6 @@ default KnowledgeArea findWithChildrenAndCompetenciesByIdElseThrow(long knowledg return findWithChildrenAndCompetenciesById(knowledgeAreaId).orElseThrow(() -> new EntityNotFoundException("KnowledgeArea", knowledgeAreaId)); } - @NotNull - default KnowledgeArea findByIdElseThrow(long knowledgeAreaId) throws EntityNotFoundException { - return findById(knowledgeAreaId).orElseThrow(() -> new EntityNotFoundException("KnowledgeArea", knowledgeAreaId)); - } - // this method is needed as native MySQL queries do not get automatically cast to boolean default boolean isDescendantOf(long descendantId, long parentId) { return isDescendantOfAsLong(descendantId, parentId) > 0; diff --git a/src/main/java/de/tum/in/www1/artemis/repository/competency/StandardizedCompetencyRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/competency/StandardizedCompetencyRepository.java index c44d4b356454..d4ceca15f940 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/competency/StandardizedCompetencyRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/competency/StandardizedCompetencyRepository.java @@ -2,24 +2,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; -import jakarta.validation.constraints.NotNull; - import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.competency.StandardizedCompetency; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the {@link StandardizedCompetency} entity. */ @Profile(PROFILE_CORE) @Repository -public interface StandardizedCompetencyRepository extends JpaRepository { - - @NotNull - default StandardizedCompetency findByIdElseThrow(long competencyId) throws EntityNotFoundException { - return findById(competencyId).orElseThrow(() -> new EntityNotFoundException("StandardizedCompetency", competencyId)); - } +public interface StandardizedCompetencyRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/CodeHintRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/CodeHintRepository.java index 8994fb4d57e1..045dfd1d0da7 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/CodeHintRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/CodeHintRepository.java @@ -5,25 +5,20 @@ import jakarta.validation.constraints.NotNull; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.hestia.CodeHint; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Spring Data repository for the CodeHint entity. */ -public interface CodeHintRepository extends JpaRepository { +public interface CodeHintRepository extends ArtemisJpaRepository { Set findByExerciseId(Long exerciseId); - @NotNull - default CodeHint findByIdElseThrow(long exerciseHintId) throws EntityNotFoundException { - return findById(exerciseHintId).orElseThrow(() -> new EntityNotFoundException("Code Hint", exerciseHintId)); - } - @NotNull default CodeHint findByIdWithSolutionEntriesElseThrow(long exerciseHintId) throws EntityNotFoundException { return findByIdWithSolutionEntries(exerciseHintId).orElseThrow(() -> new EntityNotFoundException("Code Hint", exerciseHintId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageFileReportRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageFileReportRepository.java index ba420e1c9ea2..b47887d9b8bb 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageFileReportRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageFileReportRepository.java @@ -3,13 +3,13 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.hestia.CoverageFileReport; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface CoverageFileReportRepository extends JpaRepository { +public interface CoverageFileReportRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageReportRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageReportRepository.java index a6e2fd384517..becf557e8fd0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageReportRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/CoverageReportRepository.java @@ -7,7 +7,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -15,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.hestia.CoverageReport; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -22,7 +22,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface CoverageReportRepository extends JpaRepository { +public interface CoverageReportRepository extends ArtemisJpaRepository { Boolean existsBySubmissionId(Long submissionId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintActivationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintActivationRepository.java index 7ec636b7f708..7b98e098cd77 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintActivationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintActivationRepository.java @@ -3,14 +3,14 @@ import java.util.Optional; import java.util.Set; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.hestia.ExerciseHintActivation; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; -public interface ExerciseHintActivationRepository extends JpaRepository { +public interface ExerciseHintActivationRepository extends ArtemisJpaRepository { @Query(""" SELECT hintActivation diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintRepository.java index 8847183d1bf5..96550e3c8d03 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ExerciseHintRepository.java @@ -8,12 +8,12 @@ import jakarta.validation.constraints.NotNull; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.hestia.ExerciseHint; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -21,7 +21,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ExerciseHintRepository extends JpaRepository { +public interface ExerciseHintRepository extends ArtemisJpaRepository { @Query(""" SELECT h @@ -36,11 +36,6 @@ default ExerciseHint findByIdWithRelationsElseThrow(long hintId) throws EntityNo return findByIdWithRelations(hintId).orElseThrow(() -> new EntityNotFoundException("Exercise Hint", hintId)); } - @NotNull - default ExerciseHint findByIdElseThrow(long exerciseHintId) throws EntityNotFoundException { - return findById(exerciseHintId).orElseThrow(() -> new EntityNotFoundException("Exercise Hint", exerciseHintId)); - } - Set findByExerciseId(Long exerciseId); @Query(""" diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseGitDiffReportRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseGitDiffReportRepository.java index 13e6f90ac179..a8c6e7d0a817 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseGitDiffReportRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseGitDiffReportRepository.java @@ -5,19 +5,19 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseGitDiffReport; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the ProgrammingExerciseGitDiffReport entity. */ @Repository @Profile(PROFILE_CORE) -public interface ProgrammingExerciseGitDiffReportRepository extends JpaRepository { +public interface ProgrammingExerciseGitDiffReportRepository extends ArtemisJpaRepository { /** * Avoid using this method. Use ProgrammingExerciseGitDiffReportService::getReportOfExercise instead diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseSolutionEntryRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseSolutionEntryRepository.java index 8f8d864d6e4c..cd3c579420c9 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseSolutionEntryRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseSolutionEntryRepository.java @@ -5,17 +5,17 @@ import jakarta.validation.constraints.NotNull; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Spring Data repository for the ProgrammingExerciseSolutionEntry entity. */ -public interface ProgrammingExerciseSolutionEntryRepository extends JpaRepository { +public interface ProgrammingExerciseSolutionEntryRepository extends ArtemisJpaRepository { /** * Gets a solution entry with its test cases and programming exercise diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseTaskRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseTaskRepository.java index 449e415ee8ac..3dcc0d3ab9d8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseTaskRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/ProgrammingExerciseTaskRepository.java @@ -5,17 +5,17 @@ import jakarta.validation.constraints.NotNull; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTask; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Spring Data repository for the ProgrammingExerciseTask entity. */ -public interface ProgrammingExerciseTaskRepository extends JpaRepository { +public interface ProgrammingExerciseTaskRepository extends ArtemisJpaRepository { Set findByExerciseId(Long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/hestia/TestwiseCoverageReportEntryRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/hestia/TestwiseCoverageReportEntryRepository.java index 4732a169eb53..9259d53e4a06 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/hestia/TestwiseCoverageReportEntryRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/hestia/TestwiseCoverageReportEntryRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.hestia.TestwiseCoverageReportEntry; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the TestwiseCoverageReportEntry entity. */ @Profile(PROFILE_CORE) @Repository -public interface TestwiseCoverageReportEntryRepository extends JpaRepository { +public interface TestwiseCoverageReportEntryRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCompetencyGenerationSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCompetencyGenerationSessionRepository.java index 869b40e295d9..978749785907 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCompetencyGenerationSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCompetencyGenerationSessionRepository.java @@ -1,13 +1,12 @@ package de.tum.in.www1.artemis.repository.iris; -import org.springframework.data.jpa.repository.JpaRepository; - import de.tum.in.www1.artemis.domain.iris.session.IrisCompetencyGenerationSession; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Repository interface for managing {@link IrisCompetencyGenerationSession} entities. */ -public interface IrisCompetencyGenerationSessionRepository extends JpaRepository { +public interface IrisCompetencyGenerationSessionRepository extends ArtemisJpaRepository { /** * Finds the latest {@link IrisCompetencyGenerationSession} based on its course and user. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCourseChatSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCourseChatSessionRepository.java index 546c0e25b5df..124feae04d42 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCourseChatSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisCourseChatSessionRepository.java @@ -5,17 +5,17 @@ import jakarta.validation.constraints.NotNull; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.iris.session.IrisCourseChatSession; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Repository interface for managing {@link IrisCourseChatSession} entities. */ -public interface IrisCourseChatSessionRepository extends JpaRepository { +public interface IrisCourseChatSessionRepository extends ArtemisJpaRepository { /** * Finds a list of {@link IrisCourseChatSession} based on the exercise and user IDs. @@ -25,12 +25,13 @@ public interface IrisCourseChatSessionRepository extends JpaRepository findByCourseIdAndUserId(@Param("courseId") long courseId, @Param("userId") long userId); @Query(""" @@ -59,16 +60,4 @@ default List findByExerciseIdAndUserIdElseThrow(long cour } return result; } - - /** - * Finds a session by ID or throws an exception if not found. - * - * @param sessionId The ID of the chat session to find. - * @return The found chat session. - * @throws EntityNotFoundException if no session is found. - */ - @NotNull - default IrisCourseChatSession findByIdElseThrow(long sessionId) throws EntityNotFoundException { - return findById(sessionId).orElseThrow(() -> new EntityNotFoundException("Iris Chat Session", sessionId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisExerciseChatSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisExerciseChatSessionRepository.java index 55dc0bd34153..c52b5b7f862c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisExerciseChatSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisExerciseChatSessionRepository.java @@ -5,19 +5,18 @@ import jakarta.validation.constraints.NotNull; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.iris.session.IrisExerciseChatSession; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Repository interface for managing {@link IrisExerciseChatSession} entities. - * Extends Spring Data JPA's {@link JpaRepository}. * Provides custom queries for finding chat sessions based on different criteria. */ -public interface IrisExerciseChatSessionRepository extends JpaRepository { +public interface IrisExerciseChatSessionRepository extends ArtemisJpaRepository { /** * Finds a list of {@link IrisExerciseChatSession} based on the exercise and user IDs. @@ -27,12 +26,13 @@ public interface IrisExerciseChatSessionRepository extends JpaRepository findByExerciseIdAndUserId(@Param("exerciseId") Long exerciseId, @Param("userId") Long userId); @Query(""" @@ -61,16 +61,4 @@ default List findByExerciseIdAndUserIdElseThrow(long ex } return result; } - - /** - * Finds a session by ID or throws an exception if not found. - * - * @param sessionId The ID of the chat session to find. - * @return The found chat session. - * @throws EntityNotFoundException if no session is found. - */ - @NotNull - default IrisExerciseChatSession findByIdElseThrow(long sessionId) throws EntityNotFoundException { - return findById(sessionId).orElseThrow(() -> new EntityNotFoundException("Iris Chat Session", sessionId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisHestiaSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisHestiaSessionRepository.java index c27aa7306033..d5158b939686 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisHestiaSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisHestiaSessionRepository.java @@ -5,15 +5,15 @@ import java.util.List; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import de.tum.in.www1.artemis.domain.iris.session.IrisHestiaSession; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Repository interface for managing {@link IrisHestiaSession} entities. * Provides custom queries for finding hestia sessions based on different criteria. */ -public interface IrisHestiaSessionRepository extends JpaRepository { +public interface IrisHestiaSessionRepository extends ArtemisJpaRepository { /** * Finds a list of {@link IrisHestiaSession} based on the exercise and user IDs. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisMessageRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisMessageRepository.java index fa47a05edf8b..8c8287a43a27 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisMessageRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisMessageRepository.java @@ -8,18 +8,17 @@ import jakarta.validation.constraints.NotNull; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.iris.message.IrisMessage; import de.tum.in.www1.artemis.domain.iris.message.IrisMessageSender; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the IrisMessage entity. */ -public interface IrisMessageRepository extends JpaRepository { +public interface IrisMessageRepository extends ArtemisJpaRepository { List findAllBySessionId(long sessionId); @@ -41,11 +40,6 @@ JOIN TREAT (m.session AS IrisChatSession) s """) int countLlmResponsesOfUserWithinTimeframe(@Param("userId") long userId, @Param("start") ZonedDateTime start, @Param("end") ZonedDateTime end); - @NotNull - default IrisMessage findByIdElseThrow(long messageId) throws EntityNotFoundException { - return findById(messageId).orElseThrow(() -> new EntityNotFoundException("Iris Message", messageId)); - } - @EntityGraph(type = LOAD, attributePaths = { "content" }) IrisMessage findFirstWithContentBySessionIdAndSenderOrderBySentAtDesc(long sessionId, @NotNull IrisMessageSender sender); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSessionRepository.java index 9feaaa7d8c0f..d133f51befca 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSessionRepository.java @@ -4,17 +4,17 @@ import jakarta.validation.constraints.NotNull; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import de.tum.in.www1.artemis.domain.iris.session.IrisSession; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Spring Data repository for the IrisSession entity. */ -public interface IrisSessionRepository extends JpaRepository { +public interface IrisSessionRepository extends ArtemisJpaRepository { @Query(""" SELECT s @@ -33,11 +33,6 @@ public interface IrisSessionRepository extends JpaRepository """) IrisSession findByIdWithMessagesAndContents(@Param("sessionId") long sessionId); - @NotNull - default IrisSession findByIdElseThrow(long sessionId) throws EntityNotFoundException { - return findById(sessionId).orElseThrow(() -> new EntityNotFoundException("Iris Session", sessionId)); - } - @NotNull default IrisSession findByIdWithMessagesElseThrow(long sessionId) throws EntityNotFoundException { return findByIdWithMessages(sessionId).orElseThrow(() -> new EntityNotFoundException("Iris Session", sessionId)); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSettingsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSettingsRepository.java index 3f02ba8fc034..20bd5c7fcd6d 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSettingsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSettingsRepository.java @@ -4,7 +4,6 @@ import java.util.Optional; import java.util.Set; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -12,12 +11,13 @@ import de.tum.in.www1.artemis.domain.iris.settings.IrisExerciseSettings; import de.tum.in.www1.artemis.domain.iris.settings.IrisGlobalSettings; import de.tum.in.www1.artemis.domain.iris.settings.IrisSettings; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** * Spring Data repository for the IrisSettings entity. */ -public interface IrisSettingsRepository extends JpaRepository { +public interface IrisSettingsRepository extends ArtemisJpaRepository { @Query(""" SELECT irisSettings @@ -55,8 +55,4 @@ default IrisGlobalSettings findGlobalSettingsElseThrow() { WHERE irisSettings.exercise.id = :exerciseId """) Optional findExerciseSettings(@Param("exerciseId") long exerciseId); - - default IrisSettings findByIdElseThrow(long existingSettingsId) { - return findById(existingSettingsId).orElseThrow(() -> new EntityNotFoundException("Iris Settings", existingSettingsId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSubSettingsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSubSettingsRepository.java index e8146c434dbb..ecbeccb34945 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSubSettingsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisSubSettingsRepository.java @@ -1,12 +1,11 @@ package de.tum.in.www1.artemis.repository.iris; -import org.springframework.data.jpa.repository.JpaRepository; - import de.tum.in.www1.artemis.domain.iris.settings.IrisSubSettings; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the IrisSubSettings entity. */ -public interface IrisSubSettingsRepository extends JpaRepository { +public interface IrisSubSettingsRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisTemplateRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisTemplateRepository.java index 09b46777f6bc..9cf3a0c9e943 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisTemplateRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/iris/IrisTemplateRepository.java @@ -1,12 +1,11 @@ package de.tum.in.www1.artemis.repository.iris; -import org.springframework.data.jpa.repository.JpaRepository; - import de.tum.in.www1.artemis.domain.iris.IrisTemplate; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the IrisTemplate entity. */ -public interface IrisTemplateRepository extends JpaRepository { +public interface IrisTemplateRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/AnswerPostRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/AnswerPostRepository.java index 506e58d2700c..40f8e23f371d 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/AnswerPostRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/AnswerPostRepository.java @@ -7,10 +7,10 @@ import jakarta.validation.constraints.NotNull; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.metis.AnswerPost; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -18,7 +18,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface AnswerPostRepository extends JpaRepository { +public interface AnswerPostRepository extends ArtemisJpaRepository { List findAnswerPostsByAuthorId(long authorId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationMessageRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationMessageRepository.java index 92e444acbc46..7598d6a6aa1a 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationMessageRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationMessageRepository.java @@ -22,13 +22,13 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.User; import de.tum.in.www1.artemis.domain.metis.Post; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.service.util.TimeLogUtil; import de.tum.in.www1.artemis.web.rest.dto.PostContextFilterDTO; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @@ -38,7 +38,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ConversationMessageRepository extends JpaRepository, CustomPostRepository { +public interface ConversationMessageRepository extends ArtemisJpaRepository, CustomPostRepository { Logger log = LoggerFactory.getLogger(ConversationMessageRepository.class); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationParticipantRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationParticipantRepository.java index f1d171d421ab..5870945762c7 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationParticipantRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/ConversationParticipantRepository.java @@ -7,7 +7,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -16,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.metis.ConversationParticipant; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -23,7 +23,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ConversationParticipantRepository extends JpaRepository { +public interface ConversationParticipantRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT conversationParticipant diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/PostRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/PostRepository.java index 6d5834c04119..a9322d30ba7a 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/PostRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/PostRepository.java @@ -5,7 +5,6 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -14,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.metis.Post; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -21,7 +21,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface PostRepository extends JpaRepository, JpaSpecificationExecutor { +public interface PostRepository extends ArtemisJpaRepository, JpaSpecificationExecutor { List findPostsByAuthorId(long authorId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/ReactionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/ReactionRepository.java index 95af5dba8008..dd79853c847e 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/ReactionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/ReactionRepository.java @@ -5,26 +5,21 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.metis.Reaction; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the Reaction entity. */ @Profile(PROFILE_CORE) @Repository -public interface ReactionRepository extends JpaRepository { +public interface ReactionRepository extends ArtemisJpaRepository { List findReactionsByPostId(Long postId); List findReactionsByUserId(long userId); List findReactionsByAnswerPostId(Long answerPostId); - - default Reaction findByIdElseThrow(Long reactionId) throws EntityNotFoundException { - return findById(reactionId).orElseThrow(() -> new EntityNotFoundException("Reaction", reactionId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ChannelRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ChannelRepository.java index 4a4b8ad90b9e..76266670d8e0 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ChannelRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ChannelRepository.java @@ -6,17 +6,16 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.metis.conversation.Channel; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface ChannelRepository extends JpaRepository { +public interface ChannelRepository extends ArtemisJpaRepository { @Query(""" SELECT DISTINCT channel @@ -88,8 +87,4 @@ public interface ChannelRepository extends JpaRepository { ORDER BY channel.name """) Set findChannelByCourseIdAndNameAndIdNot(@Param("courseId") Long courseId, @Param("name") String name, @Param("channelId") Long channelId); - - default Channel findByIdElseThrow(long channelId) { - return this.findById(channelId).orElseThrow(() -> new EntityNotFoundException("Channel", channelId)); - } } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationNotificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationNotificationRepository.java index 8ecf6d4ffbfe..0f0903215881 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationNotificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationNotificationRepository.java @@ -3,13 +3,13 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.notification.ConversationNotification; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface ConversationNotificationRepository extends JpaRepository { +public interface ConversationNotificationRepository extends ArtemisJpaRepository { } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationRepository.java index e19fbc7fae25..4e8ea4e9af38 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/ConversationRepository.java @@ -8,7 +8,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -18,11 +17,11 @@ import de.tum.in.www1.artemis.domain.metis.conversation.Conversation; import de.tum.in.www1.artemis.domain.metis.conversation.GeneralConversationInfo; import de.tum.in.www1.artemis.domain.metis.conversation.UserConversationInfo; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface ConversationRepository extends JpaRepository { +public interface ConversationRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying @@ -34,10 +33,6 @@ public interface ConversationRepository extends JpaRepository findWithParticipantsById(long conversationId); - default Conversation findByIdElseThrow(long conversationId) { - return this.findById(conversationId).orElseThrow(() -> new EntityNotFoundException("Conversation", conversationId)); - } - /** * Retrieves a list of user-related information for the provided conversations for the given user * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/GroupChatRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/GroupChatRepository.java index f5b3fbfe2be5..533657c8fea8 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/GroupChatRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/GroupChatRepository.java @@ -5,17 +5,16 @@ import java.util.List; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.metis.conversation.GroupChat; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface GroupChatRepository extends JpaRepository { +public interface GroupChatRepository extends ArtemisJpaRepository { /** * Find all group chats of a given user in a given course. @@ -40,9 +39,4 @@ public interface GroupChatRepository extends JpaRepository { List findGroupChatsOfUserWithParticipantsAndUserGroups(@Param("courseId") Long courseId, @Param("userId") Long userId); Integer countByCreatorIdAndCourseId(Long creatorId, Long courseId); - - default GroupChat findByIdElseThrow(long groupChatId) { - return this.findById(groupChatId).orElseThrow(() -> new EntityNotFoundException("GroupChat", groupChatId)); - } - } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/OneToOneChatRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/OneToOneChatRepository.java index 9ae24801ee09..b8be738bb7e5 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/OneToOneChatRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metis/conversation/OneToOneChatRepository.java @@ -6,17 +6,17 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.metis.conversation.OneToOneChat; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface OneToOneChatRepository extends JpaRepository { +public interface OneToOneChatRepository extends ArtemisJpaRepository { /** * Find all active one-to-one chats of a given user in a given course. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metrics/CompetencyMetricsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metrics/CompetencyMetricsRepository.java index d18539372caf..40afa75694af 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metrics/CompetencyMetricsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metrics/CompetencyMetricsRepository.java @@ -5,12 +5,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.competency.Competency; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.competency.CompetencyJolDTO; import de.tum.in.www1.artemis.web.rest.dto.metrics.CompetencyInformationDTO; import de.tum.in.www1.artemis.web.rest.dto.metrics.CompetencyProgressDTO; @@ -21,7 +21,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface CompetencyMetricsRepository extends JpaRepository { +public interface CompetencyMetricsRepository extends ArtemisJpaRepository { /** * Get the competency information for all competencies in a course. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metrics/ExerciseMetricsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metrics/ExerciseMetricsRepository.java index d8c2f638993a..4aad3df2422f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metrics/ExerciseMetricsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metrics/ExerciseMetricsRepository.java @@ -6,12 +6,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Exercise; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.metrics.ExerciseInformationDTO; import de.tum.in.www1.artemis.web.rest.dto.metrics.MapEntryLongLong; import de.tum.in.www1.artemis.web.rest.dto.metrics.ResourceTimestampDTO; @@ -22,7 +22,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface ExerciseMetricsRepository extends JpaRepository { +public interface ExerciseMetricsRepository extends ArtemisJpaRepository { /** * Get the exercise information for all exercises in a course. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/metrics/LectureUnitMetricsRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/metrics/LectureUnitMetricsRepository.java index 04da4e4e905e..c6a1960f2c1c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/metrics/LectureUnitMetricsRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/metrics/LectureUnitMetricsRepository.java @@ -5,12 +5,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.lecture.LectureUnit; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.dto.metrics.LectureUnitInformationDTO; /** @@ -18,7 +18,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface LectureUnitMetricsRepository extends JpaRepository { +public interface LectureUnitMetricsRepository extends ArtemisJpaRepository { /** * Get the lecture unit information for all lecture units in a course. diff --git a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismCaseRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismCaseRepository.java index f4e8faade5a1..6d9ab4ad7c1c 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismCaseRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismCaseRepository.java @@ -7,12 +7,12 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -20,7 +20,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface PlagiarismCaseRepository extends JpaRepository { +public interface PlagiarismCaseRepository extends ArtemisJpaRepository { @Query(""" SELECT plagiarismCase @@ -158,10 +158,6 @@ default PlagiarismCase findByIdWithPlagiarismSubmissionsAndPlagiarismDetectionCo return findByIdWithPlagiarismSubmissionsAndPlagiarismDetectionConfig(plagiarismCaseId).orElseThrow(() -> new EntityNotFoundException("PlagiarismCase", plagiarismCaseId)); } - default PlagiarismCase findByIdElseThrow(long plagiarismCaseId) { - return findById(plagiarismCaseId).orElseThrow(() -> new EntityNotFoundException("PlagiarismCase", plagiarismCaseId)); - } - /** * Count the number of plagiarism cases for a given exercise id excluding deleted users. * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismComparisonRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismComparisonRepository.java index cfd282822c06..b0e1cdd97667 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismComparisonRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismComparisonRepository.java @@ -8,7 +8,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -17,6 +16,7 @@ import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison; import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; /** @@ -24,7 +24,7 @@ */ @Profile(PROFILE_CORE) @Repository -public interface PlagiarismComparisonRepository extends JpaRepository, Long> { +public interface PlagiarismComparisonRepository extends ArtemisJpaRepository, Long> { @Query(""" SELECT DISTINCT comparison diff --git a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismResultRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismResultRepository.java index 2dcd557f0863..6b3bd6d1a7d3 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismResultRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismResultRepository.java @@ -9,19 +9,19 @@ import org.springframework.context.annotation.Profile; import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismResult; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the PlagiarismResult entity. */ @Profile(PROFILE_CORE) @Repository -public interface PlagiarismResultRepository extends JpaRepository, Long> { +public interface PlagiarismResultRepository extends ArtemisJpaRepository, Long> { @EntityGraph(type = LOAD, attributePaths = { "comparisons" }) Optional> findFirstByExerciseIdOrderByLastModifiedDateDesc(long exerciseId); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismSubmissionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismSubmissionRepository.java index b27c8cd3487f..2283ea37fb24 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismSubmissionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/plagiarism/PlagiarismSubmissionRepository.java @@ -3,7 +3,6 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -12,13 +11,14 @@ import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismCase; import de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data JPA repository for the PlagiarismCase entity. */ @Profile(PROFILE_CORE) @Repository -public interface PlagiarismSubmissionRepository extends JpaRepository, Long> { +public interface PlagiarismSubmissionRepository extends ArtemisJpaRepository, Long> { @Modifying @Transactional // ok because of modifying query diff --git a/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceEventRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceEventRepository.java index 04a8001278e7..8e4c57eca9d9 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceEventRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceEventRepository.java @@ -5,7 +5,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,13 +13,14 @@ import de.tum.in.www1.artemis.domain.science.ScienceEvent; import de.tum.in.www1.artemis.domain.science.ScienceEventType; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the ScienceEvent entity. */ @Profile(PROFILE_CORE) @Repository -public interface ScienceEventRepository extends JpaRepository { +public interface ScienceEventRepository extends ArtemisJpaRepository { Set findAllByType(ScienceEventType type); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceSettingRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceSettingRepository.java index 75f2c92576ac..64ac9491b631 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceSettingRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/science/ScienceSettingRepository.java @@ -5,17 +5,17 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.science.ScienceSetting; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; /** * Spring Data repository for the ScienceSetting entity. */ @Profile(PROFILE_CORE) @Repository -public interface ScienceSettingRepository extends JpaRepository { +public interface ScienceSettingRepository extends ArtemisJpaRepository { Set findAllByUserId(long userId); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupFreePeriodRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupFreePeriodRepository.java index 34794adc26e4..40dcc8d28b3f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupFreePeriodRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupFreePeriodRepository.java @@ -7,18 +7,17 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Course; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroupFreePeriod; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupFreePeriodRepository extends JpaRepository { +public interface TutorialGroupFreePeriodRepository extends ArtemisJpaRepository { @Query(""" SELECT period @@ -40,10 +39,6 @@ Set findOverlappingInSameCourse(@Param("course") Course Set findOverlappingInSameCourseExclusive(@Param("course") Course course, @Param("fromExclusive") ZonedDateTime fromExclusive, @Param("toExclusive") ZonedDateTime toExclusive); - default TutorialGroupFreePeriod findByIdElseThrow(Long tutorialGroupFreePeriodId) { - return findById(tutorialGroupFreePeriodId).orElseThrow(() -> new EntityNotFoundException("TutorialGroupFreePeriod", tutorialGroupFreePeriodId)); - } - /** * Finds the first overlapping tutorial group free period in the same course. * diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupNotificationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupNotificationRepository.java index 7f13eeec1e76..fec2fb055237 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupNotificationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupNotificationRepository.java @@ -3,16 +3,16 @@ import static de.tum.in.www1.artemis.config.Constants.PROFILE_CORE; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import de.tum.in.www1.artemis.domain.notification.TutorialGroupNotification; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupNotificationRepository extends JpaRepository { +public interface TutorialGroupNotificationRepository extends ArtemisJpaRepository { @Transactional // ok because of delete @Modifying diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRegistrationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRegistrationRepository.java index 31a833a7be13..2cfdc9117b6d 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRegistrationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRegistrationRepository.java @@ -8,7 +8,6 @@ import jakarta.validation.constraints.NotNull; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -18,10 +17,11 @@ import de.tum.in.www1.artemis.domain.enumeration.tutorialgroups.TutorialGroupRegistrationType; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroup; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroupRegistration; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupRegistrationRepository extends JpaRepository { +public interface TutorialGroupRegistrationRepository extends ArtemisJpaRepository { Optional findTutorialGroupRegistrationByTutorialGroupAndStudentAndType(TutorialGroup tutorialGroup, User student, TutorialGroupRegistrationType type); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java index 60b7724b69ee..2cc8e36c39ed 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupRepository.java @@ -8,7 +8,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -16,11 +15,12 @@ import de.tum.in.www1.artemis.domain.Course; import de.tum.in.www1.artemis.domain.metis.conversation.Channel; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroup; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupRepository extends JpaRepository { +public interface TutorialGroupRepository extends ArtemisJpaRepository { @Query(""" SELECT tutorialGroup @@ -150,10 +150,6 @@ default TutorialGroup findByIdWithTeachingAssistantAndCourseElseThrow(long tutor return this.findByIdWithTeachingAssistantAndCourse(tutorialGroupId).orElseThrow(() -> new EntityNotFoundException("TutorialGroup", tutorialGroupId)); } - default TutorialGroup findByIdElseThrow(long tutorialGroupId) { - return this.findById(tutorialGroupId).orElseThrow(() -> new EntityNotFoundException("TutorialGroup", tutorialGroupId)); - } - default TutorialGroup findByIdWithTeachingAssistantAndRegistrationsElseThrow(long tutorialGroupId) { return this.findByIdWithTeachingAssistantAndRegistrationsAndSessions(tutorialGroupId).orElseThrow(() -> new EntityNotFoundException("TutorialGroup", tutorialGroupId)); } diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupScheduleRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupScheduleRepository.java index 43f18d36c23f..f9d521ec903e 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupScheduleRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupScheduleRepository.java @@ -6,18 +6,18 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.Course; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroupSchedule; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupScheduleRepository extends JpaRepository { +public interface TutorialGroupScheduleRepository extends ArtemisJpaRepository { @Query(""" SELECT tutorialGroupSchedule diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupSessionRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupSessionRepository.java index 286709227821..1e0cb192f42f 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupSessionRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupSessionRepository.java @@ -7,7 +7,6 @@ import java.util.Set; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -19,11 +18,11 @@ import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroup; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroupSchedule; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroupSession; -import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupSessionRepository extends JpaRepository { +public interface TutorialGroupSessionRepository extends ArtemisJpaRepository { @Query(""" SELECT session @@ -80,10 +79,6 @@ Set findOverlappingIndividualSessionsInSameTutorialGroup(@ """) Set findAllBetween(@Param("course") Course course, @Param("start") ZonedDateTime start, @Param("end") ZonedDateTime end); - default TutorialGroupSession findByIdElseThrow(long tutorialGroupSessionId) { - return findById(tutorialGroupSessionId).orElseThrow(() -> new EntityNotFoundException("TutorialGroupSession", tutorialGroupSessionId)); - } - @Transactional // ok because of delete @Modifying void deleteByTutorialGroupCourse(Course course); diff --git a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupsConfigurationRepository.java b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupsConfigurationRepository.java index 0d596df1ae42..70ace08c3081 100644 --- a/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupsConfigurationRepository.java +++ b/src/main/java/de/tum/in/www1/artemis/repository/tutorialgroups/TutorialGroupsConfigurationRepository.java @@ -5,17 +5,17 @@ import java.util.Optional; import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import de.tum.in.www1.artemis.domain.tutorialgroups.TutorialGroupsConfiguration; +import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository; import de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException; @Profile(PROFILE_CORE) @Repository -public interface TutorialGroupsConfigurationRepository extends JpaRepository { +public interface TutorialGroupsConfigurationRepository extends ArtemisJpaRepository { @Query(""" SELECT t diff --git a/src/main/java/de/tum/in/www1/artemis/service/ComplaintResponseService.java b/src/main/java/de/tum/in/www1/artemis/service/ComplaintResponseService.java index be2dff9824b5..1662b60d27fc 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/ComplaintResponseService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/ComplaintResponseService.java @@ -205,7 +205,7 @@ private ComplaintResponse processComplaint(Long complaintResponseId, Boolean isA // TODO: make this retrieval redundant by proper fetching ComplaintResponse complaintResponseFromDatabase = complaintResponseRepository.findByIdElseThrow(complaintResponseId); // TODO: make this retrieval redundant by proper fetching - Complaint originalComplaint = complaintRepository.findByIdElseThrow(complaintResponseFromDatabase.getComplaint().getId()); + Complaint originalComplaint = complaintRepository.findWithEagerAssessorByIdElseThrow(complaintResponseFromDatabase.getComplaint().getId()); User user = this.userRepository.getUserWithGroupsAndAuthorities(); validateUserPermissionAndLockStatus(originalComplaint, complaintResponseFromDatabase, user); validateComplaintResponseEmpty(complaintResponseFromDatabase); diff --git a/src/main/java/de/tum/in/www1/artemis/web/rest/FileResource.java b/src/main/java/de/tum/in/www1/artemis/web/rest/FileResource.java index af2cca4cd32d..ad959b26096f 100644 --- a/src/main/java/de/tum/in/www1/artemis/web/rest/FileResource.java +++ b/src/main/java/de/tum/in/www1/artemis/web/rest/FileResource.java @@ -241,7 +241,7 @@ public ResponseEntity getDragAndDropBackgroundFile(@PathVariable Long qu @EnforceAtLeastStudent public ResponseEntity getDragItemFile(@PathVariable Long dragItemId) { log.debug("REST request to get file for drag item : {}", dragItemId); - DragItem dragItem = dragItemRepository.findByIdElseThrow(dragItemId); + DragItem dragItem = dragItemRepository.findWithEagerQuestionByIdElseThrow(dragItemId); Course course = dragItem.getQuestion().getExercise().getCourseViaExerciseGroupOrCourseMember(); authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null); if (dragItem.getPictureFilePath() == null) {