/
ProgrammingExerciseStudentParticipationRepository.java
58 lines (44 loc) · 3.46 KB
/
ProgrammingExerciseStudentParticipationRepository.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package de.tum.in.www1.artemis.repository;
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 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.participation.ProgrammingExerciseStudentParticipation;
/**
* Spring Data JPA repository for the Participation entity.
*/
@SuppressWarnings("unused")
@Repository
public interface ProgrammingExerciseStudentParticipationRepository extends JpaRepository<ProgrammingExerciseStudentParticipation, Long> {
@Query("select p from ProgrammingExerciseStudentParticipation p left join fetch p.results pr left join fetch pr.feedbacks left join fetch pr.submission "
+ "where p.id = :participationId and (pr.id = (select max(prr.id) from p.results prr where prr.assessmentType = 'AUTOMATIC' or (prr.completionDate IS NOT NULL and (p.exercise.assessmentDueDate IS NULL OR p.exercise.assessmentDueDate < :#{#dateTime}))) or pr.id IS NULL)")
Optional<ProgrammingExerciseStudentParticipation> findByIdWithLatestResultAndFeedbacksAndRelatedSubmissions(@Param("participationId") Long participationId,
@Param("dateTime") ZonedDateTime dateTime);
@Query("select p from ProgrammingExerciseStudentParticipation p left join fetch p.results pr left join fetch pr.feedbacks left join fetch pr.submission left join fetch pr.assessor where p.id = :participationId")
Optional<ProgrammingExerciseStudentParticipation> findByIdWithResultsAndFeedbacksAndRelatedSubmissionsAndAssessor(@Param("participationId") Long participationId);
@EntityGraph(type = LOAD, attributePaths = { "results", "exercise" })
List<ProgrammingExerciseStudentParticipation> findByBuildPlanId(String buildPlanId);
@Query("select distinct p from ProgrammingExerciseStudentParticipation p left join fetch p.results where p.buildPlanId is not null and (p.student is not null or p.team is not null)")
List<ProgrammingExerciseStudentParticipation> findAllWithBuildPlanId();
Optional<ProgrammingExerciseStudentParticipation> findByExerciseIdAndStudentLogin(Long exerciseId, String username);
Optional<ProgrammingExerciseStudentParticipation> findByExerciseIdAndTeamId(Long exerciseId, Long teamId);
List<ProgrammingExerciseStudentParticipation> findByExerciseId(Long exerciseId);
/**
* Will return the participations matching the provided participation ids, but only if they belong to the given exercise.
*
* @param exerciseId is used as a filter for the found participations.
* @param participationIds the participations to retrieve.
* @return filtered list of participations.
*/
@Query("select participation from ProgrammingExerciseStudentParticipation participation where participation.exercise.id = :#{#exerciseId} and participation.id in :#{#participationIds}")
List<ProgrammingExerciseStudentParticipation> findByExerciseIdAndParticipationIds(@Param("exerciseId") Long exerciseId,
@Param("participationIds") Collection<Long> participationIds);
@EntityGraph(type = LOAD, attributePaths = "student")
Optional<ProgrammingExerciseStudentParticipation> findWithStudentById(Long participationId);
}