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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

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 added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • 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 be able to submit their code for Pex1

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.

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

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

  • New Features

    • Enhanced handling of programming exercises during student exam working time updates
    • Added logic to dynamically manage student participation based on exam state and submission policies
  • Tests

    • Added new integration test for verifying programming exercise participation unlocking mechanism
    • Expanded test coverage for student exam working time updates
  • Improvements

    • Improved flexibility in managing programming exercise submissions during exams

@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 bot commented Nov 20, 2024

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

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.

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

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.

Walkthrough

The pull request introduces changes to the StudentExamResource class and StudentExamIntegrationTest class to enhance the management of programming exercises during student exams. The modifications focus on adding new dependencies and repositories to support more dynamic handling of student participation in programming exercises, particularly when updating working times and checking submission policies.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java - Added ProgrammingExerciseStudentParticipationRepository and ProgrammingExerciseParticipationService
- Updated constructor to inject new dependencies
- Modified updateWorkingTime method to handle programming exercise participation unlocking
src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java - Added new autowired repositories: ProgrammingExerciseStudentParticipationTestRepository, ProgrammingExerciseTestRepository, CourseTestRepository
- Added UserUtilService
- Introduced new test method testUpdateWorkingTime_ShouldTriggerUnlock()

Sequence Diagram

sequenceDiagram
    participant StudentExam
    participant StudentExamResource
    participant ProgrammingExerciseStudentParticipationRepository
    participant ProgrammingExerciseParticipationService

    StudentExam->>StudentExamResource: updateWorkingTime()
    alt Exam was originally ended
        StudentExamResource->>ProgrammingExerciseStudentParticipationRepository: Find student participation
        ProgrammingExerciseStudentParticipationRepository-->>StudentExamResource: Return participation
        StudentExamResource->>ProgrammingExerciseParticipationService: Check and unlock participation
        ProgrammingExerciseParticipationService-->>StudentExamResource: Unlock result
    end
Loading

Possibly related PRs

Suggested Labels

tests, ready for review, server

Suggested Reviewers

  • SimonEntholzer
  • JohannesStoehr
  • BBesrour
  • Hialus
  • krusche

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: 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.

@meltemarsl meltemarsl removed config-change Pull requests that change the config in a way that they require a deployment via Ansible. docker template playwright atlas Pull requests that affect the corresponding module buildagent Pull requests that affect the corresponding module communication Pull requests that affect the corresponding module core Pull requests that affect the corresponding module iris Pull requests that affect the corresponding module lecture Pull requests that affect the corresponding module lti Pull requests that affect the corresponding module plagiarism Pull requests that affect the corresponding module labels Jan 14, 2025
@meltemarsl meltemarsl force-pushed the bugfix/exam-mode/allow-submission-upon-extension branch from 5d3295b to edc9261 Compare January 14, 2025 10:19
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) and removed assessment Pull requests that affect the corresponding module exercise Pull requests that affect the corresponding module programming Pull requests that affect the corresponding module labels Jan 14, 2025
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: 2

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

863-902: Enhance test robustness and readability

The test method could be improved in several ways:

  1. Add assertions to verify the participation lock state before the update
  2. Add error handling for potential null values
  3. Extract setup code into helper methods

Consider refactoring the test to:

 @Test
 @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
 void testUpdateWorkingTime_ShouldTriggerUnlock() throws Exception {
+    // Given
+    // Set up programming exercise with participation
     ProgrammingExercise programmingExercise = programmingExerciseUtilService.addCourseExamExerciseGroupWithOneProgrammingExercise();
-    ProgrammingExerciseTestRepository.save(programmingExercise);
+    programmingExerciseTestRepository.save(programmingExercise);
 
     Course course = programmingExercise.getCourseViaExerciseGroupOrCourseMember();
-    CourseTestRepository.save(course);
+    courseTestRepository.save(course);
 
     userUtilService.addUsers(TEST_PREFIX, NUMBER_OF_STUDENTS, 0, 0, NUMBER_OF_INSTRUCTORS);
     User student = userUtilService.getUserByLogin(TEST_PREFIX + "student1");
 
+    // Create and save participation
     ProgrammingExerciseStudentParticipation participation = participationUtilService.addStudentParticipationForProgrammingExercise(programmingExercise, student.getLogin());
+    assertThat(participation).isNotNull();
+    assertThat(participation.isLocked()).isTrue();
     programmingExerciseStudentParticipationTestRepository.save(participation);
 
+    // Set up exam and student exam
     Exam exam = programmingExercise.getExam();
     exam.setStartDate(ZonedDateTime.now().minusHours(2));
     exam.setEndDate(ZonedDateTime.now().minusHours(1));
     examRepository.save(exam);
 
     StudentExam studentExam = new StudentExam();
     studentExam.setUser(student);
     studentExam.setExercises(List.of(programmingExercise));
     studentExam.setExam(exam);
     studentExam.setTestRun(false);
     studentExam.setWorkingTime(1);
     studentExamRepository.save(studentExam);
 
     doNothing().when(programmingExerciseParticipationService).unlockStudentRepositoryAndParticipation(any());
 
+    // When
     int newWorkingTime = 180 * 60;
     StudentExam updatedExam = request.patchWithResponseBody(
             "/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/student-exams/" + studentExam.getId() + "/working-time", newWorkingTime, StudentExam.class,
             HttpStatus.OK);
 
+    // Then
     assertThat(updatedExam).isNotNull();
     assertThat(updatedExam.getWorkingTime()).isEqualTo(newWorkingTime);
     assertThat(participation.isLocked()).isFalse();
+    verify(programmingExerciseParticipationService, times(1)).unlockStudentRepositoryAndParticipation(participation);
 }
📜 Review details

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

📥 Commits

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

📒 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/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

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

📓 Learnings (2)
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`.
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: client-style
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: server-style
  • GitHub Check: Build .war artifact
  • GitHub Check: Analyse
  • GitHub Check: Build and Push Docker Image
🔇 Additional comments (1)
src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java (1)

159-161: 🛠️ Refactor suggestion

Follow naming conventions for repository fields

The repository field names should follow consistent casing conventions. Some fields use camelCase while others use PascalCase.

Apply this diff to fix the naming:

-    private ProgrammingExerciseTestRepository ProgrammingExerciseTestRepository;
+    private ProgrammingExerciseTestRepository programmingExerciseTestRepository;

-    private CourseTestRepository CourseTestRepository;
+    private CourseTestRepository courseTestRepository;

Also applies to: 162-164, 219-221, 222-224

⛔ Skipped due to learnings
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`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix component:Exam Mode exam Pull requests that affect the corresponding module 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.

5 participants