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

Exam mode: Allow submission upon extension #9833

Closed

Conversation

meltemarsl
Copy link

@meltemarsl meltemarsl commented Nov 20, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I documented the Java code using JavaDoc style.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).
  • I tested all changes and their related features with all corresponding user types on a test server configured with Gitlab and Jenkins.

Motivation and Context

When instructors extend the time of a student after the exam has officially ended, the student can again access the exam, but is unable to push code.

Linked issue

Description

When the instructor extends a student's individual working time after the exam officially ends, student having the extended time should be able to submit their code.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Student
  • 1 Programming Exercise with at least 1 exercise

Test 1 - Without submission policy

  1. Log in to Artemis as an Instructor
  2. Create an exam (Ex1)
  3. Create a programming exercise (Pex1, without a submission policy) for Ex1
  4. Register a student (student1) for Ex1
  5. Extend the individual working time of student1 after the exam ends
  6. Log in to Artemis as student1
  7. Check if the student1 can submit their code for Pex1
  • Note: If the student handed in their exam, the instructor should first change the student exam to unsubmitted (with the button on the same page) before extending the working time.

Test 2 - With submission policy

  1. Log in to Artemis as an Instructor
  2. Create an exam (Ex2)
  3. Create a programming exercise (Pex2, with a submission policy) for Ex2
  4. Register a student (student2) for Ex2
  5. During the exam: Log in to Artemis as student2
  6. During the exam: Make commits until reaching the submission policy limit. (e.g. 5 commits if the policy limit is 5)
  7. After the exam, as the instructor: Extend the individual working time of student2
  8. As the student2, you shouldn't be able to submit your code since you already reached the submission limit -> repository is still locked.
  • Note: If the student handed in their exam, the instructor should first change the student exam to unsubmitted (with the button on the same page) before extending the working time.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

  • New Features
    • Enhanced exam processing now dynamically manages programming exercise participation. When working time is updated, the system evaluates submission policies and unlocks participation as appropriate.
    • Improved retrieval of exam details ensures comprehensive exercise and policy information is considered, resulting in a more consistent exam experience.

@meltemarsl meltemarsl requested a review from a team as a code owner November 20, 2024 14:10
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) exam Pull requests that affect the corresponding module labels Nov 20, 2024
@meltemarsl meltemarsl changed the title Exam mode: Allow submission upon extension Exam mode: Allow submission upon extension Nov 20, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (2)

Line range hint 149-171: Constructor Contains Many Parameters Indicating Potential Class Responsibility Overload

The StudentExamResource constructor now has a large number of parameters (over 20 dependencies), which can make the code harder to maintain and understand. This might indicate that the class is handling too many responsibilities.

Consider refactoring the class to adhere to the single responsibility principle by extracting related functionalities into separate services or components. This can improve maintainability and readability.


269-281: Refactor Logic into a Separate Method for Improved Readability

The logic within the updateWorkingTime method, specifically from lines 269 to 281, is complex and involves multiple nested operations. Extracting this block into a separate private method would enhance readability and maintainability.

Apply this diff to refactor the code:

if (!studentExam.isEnded() && wasEndedOriginally) {
+   unlockProgrammingExerciseParticipations(studentExam);
}

...

+ private void unlockProgrammingExerciseParticipations(StudentExam studentExam) {
+     studentExam.getExercises().stream()
+         .filter(ProgrammingExercise.class::isInstance)
+         .forEach(exercise -> {
+             var participation = programmingExerciseStudentParticipationRepository
+                 .findByExerciseIdAndStudentLogin(exercise.getId(), studentExam.getUser().getLogin());

+             var submissionPolicy = ((ProgrammingExercise) exercise).getSubmissionPolicy();

+             participation.ifPresent(participationObj -> {
+                 long inTimeSubmissions = participationObj.getSubmissions().stream()
+                     .filter(submission -> !submission.isLate())
+                     .count();
+                 if (submissionPolicy == null || inTimeSubmissions < submissionPolicy.getSubmissionLimit()) {
+                     programmingExerciseParticipationService.unlockStudentRepositoryAndParticipation(participationObj);
+                 }
+             });
+         });
+ }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e3ed347 and 289b371.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (5 hunks)
  • src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

