Skip to content

Commit

Permalink
Development: Improve method name (#9097)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender authored Jul 21, 2024
1 parent d96f63c commit 2f64afc
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/main/java/de/tum/in/www1/artemis/domain/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public Course getCourseViaExerciseGroupOrCourseMember() {
* @return exam, to which the exercise belongs
*/
@JsonIgnore
public Exam getExamViaExerciseGroupOrCourseMember() {
public Exam getExam() {
if (isExamExercise()) {
return this.getExerciseGroup().getExam();
}
Expand Down Expand Up @@ -953,8 +953,7 @@ private Set<GradingInstruction> copyGradingInstruction(GradingCriterion original
*/
@JsonIgnore
public boolean isExampleSolutionPublished() {
ZonedDateTime exampleSolutionPublicationDate = this.isExamExercise() ? this.getExamViaExerciseGroupOrCourseMember().getExampleSolutionPublicationDate()
: this.getExampleSolutionPublicationDate();
ZonedDateTime exampleSolutionPublicationDate = this.isExamExercise() ? this.getExam().getExampleSolutionPublicationDate() : this.getExampleSolutionPublicationDate();
return exampleSolutionPublicationDate != null && ZonedDateTime.now().isAfter(exampleSolutionPublicationDate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static NotificationTarget createExamExerciseTargetWithExerciseUpdate(Exer
NotificationTarget target = new NotificationTarget(EXAMS_TEXT, exercise.getCourseViaExerciseGroupOrCourseMember().getId(), COURSES_TEXT);
target.setProblemStatement(exercise.getProblemStatement());
target.setExerciseId(exercise.getId());
target.setExamId(exercise.getExamViaExerciseGroupOrCourseMember().getId());
target.setExamId(exercise.getExam().getId());
return target;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ public boolean isAllowedToGetExamResult(Exercise exercise, StudentParticipation
if (this.isAtLeastTeachingAssistantInCourse(exercise.getCourseViaExerciseGroupOrCourseMember(), user) || exercise.isCourseExercise()) {
return true;
}
Exam exam = exercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = exercise.getExam();
if (!examDateService.isExerciseWorkingPeriodOver(exercise, studentParticipation)) {
// students can always see their results during the exam.
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public boolean isAfterDueDate(ParticipationInterface participation) {
final Exercise exercise = participation.getExercise();
if (exercise.isExamExercise()) {
if (participation instanceof StudentParticipation studentParticipation) {
return examDateService.isIndividualExerciseWorkingPeriodOver(exercise.getExamViaExerciseGroupOrCourseMember(), studentParticipation);
return examDateService.isIndividualExerciseWorkingPeriodOver(exercise.getExam(), studentParticipation);
}
else {
return examDateService.isExamWithGracePeriodOver(exercise.getExamViaExerciseGroupOrCourseMember());
return examDateService.isExamWithGracePeriodOver(exercise.getExam());
}
}
else {
Expand Down Expand Up @@ -168,7 +168,7 @@ public static Optional<ZonedDateTime> getDueDate(ParticipationInterface particip
*/
public static boolean isAfterAssessmentDueDate(Exercise exercise) {
if (exercise.isExamExercise()) {
return exercise.getExamViaExerciseGroupOrCourseMember().resultsPublished();
return exercise.getExam().resultsPublished();
}
return exercise.getAssessmentDueDate() == null || ZonedDateTime.now().isAfter(exercise.getAssessmentDueDate());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean isExerciseWorkingPeriodOver(Exercise exercise, StudentParticipati
if (!exercise.isExamExercise()) {
throw new IllegalArgumentException("This function should only be used for exam exercises");
}
Exam exam = exercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = exercise.getExam();
if (exam.isTestExam()) {
return isIndividualExerciseWorkingPeriodOver(exam, studentParticipation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void createAndSendWorkingTimeUpdateEvent(StudentExam studentExam, int new
*/
@Async
public void createAndSendProblemStatementUpdateEvent(Exercise exercise, String message, User instructor) {
Exam exam = exercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = exercise.getExam();
studentExamRepository.findAllWithExercisesByExamId(exam.getId()).stream().filter(studentExam -> studentExam.getExercises().contains(exercise))
.forEach(studentExam -> this.createAndSendProblemStatementUpdateEvent(studentExam, exercise, message, instructor));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void createNonProgrammingExerciseExport(Exercise exercise, Path courseDir
private void createSubmissionsResultsExport(Exercise exercise, Path exerciseDir, User user) throws IOException {
// quizzes do not have an assessment due date, so we need to check if they have ended according to their due date
boolean isInstructor = authCheckService.isAtLeastInstructorForExercise(exercise, user);
boolean includeResults = (exercise.isExamExercise() && exercise.getExamViaExerciseGroupOrCourseMember().resultsPublished())
boolean includeResults = (exercise.isExamExercise() && exercise.getExam().resultsPublished())
|| (exercise.isCourseExercise() && ExerciseDateService.isAfterAssessmentDueDate(exercise) && !(exercise instanceof QuizExercise))
|| (exercise.isCourseExercise() && exercise instanceof QuizExercise quizExercise && quizExercise.isQuizEnded()) || isInstructor;
for (var participation : exercise.getStudentParticipations()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public ResponseEntity<StudentParticipation> getDataForTextEditor(@PathVariable L

textExercise.filterSensitiveInformation();
if (textExercise.isExamExercise()) {
textExercise.getExamViaExerciseGroupOrCourseMember().setCourse(null);
textExercise.getExam().setCourse(null);
}

return ResponseEntity.ok(participation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void broadcastNewResultToParticipants(StudentParticipation studentPartic
isWorkingPeriodOver = exerciseDateService.isAfterLatestDueDate(exercise);
}
// Don't send students results after the exam ended
boolean isAfterExamEnd = isWorkingPeriodOver && exercise.isExamExercise() && !exercise.getExamViaExerciseGroupOrCourseMember().isTestExam();
boolean isAfterExamEnd = isWorkingPeriodOver && exercise.isExamExercise() && !exercise.getExam().isTestExam();
// If the assessment due date is not over yet, do not send manual feedback to students!
boolean isAutomaticAssessmentOrDueDateOver = AssessmentType.AUTOMATIC == result.getAssessmentType() || exercise.getAssessmentDueDate() == null
|| ZonedDateTime.now().isAfter(exercise.getAssessmentDueDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void submitComplaintResponse_examExercise() throws Exception {
TextExercise examExercise = textExerciseUtilService.addCourseExamExerciseGroupWithOneTextExercise();
Course examCourse = examExercise.getCourseViaExerciseGroupOrCourseMember();

Exam exam = examExercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = examExercise.getExam();
exam.setExamStudentReviewStart(ZonedDateTime.now().minusHours(1));
exam.setExamStudentReviewEnd(ZonedDateTime.now().plusHours(1));
examRepository.save(exam);
Expand Down Expand Up @@ -947,12 +947,12 @@ void submitComplaintForExam_courseComplaintsDisabled_exceededTextLimit() throws
}

private Submission createComplaintForExamExercise(TextExercise examExercise, String complaintText, HttpStatus expectedStatus) throws Exception {
examExercise.getExamViaExerciseGroupOrCourseMember().setExamStudentReviewStart(ZonedDateTime.now().minusHours(1));
examExercise.getExamViaExerciseGroupOrCourseMember().setExamStudentReviewEnd(ZonedDateTime.now().plusHours(1));
examRepository.save(examExercise.getExamViaExerciseGroupOrCourseMember());
examExercise.getExam().setExamStudentReviewStart(ZonedDateTime.now().minusHours(1));
examExercise.getExam().setExamStudentReviewEnd(ZonedDateTime.now().plusHours(1));
examRepository.save(examExercise.getExam());
TextSubmission textSubmission = ParticipationFactory.generateTextSubmission("This is my submission", Language.ENGLISH, true);
textSubmission = textExerciseUtilService.saveTextSubmissionWithResultAndAssessor(examExercise, textSubmission, TEST_PREFIX + "student1", TEST_PREFIX + "tutor1");
var examId = examExercise.getExamViaExerciseGroupOrCourseMember().getId();
var examId = examExercise.getExam().getId();
final var examExerciseComplaint = new ComplaintRequestDTO(textSubmission.getLatestResult().getId(), complaintText, ComplaintType.COMPLAINT, Optional.of(examId));

String url = "/api/complaints";
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/de/tum/in/www1/artemis/domain/ExerciseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,20 @@ void filterForCourseDashboard_submissionWithMixedResults() {
}

@Test
void getExamViaExerciseGroupOrCourseMember_withExamExercise() {
void getExam_withExamExercise() {
Exam exam = ExamFactory.generateExam(null);
ExerciseGroup exerciseGroup = ExamFactory.generateExerciseGroup(true, exam);
Exercise examExercise = TextExerciseFactory.generateTextExerciseForExam(exerciseGroup);

Exam result = examExercise.getExamViaExerciseGroupOrCourseMember();
Exam result = examExercise.getExam();
assertThat(result).isEqualTo(exam);
}

@Test
void getExamViaExerciseGroupOrCourseMember_withoutExamExercise() {
void getExam_withoutExamExercise() {
Exercise examExercise = TextExerciseFactory.generateTextExerciseForExam(null);

Exam result = examExercise.getExamViaExerciseGroupOrCourseMember();
Exam result = examExercise.getExam();
assertThat(result).isNull();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private ProgrammingExercise newExamProgrammingExercise() {

@Override
ProgrammingExercise changeRelevantExerciseEndDate(ProgrammingExercise programmingExercise, ZonedDateTime endDate) {
Exam exam = programmingExercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = programmingExercise.getExam();
// Only change the exam end date, as exam exercises don't have individual dates (all dates are null)
exam.setEndDate(endDate);
super.examRepository.save(exam);
Expand Down Expand Up @@ -1493,7 +1493,7 @@ private void updateAndSaveAutomaticResult(Result result, boolean test1Passes, bo
}

private void createStudentExam(ProgrammingExercise exercise, String student) {
var exam = exercise.getExamViaExerciseGroupOrCourseMember();
var exam = exercise.getExam();
examUtilService.addStudentExamWithUser(exam, student);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void shouldCancelAllTasksIfSchedulingNoLongerNeeded() throws Exception {
@WithMockUser(username = "admin", roles = "ADMIN")
void testStudentExamIndividualWorkingTimeChangeDuringConduction() {
ProgrammingExercise examExercise = programmingExerciseUtilService.addCourseExamExerciseGroupWithOneProgrammingExercise();
Exam exam = examExercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = examExercise.getExam();
exam.setStartDate(ZonedDateTime.now().minusMinutes(1));
exam = examRepository.saveAndFlush(exam);
User user = userUtilService.getUserByLogin(TEST_PREFIX + "student1");
Expand All @@ -638,7 +638,7 @@ void testStudentExamIndividualWorkingTimeChangeDuringConduction() {
@WithMockUser(username = "admin", roles = "ADMIN")
void testRescheduleExamDuringConduction() {
ProgrammingExercise examExercise = programmingExerciseUtilService.addCourseExamExerciseGroupWithOneProgrammingExercise();
Exam exam = examExercise.getExamViaExerciseGroupOrCourseMember();
Exam exam = examExercise.getExam();
exam.setStartDate(ZonedDateTime.now().minusMinutes(1));
exam = examRepository.saveAndFlush(exam);
User user = userUtilService.getUserByLogin(TEST_PREFIX + "student1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void updateProblemStatement_courseExercise() throws Exception {
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void updateProblemStatement_examExercise() throws Exception {
var programmingExercise = programmingExerciseUtilService.addCourseExamExerciseGroupWithOneProgrammingExercise();
var exam = programmingExercise.getExamViaExerciseGroupOrCourseMember();
var exam = programmingExercise.getExam();
StudentExam studentExam = examUtilService.addStudentExam(exam);
examUtilService.addExerciseToStudentExam(studentExam, programmingExercise);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ void createProgrammingExerciseForExam_validExercise_created() throws Exception {

examExercise.setId(generatedExercise.getId());
assertThat(examExercise).isEqualTo(generatedExercise);
final Exam loadedExam = examRepository.findWithExerciseGroupsAndExercisesById(examExercise.getExamViaExerciseGroupOrCourseMember().getId()).orElseThrow();
final Exam loadedExam = examRepository.findWithExerciseGroupsAndExercisesById(examExercise.getExam().getId()).orElseThrow();
assertThat(loadedExam.getNumberOfExercisesInExam()).isEqualTo(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void testFilterFeedbacksForClientAreSortedWithManualFirst() {
@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "STUDENT")
void testFilterFeedbacksForClientAsStudent_shouldFilterInExamsBeforePublish() {
Exam exam = examStudentParticipation.getExercise().getExamViaExerciseGroupOrCourseMember();
Exam exam = examStudentParticipation.getExercise().getExam();
exam.setPublishResultsDate(ZonedDateTime.now().plusDays(2));
examRepository.save(exam);
Result result = participationUtilService.addResultToParticipation(null, null, examStudentParticipation);
Expand All @@ -129,7 +129,7 @@ void testFilterFeedbacksForClientAsStudent_shouldFilterInExamsBeforePublish() {
@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "STUDENT")
void testFilterFeedbacksForClientAsStudent_shouldFilterInExamsAfterPublish() {
Exam exam = examStudentParticipation.getExercise().getExamViaExerciseGroupOrCourseMember();
Exam exam = examStudentParticipation.getExercise().getExam();
exam.setPublishResultsDate(ZonedDateTime.now().minusDays(2));
examRepository.save(exam);
Result result = participationUtilService.addResultToParticipation(null, null, examStudentParticipation);
Expand Down

0 comments on commit 2f64afc

Please sign in to comment.