Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive learning: Add option to import exercises and lecture units when importing competencies #9205

Merged
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
c8ef79a
Implement feature
JohannesStoehr Aug 11, 2024
07e3972
Fix existing tests
JohannesStoehr Aug 12, 2024
a4ce649
Fix LearningPathIntegrationTest
JohannesStoehr Aug 13, 2024
4734e50
add custom import course competencies modal
JohannesWt Aug 15, 2024
842d08f
return results from modal and import all course competencies
JohannesWt Aug 18, 2024
04a927d
move create CoruseCompetencyRelations to course-competency-api.servic…
JohannesWt Aug 18, 2024
8a18bac
remove course-competency-service and switch to promise based course-c…
JohannesWt Aug 18, 2024
6ae3437
add course-competency-api.service tests
JohannesWt Aug 18, 2024
1175863
add import-course-competencies-settings.component.spec.ts tests
JohannesWt Aug 19, 2024
45320b4
add aria label and test
JohannesWt Aug 19, 2024
8b48e8c
add tests for import-list.component.html
JohannesWt Aug 21, 2024
39cc1e8
add tests for import-all-course-competencies-modal.component.ts
JohannesWt Aug 21, 2024
0c004dc
fix checkbox click
JohannesWt Aug 21, 2024
3d8e409
fix reference date input
JohannesWt Aug 21, 2024
4d567c7
move debounce to base-api-http.service.ts to make it more generic
JohannesWt Aug 21, 2024
355e6b9
reduce the use of effects
JohannesWt Aug 25, 2024
5a0bd80
use untracked for initial data loading
JohannesWt Aug 25, 2024
8c2f12e
Merge branch 'refs/heads/develop' into feature/adaptive-learning/impo…
JohannesStoehr Aug 25, 2024
d9f70ea
Fix most of server stuff
JohannesStoehr Aug 26, 2024
39336d7
fix some client tests
JohannesWt Aug 26, 2024
a37ed03
fix last client test
JohannesWt Aug 26, 2024
00a1c89
Fix more server stuff
JohannesStoehr Aug 26, 2024
28dd9dc
Merge remote-tracking branch 'origin/feature/adaptive-learning/import…
JohannesStoehr Aug 26, 2024
e8e5fa0
fix source course Id in test
JohannesWt Aug 26, 2024
a474d1e
fix source course Id in test v2
JohannesWt Aug 26, 2024
72cced3
add translations
JohannesWt Aug 26, 2024
64795ed
add translation to import-course-competencies-settings.component.spec.ts
JohannesWt Aug 26, 2024
ef1754c
rename import-list to import-table.component.ts
JohannesWt Aug 27, 2024
175f66b
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Aug 27, 2024
1e4db66
Fix most server stuff
JohannesStoehr Aug 27, 2024
6a0fe9f
Fix even more server stuff
JohannesStoehr Aug 27, 2024
c585cfe
Fix remaining server stuff
JohannesStoehr Aug 28, 2024
01264c0
Improve smaller stuff
JohannesStoehr Aug 28, 2024
c35d9dd
Fix server tests
JohannesStoehr Aug 28, 2024
348348d
Fix lecture unit linking
JohannesStoehr Aug 29, 2024
69a83ff
fix not displayed relations
JohannesWt Aug 29, 2024
3b4dafc
Fix Java Doc
JohannesStoehr Aug 29, 2024
e616b55
Merge remote-tracking branch 'origin/feature/adaptive-learning/import…
JohannesStoehr Aug 29, 2024
d664518
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Aug 29, 2024
f6908ad
Review
JohannesStoehr Aug 30, 2024
16b5990
Catch individual exceptions
JohannesStoehr Aug 30, 2024
d1a591b
first round of client MAGA (make Artemis great again) feedback
JohannesWt Aug 30, 2024
25aed02
Add JavaDoc explaining potential NonUniqueResultException
JohannesStoehr Aug 30, 2024
44685ef
Merge branch 'refs/heads/develop' into feature/adaptive-learning/impo…
JohannesStoehr Aug 31, 2024
7f1b4c0
Remove unnecessary comments
JohannesStoehr Aug 31, 2024
605c734
Improve no unique results handling
JohannesStoehr Sep 2, 2024
3d79644
add z-index comment
JohannesWt Sep 2, 2024
ba899f9
add variable for column
JohannesWt Sep 2, 2024
6fc35e9
Add methods
JohannesStoehr Sep 2, 2024
6a9b4f8
fix import prerequisites and competencies
JohannesWt Sep 3, 2024
3d9864e
simplify base-http-service and remove unused imports
JohannesWt Sep 11, 2024
e191b95
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesWt Sep 11, 2024
8957296
add throws annotation to base http service
JohannesWt Sep 11, 2024
71d6892
remove test as this should be handled by component
JohannesWt Sep 11, 2024
3ff0634
add more client tests
JohannesWt Sep 11, 2024
d849f89
add client tests for columns
JohannesWt Sep 11, 2024
19b4a5e
add client tests for branch coverage
JohannesWt Sep 11, 2024
7d224bc
add test for learning-path-navigation.service.spec.ts
JohannesWt Sep 11, 2024
16827a2
add tests for judgement-of-learning-rating-component.spec.ts
JohannesWt Sep 12, 2024
5fcde9e
Merge
JohannesStoehr Aug 11, 2024
03e595e
Fix existing tests
JohannesStoehr Aug 12, 2024
9ff4ef9
Fix LearningPathIntegrationTest
JohannesStoehr Aug 13, 2024
ec59035
add custom import course competencies modal
JohannesWt Aug 15, 2024
171cb77
return results from modal and import all course competencies
JohannesWt Aug 18, 2024
6153ba1
move create CoruseCompetencyRelations to course-competency-api.servic…
JohannesWt Aug 18, 2024
7f4a55f
remove course-competency-service and switch to promise based course-c…
JohannesWt Aug 18, 2024
b81fd04
add course-competency-api.service tests
JohannesWt Aug 18, 2024
2e40209
add import-course-competencies-settings.component.spec.ts tests
JohannesWt Aug 19, 2024
3073440
add aria label and test
JohannesWt Aug 19, 2024
910e63a
add tests for import-list.component.html
JohannesWt Aug 21, 2024
6b69fe5
add tests for import-all-course-competencies-modal.component.ts
JohannesWt Aug 21, 2024
48d3a1e
fix checkbox click
JohannesWt Aug 21, 2024
3bb1e21
fix reference date input
JohannesWt Aug 21, 2024
810ef29
move debounce to base-api-http.service.ts to make it more generic
JohannesWt Aug 21, 2024
82cfee1
reduce the use of effects
JohannesWt Aug 25, 2024
9ef6de9
use untracked for initial data loading
JohannesWt Aug 25, 2024
8cbf8e4
Fix most of server stuff
JohannesStoehr Aug 26, 2024
df147cc
Fix more server stuff
JohannesStoehr Aug 26, 2024
e4693ca
fix some client tests
JohannesWt Aug 26, 2024
5418b0a
fix last client test
JohannesWt Aug 26, 2024
37ee7c8
fix source course Id in test
JohannesWt Aug 26, 2024
a68932c
fix source course Id in test v2
JohannesWt Aug 26, 2024
6eb747f
add translations
JohannesWt Aug 26, 2024
3fa90b0
add translation to import-course-competencies-settings.component.spec.ts
JohannesWt Aug 26, 2024
c666b87
rename import-list to import-table.component.ts
JohannesWt Aug 27, 2024
9103fb5
Fix most server stuff
JohannesStoehr Aug 27, 2024
6a9332e
Fix even more server stuff
JohannesStoehr Aug 27, 2024
e29fe94
Fix remaining server stuff
JohannesStoehr Aug 28, 2024
40556f7
Improve smaller stuff
JohannesStoehr Aug 28, 2024
7450760
Fix server tests
JohannesStoehr Aug 28, 2024
073c6e2
Fix lecture unit linking
JohannesStoehr Aug 29, 2024
57ab38f
Fix Java Doc
JohannesStoehr Aug 29, 2024
e889fdf
fix not displayed relations
JohannesWt Aug 29, 2024
9a5a5e1
Review
JohannesStoehr Aug 30, 2024
1936f58
Catch individual exceptions
JohannesStoehr Aug 30, 2024
8cd1876
first round of client MAGA (make Artemis great again) feedback
JohannesWt Aug 30, 2024
3504c27
Add JavaDoc explaining potential NonUniqueResultException
JohannesStoehr Aug 30, 2024
6812b59
Remove unnecessary comments
JohannesStoehr Aug 31, 2024
b9505e0
Improve no unique results handling
JohannesStoehr Sep 2, 2024
2e1be85
add z-index comment
JohannesWt Sep 2, 2024
16579c7
add variable for column
JohannesWt Sep 2, 2024
cd19f08
Add methods
JohannesStoehr Sep 2, 2024
d0d8bac
fix import prerequisites and competencies
JohannesWt Sep 3, 2024
294bb13
simplify base-http-service and remove unused imports
JohannesWt Sep 11, 2024
b0e45c0
add throws annotation to base http service
JohannesWt Sep 11, 2024
7658746
remove test as this should be handled by component
JohannesWt Sep 11, 2024
4a7b24a
add more client tests
JohannesWt Sep 11, 2024
d4272fd
add client tests for columns
JohannesWt Sep 11, 2024
c30a7cd
add client tests for branch coverage
JohannesWt Sep 11, 2024
e6ba738
add test for learning-path-navigation.service.spec.ts
JohannesWt Sep 11, 2024
ade935a
add tests for judgement-of-learning-rating-component.spec.ts
JohannesWt Sep 12, 2024
2015ac9
Fix merge
JohannesStoehr Sep 14, 2024
9d45d60
Merge remote-tracking branch 'origin/feature/adaptive-learning/import…
JohannesStoehr Sep 14, 2024
2aac90a
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Sep 16, 2024
59e8b31
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Sep 19, 2024
c651344
Improve Testcoverage
JohannesStoehr Sep 20, 2024
cd4ec54
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Sep 20, 2024
7b25282
Fix test reset
JohannesStoehr Sep 20, 2024
753827c
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Sep 20, 2024
12496fb
Fix quiz start time and programming test
JohannesStoehr Sep 21, 2024
5e29e4e
Merge branch 'refs/heads/develop' into feature/adaptive-learning/impo…
JohannesStoehr Sep 30, 2024
92a1f3e
Merge
JohannesStoehr Sep 30, 2024
eeb9063
Merge branch 'develop' into feature/adaptive-learning/import-exercise…
JohannesStoehr Oct 3, 2024
a29c52c
Merge
JohannesStoehr Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public DragItem getSelectedDragItemForDropLocation(DropLocation dropLocation) {
* @param question the changed question with the changed DragItems and DropLocations
*/
private void checkAndDeleteMappings(DragAndDropQuestion question) {

if (question != null) {
// Check if a dragItem or dropLocation was deleted and delete reference to it in mappings
Set<DragAndDropMapping> selectedMappingsToDelete = new HashSet<>();
Expand All @@ -98,7 +97,6 @@ private void checkAndDeleteMappings(DragAndDropQuestion question) {
*/
@Override
public void checkAndDeleteReferences(QuizExercise quizExercise) {

// Delete all references to question, dropLocations and dragItem if the question was deleted
if (!quizExercise.getQuizQuestions().contains(getQuizQuestion())) {
setQuizQuestion(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public void setInvalid(Boolean invalid) {
this.invalid = invalid;
}

public void setMappings(Set<DragAndDropMapping> mappings) {
this.mappings = mappings;
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

/**
* This method is called after the entity is saved for the first time. We replace the placeholder in the pictureFilePath with the id of the entity because we don't know it
* before creation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public void setInvalid(Boolean invalid) {
this.invalid = invalid;
}

public void setMappings(Set<DragAndDropMapping> mappings) {
this.mappings = mappings;
}

/**
* check if the DropLocation is solved correctly
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void setQuestion(ShortAnswerQuestion shortAnswerQuestion) {
this.question = shortAnswerQuestion;
}

public void setMappings(Set<ShortAnswerMapping> mappings) {
this.mappings = mappings;
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@Override
public String toString() {
return "ShortAnswerSolution{" + "id=" + getId() + ", text='" + getText() + "'" + ", invalid='" + isInvalid() + "'" + "}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void setQuestion(ShortAnswerQuestion shortAnswerQuestion) {
this.question = shortAnswerQuestion;
}

public void setMappings(Set<ShortAnswerMapping> shortAnswerMappings) {
this.mappings = shortAnswerMappings;
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@Override
public String toString() {
return "ShortAnswerSpot{" + "id=" + getId() + ", width=" + getWidth() + ", spotNr=" + getSpotNr() + ", invalid='" + isInvalid() + "'" + "}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.in.www1.artemis.exception;

/**
* Checked exception in case a query does not return a unique result, so calling methods must handle this case.
*/
public class NoUniqueQueryException extends Exception {
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved

public NoUniqueQueryException(String message) {
super(message);
}
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ public interface CompetencyRepository extends ArtemisJpaRepository<Competency, L
@Query("""
SELECT c
FROM Competency c
LEFT JOIN FETCH c.exercises
LEFT JOIN FETCH c.lectureUnits lu
LEFT JOIN FETCH lu.lecture l
LEFT JOIN FETCH l.attachments
WHERE c.course.id = :courseId
""")
Set<Competency> findAllForCourse(@Param("courseId") long courseId);
Set<Competency> findAllForCourseWithExercisesAndLectureUnitsAndLecturesAndAttachments(@Param("courseId") long courseId);
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@Query("""
SELECT c
Expand Down
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,44 @@ public interface CourseCompetencyRepository extends ArtemisJpaRepository<CourseC
""")
Set<CourseCompetency> findAllForCourse(@Param("courseId") long courseId);

@Query("""
SELECT c
FROM CourseCompetency c
LEFT JOIN FETCH c.exercises ex
LEFT JOIN FETCH c.lectureUnits lu
LEFT JOIN FETCH lu.lecture l
LEFT JOIN FETCH l.attachments
WHERE c.course.id = :courseId
""")
Set<CourseCompetency> findAllForCourseWithExercisesAndLectureUnitsAndLecturesAndAttachments(@Param("courseId") long courseId);

@Query("""
SELECT c
FROM CourseCompetency c
LEFT JOIN FETCH c.exercises ex
LEFT JOIN FETCH c.lectureUnits lu
LEFT JOIN FETCH lu.lecture l
LEFT JOIN FETCH l.lectureUnits
LEFT JOIN FETCH l.attachments
WHERE c.id = :id
""")
Optional<CourseCompetency> findByIdWithExercisesAndLectureUnitsAndLectures(@Param("id") long id);

default CourseCompetency findByIdWithExercisesAndLectureUnitsAndLecturesElseThrow(long id) {
return getValueElseThrow(findByIdWithExercisesAndLectureUnitsAndLectures(id), id);
}

@Query("""
SELECT c
FROM CourseCompetency c
LEFT JOIN FETCH c.exercises ex
LEFT JOIN FETCH c.lectureUnits lu
LEFT JOIN FETCH lu.lecture l
LEFT JOIN FETCH l.attachments
WHERE c.id IN :ids
""")
Set<CourseCompetency> findAllByIdWithExercisesAndLectureUnitsAndLecturesAndAttachments(@Param("ids") Set<Long> ids);

JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved
/**
* Fetches all information related to the calculation of the mastery for exercises in a competency.
* The complex grouping by is necessary for postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

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

import jakarta.validation.constraints.NotNull;

import org.hibernate.NonUniqueResultException;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
Expand All @@ -16,6 +18,7 @@
import org.springframework.stereotype.Repository;

import de.tum.in.www1.artemis.domain.FileUploadExercise;
import de.tum.in.www1.artemis.exception.NoUniqueQueryException;
import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository;

/**
Expand All @@ -38,8 +41,41 @@ public interface FileUploadExerciseRepository extends ArtemisJpaRepository<FileU
@EntityGraph(type = LOAD, attributePaths = { "teamAssignmentConfig", "categories", "competencies" })
Optional<FileUploadExercise> findWithEagerTeamAssignmentConfigAndCategoriesAndCompetenciesById(Long exerciseId);

@Query("""
SELECT f
FROM FileUploadExercise f
LEFT JOIN FETCH f.competencies
WHERE f.title = :title
AND f.course.id = :courseId
""")
Set<FileUploadExercise> findAllWithCompetenciesByTitleAndCourseId(@Param("title") String title, @Param("courseId") long courseId) throws NonUniqueResultException;
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

/**
* Finds a file upload exercise by its title and course id and throws a NoUniqueQueryException if multiple exercises are found.
*
* @param title the title of the exercise
* @param courseId the id of the course
* @return the exercise with the given title and course id
* @throws NoUniqueQueryException if multiple exercises are found with the same title
*/
default Optional<FileUploadExercise> findUniqueWithCompetenciesByTitleAndCourseId(String title, long courseId) throws NoUniqueQueryException {
Set<FileUploadExercise> allExercises = findAllWithCompetenciesByTitleAndCourseId(title, courseId);
if (allExercises.size() > 1) {
throw new NoUniqueQueryException("Found multiple exercises with title " + title + " in course with id " + courseId);
}
return allExercises.stream().findFirst();
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@NotNull
default FileUploadExercise findWithEagerCompetenciesByIdElseThrow(Long exerciseId) {
return getValueElseThrow(findWithEagerCompetenciesById(exerciseId), exerciseId);
}

@EntityGraph(type = LOAD, attributePaths = { "gradingCriteria" })
Optional<FileUploadExercise> findWithGradingCriteriaById(Long exerciseId);
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@NotNull
default FileUploadExercise findWithGradingCriteriaByIdElseThrow(Long exerciseId) {
return getValueElseThrow(findWithGradingCriteriaById(exerciseId), exerciseId);
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.stereotype.Repository;

import de.tum.in.www1.artemis.domain.Lecture;
import de.tum.in.www1.artemis.exception.NoUniqueQueryException;
import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository;
import de.tum.in.www1.artemis.web.rest.dto.CourseContentCount;

Expand Down Expand Up @@ -100,6 +101,30 @@ public interface LectureRepository extends ArtemisJpaRepository<Lecture, Long> {
""")
Optional<Lecture> findByIdWithLectureUnitsAndSlidesAndAttachments(@Param("lectureId") long lectureId);

@Query("""
SELECT lecture
FROM Lecture lecture
LEFT JOIN FETCH lecture.lectureUnits
WHERE lecture.title = :title AND lecture.course.id = :courseId
""")
Set<Lecture> findAllByTitleAndCourseIdWithLectureUnits(@Param("title") String title, @Param("courseId") long courseId);
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Finds a lecture by its title and course id and throws a NoUniqueQueryException if multiple lectures are found.
*
* @param title the title of the lecture
* @param courseId the id of the course
* @return the lecture with the given title and course id
* @throws NoUniqueQueryException if multiple lectures are found with the same title
*/
default Optional<Lecture> findUniqueByTitleAndCourseIdWithLectureUnitsElseThrow(String title, long courseId) throws NoUniqueQueryException {
Set<Lecture> allLectures = findAllByTitleAndCourseIdWithLectureUnits(title, courseId);
if (allLectures.size() > 1) {
throw new NoUniqueQueryException("Found multiple lectures with title " + title + " in course with id " + courseId);
}
return allLectures.stream().findFirst();
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings("PMD.MethodNamingConventions")
Page<Lecture> findByTitleIgnoreCaseContainingOrCourse_TitleIgnoreCaseContaining(String partialTitle, String partialCourseTitle, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import java.util.Set;

import org.hibernate.NonUniqueResultException;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down Expand Up @@ -61,6 +62,27 @@ public interface LectureUnitRepository extends ArtemisJpaRepository<LectureUnit,
""")
Optional<LectureUnit> findByIdWithCompletedUsers(@Param("lectureUnitId") long lectureUnitId);

/**
* Finds a lecture unit by name, lecture title and course id. Currently, name duplicates are allowed but this method throws an exception if multiple lecture units with the
* same name are found.
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved
*
* @param name the name of the lecture unit
* @param lectureTitle the title of the lecture containing the lecture unit
* @param courseId the id of the course containing the lecture
* @return the lecture unit with the given name, lecture title and course id
* @throws NonUniqueResultException if multiple lecture units with the same name in the same lecture are found
*/
@Query("""
SELECT lu
FROM LectureUnit lu
LEFT JOIN FETCH lu.competencies
WHERE lu.name = :name
AND lu.lecture.title = :lectureTitle
AND lu.lecture.course.id = :courseId
""")
Optional<LectureUnit> findByNameAndLectureTitleAndCourseIdWithCompetencies(@Param("name") String name, @Param("lectureTitle") String lectureTitle,
@Param("courseId") long courseId) throws NonUniqueResultException;

default LectureUnit findByIdWithCompletedUsersElseThrow(long lectureUnitId) {
return getValueElseThrow(findByIdWithCompletedUsers(lectureUnitId), lectureUnitId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import jakarta.validation.constraints.NotNull;

Expand All @@ -17,6 +18,7 @@
import org.springframework.stereotype.Repository;

import de.tum.in.www1.artemis.domain.modeling.ModelingExercise;
import de.tum.in.www1.artemis.exception.NoUniqueQueryException;
import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository;

/**
Expand Down Expand Up @@ -54,9 +56,10 @@ public interface ModelingExerciseRepository extends ArtemisJpaRepository<Modelin
LEFT JOIN FETCH results.assessor
LEFT JOIN FETCH modelingExercise.teamAssignmentConfig
LEFT JOIN FETCH modelingExercise.plagiarismDetectionConfig
LEFT JOIN FETCH modelingExercise.gradingCriteria
WHERE modelingExercise.id = :exerciseId
""")
Optional<ModelingExercise> findByIdWithExampleSubmissionsAndResultsAndPlagiarismDetectionConfig(@Param("exerciseId") Long exerciseId);
Optional<ModelingExercise> findByIdWithExampleSubmissionsAndResultsAndPlagiarismDetectionConfigAndGradingCriteria(@Param("exerciseId") Long exerciseId);
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get all modeling exercises that need to be scheduled: Those must satisfy one of the following requirements:
Expand Down Expand Up @@ -94,6 +97,31 @@ public interface ModelingExerciseRepository extends ArtemisJpaRepository<Modelin
@EntityGraph(type = LOAD, attributePaths = { "studentParticipations", "studentParticipations.submissions", "studentParticipations.submissions.results" })
Optional<ModelingExercise> findWithStudentParticipationsSubmissionsResultsById(Long exerciseId);

@Query("""
SELECT m
FROM ModelingExercise m
LEFT JOIN FETCH m.competencies
WHERE m.title = :title
AND m.course.id = :courseId
""")
Set<ModelingExercise> findAllWithCompetenciesByTitleAndCourseId(@Param("title") String title, @Param("courseId") long courseId);
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

/**
* Finds a modeling exercise by its title and course id and throws a NoUniqueQueryException if multiple exercises are found.
*
* @param title the title of the exercise
* @param courseId the id of the course
* @return the exercise with the given title and course id
* @throws NoUniqueQueryException if multiple exercises are found with the same title
*/
default Optional<ModelingExercise> findUniqueWithCompetenciesByTitleAndCourseId(String title, long courseId) throws NoUniqueQueryException {
Set<ModelingExercise> allExercises = findAllWithCompetenciesByTitleAndCourseId(title, courseId);
if (allExercises.size() > 1) {
throw new NoUniqueQueryException("Found multiple exercises with title " + title + " in course with id " + courseId);
}
return allExercises.stream().findFirst();
}
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@NotNull
default ModelingExercise findWithEagerExampleSubmissionsAndCompetenciesByIdElseThrow(long exerciseId) {
return getValueElseThrow(findWithEagerExampleSubmissionsAndCompetenciesById(exerciseId), exerciseId);
Expand All @@ -106,7 +134,7 @@ default ModelingExercise findWithEagerExampleSubmissionsAndCompetenciesAndPlagia

@NotNull
default ModelingExercise findByIdWithExampleSubmissionsAndResultsAndPlagiarismDetectionConfigElseThrow(long exerciseId) {
return getValueElseThrow(findByIdWithExampleSubmissionsAndResultsAndPlagiarismDetectionConfig(exerciseId), exerciseId);
return getValueElseThrow(findByIdWithExampleSubmissionsAndResultsAndPlagiarismDetectionConfigAndGradingCriteria(exerciseId), exerciseId);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ public interface PrerequisiteRepository extends ArtemisJpaRepository<Prerequisit
List<Prerequisite> findAllByCourseIdOrderById(long courseId);

@Query("""
SELECT c
FROM Prerequisite c
WHERE c.course.id = :courseId
SELECT p
FROM Prerequisite p
LEFT JOIN FETCH p.exercises
LEFT JOIN FETCH p.lectureUnits lu
LEFT JOIN FETCH lu.lecture l
LEFT JOIN FETCH l.attachments
WHERE p.course.id = :courseId
""")
Set<Prerequisite> findAllForCourse(@Param("courseId") long courseId);
Set<Prerequisite> findAllForCourseWithExercisesAndLectureUnitsAndLecturesAndAttachments(@Param("courseId") long courseId);
JohannesStoehr marked this conversation as resolved.
Show resolved Hide resolved

@Query("""
SELECT c
FROM Prerequisite c
LEFT JOIN FETCH c.lectureUnits lu
LEFT JOIN FETCH c.exercises
WHERE c.id = :competencyId
SELECT p
FROM Prerequisite p
LEFT JOIN FETCH p.lectureUnits lu
LEFT JOIN FETCH p.exercises
WHERE p.id = :competencyId
""")
Optional<Prerequisite> findByIdWithLectureUnitsAndExercises(@Param("competencyId") long competencyId);

@Query("""
SELECT c
FROM Prerequisite c
LEFT JOIN FETCH c.lectureUnits lu
WHERE c.id = :competencyId
SELECT p
FROM Prerequisite p
LEFT JOIN FETCH p.lectureUnits lu
WHERE p.id = :competencyId
""")
Optional<Prerequisite> findByIdWithLectureUnits(@Param("competencyId") long competencyId);

Expand Down
Loading
Loading