📓 Learnings (1)
src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (1)
Learnt from: valentin-boehm
PR: ls1intum/Artemis#7384
File: src/test/java/de/tum/in/www1/artemis/exam/StudentExamIntegrationTest.java:2836-2846
Timestamp: 2024-11-12T12:51:51.201Z
Learning: The `testAbandonStudentExamNotInTime` method does not require additional checks to verify the state of `studentExam1` after receiving a `HttpStatus.FORBIDDEN` because the control flow in the `StudentExamResource` is straightforward and ensures no state change occurs.
🔇 Additional comments (2)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (2)

131-132: Dependency Injection Via Constructor Is Correct

The addition of ProgrammingExerciseStudentParticipationRepository as a private final member and its injection via the constructor adheres to best practices and the project's dependency injection guidelines.


138-139: Dependency Injection Via Constructor Is Correct

The addition of ProgrammingExerciseParticipationService as a private final member and its injection via the constructor is appropriate and aligns with the project's conventions for dependency management.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java (1)

436-444: Optimize query performance by filtering programming exercises.

The current query fetches all exercises but only needs programming exercises with submission policies. Consider optimizing the query to only fetch programming exercises.

Apply this diff to optimize the query:

    @Query("""
            SELECT se
            FROM StudentExam se
-                LEFT JOIN FETCH se.exercises ex
-                LEFT JOIN TREAT(ex AS ProgrammingExercise) progEx
-                LEFT JOIN FETCH progEx.submissionPolicy sp
+                LEFT JOIN FETCH se.exercises progEx
+                JOIN TYPE(progEx) t
+                LEFT JOIN FETCH progEx.submissionPolicy sp
+            WHERE se.id = :studentExamId
+                AND t = ProgrammingExercise
            WHERE se.id = :studentExamId
        """)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between edc9261 and 24f50ac.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

  • src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java
  • src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java
📓 Learnings (1)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (2)
Learnt from: julian-christl
PR: ls1intum/Artemis#9322
File: src/main/java/de/tum/cit/aet/artemis/programming/repository/ProgrammingExerciseStudentParticipationRepository.java:0-0
Timestamp: 2024-11-12T12:51:51.201Z
Learning: In Artemis, an `ExerciseGroup` always has an associated `Exam`, so `exerciseGroup.exam` is never null.
Learnt from: julian-christl
PR: ls1intum/Artemis#9322
File: src/main/java/de/tum/cit/aet/artemis/programming/repository/ProgrammingExerciseStudentParticipationRepository.java:170-172
Timestamp: 2024-11-12T12:51:46.554Z
Learning: In Artemis, `exercise.exerciseGroup` may be null, as not all exercises belong to an `ExerciseGroup`.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: client-style
  • GitHub Check: client-tests
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: Analyse
🔇 Additional comments (3)
src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java (1)

429-435: LGTM!

The method signature and documentation are clear and follow the repository's conventions.

src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (2)

131-132: LGTM!

The new dependencies are properly injected through constructor injection, following the coding guidelines.

Also applies to: 138-138, 149-150, 170-171


254-283: Refactor for better code organization and error handling.

The code could be improved for better readability, error handling and performance.

Extract the logic into a dedicated method and improve error handling as suggested in the past review:

