Skip to content

Commit

Permalink
Development: Ensure correct @repository annotation usage (#9610)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesStoehr authored Oct 27, 2024
1 parent efe7c16 commit 041d5c9
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package de.tum.cit.aet.artemis.assessment.repository;

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

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

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

import de.tum.cit.aet.artemis.assessment.domain.LongFeedbackText;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

@Profile(PROFILE_CORE)
@Repository
public interface LongFeedbackTextRepository extends ArtemisJpaRepository<LongFeedbackText, Long> {

@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package de.tum.cit.aet.artemis.atlas.repository;

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

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

import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.atlas.domain.LearningObject;
import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency;
Expand All @@ -21,6 +25,8 @@
/**
* Spring Data JPA repository for the {@link CourseCompetency} entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface CourseCompetencyRepository extends ArtemisJpaRepository<CourseCompetency, Long> {

@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package de.tum.cit.aet.artemis.atlas.repository;

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

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

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

import de.tum.cit.aet.artemis.atlas.domain.competency.Prerequisite;
import de.tum.cit.aet.artemis.core.domain.Course;
Expand All @@ -14,10 +18,10 @@
/**
* Spring Data JPA repository for the {@link Prerequisite} entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface PrerequisiteRepository extends ArtemisJpaRepository<Prerequisite, Long> {

List<Prerequisite> findAllByCourseIdOrderById(long courseId);

@Query("""
SELECT p
FROM Prerequisite p
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package de.tum.cit.aet.artemis.communication.repository;

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

import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.communication.domain.Post;

@Profile(PROFILE_CORE)
@Repository
public interface CustomPostRepository {

Page<Long> findPostIdsWithSpecification(Specification<Post> specification, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package de.tum.cit.aet.artemis.core.repository;

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

import java.util.List;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.domain.Authority;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

/**
* Spring Data JPA repository for the Authority entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface AuthorityRepository extends ArtemisJpaRepository<Authority, String> {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package de.tum.cit.aet.artemis.core.repository;

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

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.domain.MigrationChangelog;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

@Profile(PROFILE_CORE)
@Repository
public interface MigrationChangeRepository extends ArtemisJpaRepository<MigrationChangelog, String> {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.cit.aet.artemis.core.repository;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;
import static org.springframework.data.jpa.repository.EntityGraph.EntityGraphType.LOAD;

import java.time.Instant;
Expand All @@ -9,19 +10,23 @@

import jakarta.validation.constraints.NotNull;

import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.domain.PersistentAuditEvent;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

/**
* Spring Data JPA repository for the PersistentAuditEvent entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface PersistenceAuditEventRepository extends ArtemisJpaRepository<PersistentAuditEvent, Long> {

@EntityGraph(type = LOAD, attributePaths = { "data" })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package de.tum.cit.aet.artemis.iris.repository;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_IRIS;
import static org.springframework.data.jpa.repository.EntityGraph.EntityGraphType.LOAD;

import java.util.Collections;
import java.util.List;

import jakarta.validation.constraints.NotNull;

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.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.domain.DomainObject;
import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
Expand All @@ -21,6 +24,8 @@
* Repository interface for managing {@link IrisTextExerciseChatSession} entities.
* Provides custom queries for finding text exercise chat sessions based on different criteria.
*/
@Profile(PROFILE_IRIS)
@Repository
public interface IrisTextExerciseChatSessionRepository extends ArtemisJpaRepository<IrisTextExerciseChatSession, Long> {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package de.tum.cit.aet.artemis.programming.repository;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;
import static org.springframework.data.jpa.repository.EntityGraph.EntityGraphType.LOAD;

import java.util.Optional;

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

import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise;
import de.tum.cit.aet.artemis.programming.domain.build.BuildPlan;

@Profile(PROFILE_CORE)
@Repository
public interface BuildPlanRepository extends ArtemisJpaRepository<BuildPlan, Long> {

@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package de.tum.cit.aet.artemis.programming.repository.hestia;

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

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.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
Expand All @@ -15,6 +19,8 @@
/**
* Spring Data repository for the CodeHint entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface CodeHintRepository extends ArtemisJpaRepository<CodeHint, Long> {

Set<CodeHint> findByExerciseId(Long exerciseId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package de.tum.cit.aet.artemis.programming.repository.hestia;

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

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

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

import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
import de.tum.cit.aet.artemis.programming.domain.hestia.ExerciseHintActivation;

@Profile(PROFILE_CORE)
@Repository
public interface ExerciseHintActivationRepository extends ArtemisJpaRepository<ExerciseHintActivation, Long> {

@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package de.tum.cit.aet.artemis.programming.repository.hestia;

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

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.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
Expand All @@ -15,6 +19,8 @@
/**
* Spring Data repository for the ProgrammingExerciseSolutionEntry entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface ProgrammingExerciseSolutionEntryRepository extends ArtemisJpaRepository<ProgrammingExerciseSolutionEntry, Long> {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package de.tum.cit.aet.artemis.programming.repository.hestia;

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

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

import jakarta.validation.constraints.NotNull;

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

import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;
Expand All @@ -16,37 +20,10 @@
/**
* Spring Data repository for the ProgrammingExerciseTask entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface ProgrammingExerciseTaskRepository extends ArtemisJpaRepository<ProgrammingExerciseTask, Long> {

Set<ProgrammingExerciseTask> findByExerciseId(Long exerciseId);

/**
* Gets a task with its programming exercise, test cases and solution entries of the test cases
*
* @param entryId The id of the task
* @return The task with the given ID if found
* @throws EntityNotFoundException If no task with the given ID was found
*/
@NotNull
default ProgrammingExerciseTask findByIdWithTestCaseAndSolutionEntriesElseThrow(long entryId) throws EntityNotFoundException {
return getValueElseThrow(findByIdWithTestCaseAndSolutionEntries(entryId), entryId);
}

/**
* Gets a task with its programming exercise, test cases and solution entries of the test cases
*
* @param entryId The id of the task
* @return The task with the given ID
*/
@Query("""
SELECT t
FROM ProgrammingExerciseTask t
LEFT JOIN FETCH t.testCases tc
LEFT JOIN FETCH tc.solutionEntries
WHERE t.id = :entryId
""")
Optional<ProgrammingExerciseTask> findByIdWithTestCaseAndSolutionEntries(@Param("entryId") long entryId);

/**
* Gets all tasks with its test cases and solution entries of the test case for a programming exercise
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository;
import de.tum.cit.aet.artemis.atlas.repository.KnowledgeAreaRepository;
import de.tum.cit.aet.artemis.atlas.repository.PrerequisiteRepository;
import de.tum.cit.aet.artemis.atlas.repository.ScienceSettingRepository;
import de.tum.cit.aet.artemis.atlas.repository.SourceRepository;
import de.tum.cit.aet.artemis.atlas.repository.StandardizedCompetencyRepository;
import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyProgressService;
import de.tum.cit.aet.artemis.atlas.test_repository.CompetencyProgressTestRepository;
import de.tum.cit.aet.artemis.atlas.test_repository.LearningPathTestRepository;
import de.tum.cit.aet.artemis.atlas.test_repository.PrerequisiteTestRepository;
import de.tum.cit.aet.artemis.atlas.test_repository.ScienceEventTestRepository;
import de.tum.cit.aet.artemis.core.service.feature.FeatureToggleService;
import de.tum.cit.aet.artemis.core.util.PageableSearchUtilService;
Expand Down Expand Up @@ -74,7 +74,7 @@ public abstract class AbstractAtlasIntegrationTest extends AbstractSpringIntegra
protected ScienceEventTestRepository scienceEventRepository;

@Autowired
protected PrerequisiteRepository prerequisiteRepository;
protected PrerequisiteTestRepository prerequisiteRepository;

@Autowired
protected CompetencyJolRepository competencyJolRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.stereotype.Service;

import de.tum.cit.aet.artemis.atlas.domain.competency.Prerequisite;
import de.tum.cit.aet.artemis.atlas.repository.PrerequisiteRepository;
import de.tum.cit.aet.artemis.atlas.test_repository.PrerequisiteTestRepository;
import de.tum.cit.aet.artemis.core.domain.Course;

/**
Expand All @@ -17,7 +17,7 @@
public class PrerequisiteUtilService {

@Autowired
private PrerequisiteRepository prerequisiteRepository;
private PrerequisiteTestRepository prerequisiteRepository;

/**
* Creates and saves a Prerequisite competency for the given Course.
Expand Down
Loading

0 comments on commit 041d5c9

Please sign in to comment.