-            boolean wasEndedOriginally = now.isAfter(exam.getEndDate());
-            if (wasEndedOriginally) {
-                studentExam.getExercises().stream().filter(ProgrammingExercise.class::isInstance).forEach(exercise -> {
-                    var programmingExerciseStudentParticipation = programmingExerciseStudentParticipationRepository.findByExerciseIdAndStudentLogin(exercise.getId(),
-                            studentExam.getUser().getLogin());
-                    var programmingExerciseSubmissionPolicy = ((ProgrammingExercise) exercise).getSubmissionPolicy();
-                    // Unlock if there is no submission policy
-                    // or there is a submission policy, but its limit was not reached yet
-                    var submissionCount = programmingExerciseStudentParticipationRepository
-                            .findAllWithSubmissionsByExerciseIdAndStudentLogin(exercise.getId(), studentExam.getUser().getLogin()).size();
-                    if (programmingExerciseSubmissionPolicy == null || submissionCount < programmingExerciseSubmissionPolicy.getSubmissionLimit()) {
-                        programmingExerciseStudentParticipation.ifPresent(programmingExerciseParticipationService::unlockStudentRepositoryAndParticipation);
-                    }
-                });
-            }
+            unlockProgrammingExerciseParticipationsIfNeeded(studentExam, exam, now);
+        }
+    }
+
+    /**
+     * Unlocks programming exercise participations if the exam was ended originally.
+     * Only unlocks if submission policy allows or is not present.
+     */
+    private void unlockProgrammingExerciseParticipationsIfNeeded(StudentExam studentExam, Exam exam, ZonedDateTime now) {
+        if (!now.isAfter(exam.getEndDate())) {
+            return;
+        }
+
+        String studentLogin = studentExam.getUser().getLogin();
+        studentExam.getExercises().stream()
+            .filter(ProgrammingExercise.class::isInstance)
+            .map(ProgrammingExercise.class::cast)
+            .forEach(programmingExercise -> {
+                var participation = programmingExerciseStudentParticipationRepository
+                    .findByExerciseIdAndStudentLogin(programmingExercise.getId(), studentLogin);
+                
+                if (participation.isEmpty()) {
+                    log.warn("No participation found for programming exercise {} and student {}", 
+                        programmingExercise.getId(), studentLogin);
+                    return;
+                }
+
+                var submissionPolicy = programmingExercise.getSubmissionPolicy();
+                if (submissionPolicy == null) {
+                    programmingExerciseParticipationService.unlockStudentRepositoryAndParticipation(participation.get());
+                    return;
+                }
+
+                var submissionCount = programmingExerciseStudentParticipationRepository
+                    .findAllWithSubmissionsByExerciseIdAndStudentLogin(programmingExercise.getId(), studentLogin)
+                    .size();
+
+                if (submissionCount < submissionPolicy.getSubmissionLimit()) {
+                    programmingExerciseParticipationService.unlockStudentRepositoryAndParticipation(participation.get());
+                }
+            });

@helios-aet helios-aet bot temporarily deployed to artemis-test6.artemis.cit.tum.de February 6, 2025 08:50 Inactive
@ls1intum ls1intum deleted a comment from coderabbitai bot Feb 6, 2025
@ls1intum ls1intum deleted a comment from github-actions bot Feb 6, 2025
@meltemarsl
Copy link
Author

Tested on TS6. After the exam ends, I extend the individual working of the student, but when I logged in as the student, I cannot start the exam again. Did I test it wrongly, could you give me more instruction on this? Thank you

image

I added a note to the instructions: Note: If the student handed in their exam, the instructor should first change the student exam to unsubmitted (with the button on the same page) before extending the working time.
Could you check it again?
Thank you.

@meltemarsl meltemarsl closed this Feb 6, 2025
@meltemarsl meltemarsl reopened this Feb 6, 2025
@meltemarsl
Copy link
Author

[Tested on TS6] After the timer for student runs out (and student is changed to the submit page), setting individual time for the student allows student to continue working on the exercise. Pushing from IntelliJ is also possible. However, once the student has already submitted the exam, setting the individual time has no effect for the student anymore. They are unable to restart the exam nor push to the repository. image

Since the submission has a limited timer, I can imagine that students will panic and accidentally submit. Is this the intended design?

I added a note to the instructions: Note: If the student handed in their exam, the instructor should first change the student exam to unsubmitted (with the button on the same page) before extending the working time.
Could you check it again?
Thank you.

Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

The changes introduce a new method in the StudentExamRepository for fetching a StudentExam along with its exercises and submission policies using a custom JPQL query. The StudentExamResource was updated to inject additional dependencies and to use this new method in its updateWorkingTime logic, which now also includes conditional unlocking of programming exercise participations. The integration tests were expanded with new fields, constants, and a test method to validate the updated working time logic.

Changes

File(s) Summary of Changes
src/.../repository/StudentExamRepository.java Added new method findByIdWithExercisesAndSubmissionPolicy with a custom JPQL left join query for fetching associated exercises and submission policies.
src/.../web/StudentExamResource.java Injected ProgrammingExerciseStudentParticipationRepository and ProgrammingExerciseParticipationService into the constructor; updated updateWorkingTime to use the new method and include unlocking logic for programming exercises.
src/.../StudentExamIntegrationTest.java Added new autowired fields, a constant (NUMBER_OF_INSTRUCTORS), and a new test method testUpdateWorkingTime_ShouldTriggerUnlock to verify that working time updates unlock programming exercise participation.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant R as StudentExamResource
    participant Repo as StudentExamRepository
    participant P as ProgrammingExerciseParticipationService

    C->>R: updateWorkingTime(examId, newTime)
    R->>Repo: findByIdWithExercisesAndSubmissionPolicy(examId)
    Repo-->>R: Optional<StudentExam>
    alt Exam ended
        loop For each programming exercise
            R->>P: unlockParticipation(exercise)
        end
    end
Loading

Possibly related PRs

Suggested labels

programming

Suggested reviewers

  • Hialus
  • SimonEntholzer
  • krusche
  • BBesrour
  • EneaGore

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 PMD (7.8.0)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (1)

278-278: 🛠️ Refactor suggestion

Optimize database query by counting submissions directly

At line 278~, the code retrieves all submissions to count them, which can be inefficient, especially if there are many submissions. To improve performance, consider adding a repository method that counts the submissions directly in the database.

Add this method to ProgrammingExerciseStudentParticipationRepository:

@Query("SELECT COUNT(s) FROM ProgrammingSubmission s WHERE s.participation.exercise.id = :exerciseId AND s.participation.student.login = :studentLogin")
long countSubmissionsByExerciseIdAndStudentLogin(@Param("exerciseId") Long exerciseId, @Param("studentLogin") String studentLogin);

Then, update the code to use this new method:

- var submissionCount = programmingExerciseStudentParticipationRepository
-       .findAllWithSubmissionsByExerciseIdAndStudentLogin(exercise.getId(), studentExam.getUser().getLogin()).size();
+ var submissionCount = programmingExerciseStudentParticipationRepository
+       .countSubmissionsByExerciseIdAndStudentLogin(programmingExercise.getId(), studentExam.getUser().getLogin());
🧹 Nitpick comments (3)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (1)

271-283: Avoid unnecessary casting by working with ProgrammingExercise directly

In the loop starting at line 271~, you filter exercises of type ProgrammingExercise but continue to handle them as Exercise, performing casts multiple times. To enhance code readability and avoid redundant casting, consider mapping the exercises directly to ProgrammingExercise instances.

Apply this diff to refactor the code:

- studentExam.getExercises().stream().filter(ProgrammingExercise.class::isInstance).forEach(exercise -> {
-     var programmingExerciseStudentParticipation = programmingExerciseStudentParticipationRepository.findByExerciseIdAndStudentLogin(exercise.getId(),
+ studentExam.getExercises().stream()
+     .filter(ProgrammingExercise.class::isInstance)
+     .map(ProgrammingExercise.class::cast)
+     .forEach(programmingExercise -> {
+     var programmingExerciseStudentParticipation = programmingExerciseStudentParticipationRepository.findByExerciseIdAndStudentLogin(programmingExercise.getId(),
          studentExam.getUser().getLogin());
-     var programmingExerciseSubmissionPolicy = ((ProgrammingExercise) exercise).getSubmissionPolicy();
+     var programmingExerciseSubmissionPolicy = programmingExercise.getSubmissionPolicy();
      // Rest of the code...
    });
src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (2)

162-163: Fix inconsistent field naming.

The repository field names use inconsistent casing:

  • ProgrammingExerciseTestRepository and CourseTestRepository use PascalCase
  • Other repository fields like programmingExerciseStudentParticipationTestRepository use camelCase

Apply this diff to maintain consistent camelCase naming:

-    private ProgrammingExerciseTestRepository ProgrammingExerciseTestRepository;
+    private ProgrammingExerciseTestRepository programmingExerciseTestRepository;

-    private CourseTestRepository CourseTestRepository;
+    private CourseTestRepository courseTestRepository;

Also applies to: 220-220


863-902: Add test coverage for submission after extension.

While the test verifies that the repository is unlocked when working time is updated, it would be valuable to add test cases that verify:

  1. The student can successfully submit after their working time is extended
  2. The submission is properly saved and processed
  3. Edge cases like multiple extensions or extensions after the exam end date

Would you like me to help generate additional test cases to cover these scenarios?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc1e3cb and a0cdd1d.

📒 Files selected for processing (3)
  • src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (6 hunks)
  • src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

  • src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java
  • src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java
`src/test/java/**/*.java`: test_naming: descriptive; test_si...

src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

  • src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java
📓 Learnings (2)
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java (2)
Learnt from: julian-christl
PR: ls1intum/Artemis#9322
File: src/main/java/de/tum/cit/aet/artemis/programming/repository/ProgrammingExerciseStudentParticipationRepository.java:0-0
Timestamp: 2024-11-12T12:51:51.201Z
Learning: In Artemis, an `ExerciseGroup` always has an associated `Exam`, so `exerciseGroup.exam` is never null.
Learnt from: julian-christl
PR: ls1intum/Artemis#9322
File: src/main/java/de/tum/cit/aet/artemis/programming/repository/ProgrammingExerciseStudentParticipationRepository.java:170-172
Timestamp: 2024-11-12T12:51:46.554Z
Learning: In Artemis, `exercise.exerciseGroup` may be null, as not all exercises belong to an `ExerciseGroup`.
src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (2)
Learnt from: julian-christl
PR: ls1intum/Artemis#9322
File: src/main/java/de/tum/cit/aet/artemis/programming/repository/ProgrammingExerciseStudentParticipationRepository.java:0-0
Timestamp: 2024-11-12T12:51:51.201Z
Learning: In Artemis, an `ExerciseGroup` always has an associated `Exam`, so `exerciseGroup.exam` is never null.
Learnt from: julian-christl
PR: ls1intum/Artemis#9322
File: src/main/java/de/tum/cit/aet/artemis/programming/repository/ProgrammingExerciseStudentParticipationRepository.java:170-172
Timestamp: 2024-11-12T12:51:46.554Z
Learning: In Artemis, `exercise.exerciseGroup` may be null, as not all exercises belong to an `ExerciseGroup`.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: client-style
  • GitHub Check: server-style
  • GitHub Check: client-tests-selected
  • GitHub Check: server-tests
  • GitHub Check: client-tests
  • GitHub Check: Analyse
🔇 Additional comments (2)
src/main/java/de/tum/cit/aet/artemis/exam/repository/StudentExamRepository.java (1)

437-444: Verify correct retrieval of submission policies in JPQL query

In the method findByIdWithExercisesAndSubmissionPolicy, ensure that the JPQL query accurately retrieves submission policies associated with ProgrammingExercise instances. The use of TREAT(ex AS ProgrammingExercise) should downcast exercises to ProgrammingExercise where applicable.

Please confirm that the TREAT function is supported in your JPA provider and behaves as expected in this context. Also, verify that this query retrieves the correct data without introducing any unintended side effects.

src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (1)

863-902: Minimize database interactions in tests by using mocks.

The test method performs multiple database operations, such as saving programmingExercise, course, participation, exam, and studentExam. According to the coding guidelines, tests should avoid direct database access and prefer mocking to improve performance and ensure test isolation.

Consider mocking the repositories and services involved to simulate database interactions. Utilize Mockito or similar frameworks to mock the behavior of these components. This will make the test faster, more reliable, and in alignment with the avoid_db_access guideline.

Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

@helios-aet helios-aet bot temporarily deployed to artemis-test1.artemis.cit.tum.de February 11, 2025 11:28 Inactive
@helios-aet helios-aet bot temporarily deployed to artemis-test1.artemis.cit.tum.de February 11, 2025 11:43 Inactive
@helios-aet helios-aet bot temporarily deployed to artemis-test4.artemis.cit.tum.de February 11, 2025 11:43 Inactive
Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS4. Works as described

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix exam Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!) tests
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

7 participants