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 1 commit 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.

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I added authorities to all new routes and checked the course groups for displaying navigation elements (links, buttons).
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

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

Description

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 2 Students
  • 1 Programming Exercise with Complaints enabled
  1. Log in to Artemis
  2. Navigate to Course Administration
  3. ...

Exam Mode Testing

Prerequisites:

  • 1 Instructor
  • 2 Students
  • 1 Exam with a Programming Exercise
  1. Log in to Artemis
  2. Participate in the exam as a student
  3. Make sure that the UI of the programming exercise in the exam mode stays unchanged. You can use the exam mode documentation as reference.
  4. ...

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 functionality for managing programming exercises during student exams, allowing for dynamic unlocking of student participation based on exam state and submission policies.
    • New test cases added to ensure the correct unlocking of student participation when updating exam working time.
  • Bug Fixes

    • Improved handling of various scenarios in student exam submissions, including edge cases related to visibility and submission timeframes.
  • Tests

    • Expanded test coverage with new methods and refined existing tests for better clarity and maintainability.

@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

Walkthrough

The changes in this pull request involve updates to the StudentExamResource and StudentExamIntegrationTest classes. The StudentExamResource class now includes new dependencies for managing programming exercises, enhancing the updateWorkingTime method to unlock student participation based on specific conditions. The StudentExamIntegrationTest class has been modified to include new test cases and dependencies, focusing on verifying the functionality related to the updates in StudentExamResource, particularly around the unlocking of programming exercise participation.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/exam/web/StudentExamResource.java - Added dependencies: ProgrammingExerciseStudentParticipationRepository, ProgrammingExerciseParticipationService.
- Updated constructor to inject new dependencies.
- Enhanced updateWorkingTime method to unlock student participation based on exam state and submission policies.
src/test/java/de/tum/cit/aet/artemis/exam/StudentExamIntegrationTest.java - Added dependencies: ProgrammingExerciseStudentParticipationRepository, ProgrammingExerciseRepository, CourseRepository, UserUtilService.
- Introduced testUpdateWorkingTime_ShouldTriggerUnlock method to verify unlocking functionality.
- Expanded test scenarios and refined existing tests for clarity and maintainability.

Possibly related PRs

Suggested labels

tests, ready for review, server, programming, exam

Suggested reviewers

  • SimonEntholzer
  • JohannesStoehr
  • MaximilianAnzinger

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


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

Comment on lines +269 to +281
boolean wasEndedOriginally = now.isAfter(exam.getEndDate());
if (!studentExam.isEnded() && 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
if (programmingExerciseSubmissionPolicy == null || exercise.getNumberOfSubmissions().inTime() < programmingExerciseSubmissionPolicy.getSubmissionLimit()) {
programmingExerciseStudentParticipation.ifPresent(programmingExerciseParticipationService::unlockStudentRepositoryAndParticipation);
}
});
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential Logical Error: Retrieving Submission Count from Exercise Instead of Participation

In the current implementation, the method exercise.getNumberOfSubmissions().inTime() is used to check the student's number of in-time submissions. However, submissions are associated with student participations, not exercises. Using this method may not correctly reflect the individual student's submission count.

To accurately determine if a student's repository should be unlocked, retrieve the number of submissions from the student's participation. Apply this diff to correct the issue:

if (!studentExam.isEnded() && wasEndedOriginally) {
    studentExam.getExercises().stream()
        .filter(ProgrammingExercise.class::isInstance)
        .forEach(exercise -> {
            var programmingExerciseStudentParticipation = programmingExerciseStudentParticipationRepository
                .findByExerciseIdAndStudentLogin(exercise.getId(), studentExam.getUser().getLogin());

            var programmingExerciseSubmissionPolicy = ((ProgrammingExercise) exercise).getSubmissionPolicy();

            programmingExerciseStudentParticipation.ifPresent(participation -> {
+               long inTimeSubmissions = participation.getSubmissions().stream()
+                   .filter(submission -> !submission.isLate())
+                   .count();
+               if (programmingExerciseSubmissionPolicy == null || inTimeSubmissions < programmingExerciseSubmissionPolicy.getSubmissionLimit()) {
                    programmingExerciseParticipationService.unlockStudentRepositoryAndParticipation(participation);
+               }
            });
        });
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
boolean wasEndedOriginally = now.isAfter(exam.getEndDate());
if (!studentExam.isEnded() && 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
if (programmingExerciseSubmissionPolicy == null || exercise.getNumberOfSubmissions().inTime() < programmingExerciseSubmissionPolicy.getSubmissionLimit()) {
programmingExerciseStudentParticipation.ifPresent(programmingExerciseParticipationService::unlockStudentRepositoryAndParticipation);
}
});
}
boolean wasEndedOriginally = now.isAfter(exam.getEndDate());
if (!studentExam.isEnded() && wasEndedOriginally) {
studentExam.getExercises().stream()
.filter(ProgrammingExercise.class::isInstance)
.forEach(exercise -> {
var programmingExerciseStudentParticipation = programmingExerciseStudentParticipationRepository
.findByExerciseIdAndStudentLogin(exercise.getId(), studentExam.getUser().getLogin());
var programmingExerciseSubmissionPolicy = ((ProgrammingExercise) exercise).getSubmissionPolicy();
programmingExerciseStudentParticipation.ifPresent(participation -> {
long inTimeSubmissions = participation.getSubmissions().stream()
.filter(submission -> !submission.isLate())
.count();
if (programmingExerciseSubmissionPolicy == null || inTimeSubmissions < programmingExerciseSubmissionPolicy.getSubmissionLimit()) {
programmingExerciseParticipationService.unlockStudentRepositoryAndParticipation(participation);
}
});
});
}

Comment on lines +864 to +905
@Test
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void testUpdateWorkingTime_ShouldTriggerUnlock() throws Exception {
ProgrammingExercise programmingExercise = programmingExerciseUtilService.addCourseExamExerciseGroupWithOneProgrammingExercise();
programmingExerciseRepository.save(programmingExercise);

Course course = programmingExercise.getCourseViaExerciseGroupOrCourseMember();
courseRepository.save(course);

userUtilService.addUsers(TEST_PREFIX, NUMBER_OF_STUDENTS, 0, 0, NUMBER_OF_INSTRUCTORS);
User student = userUtilService.getUserByLogin(TEST_PREFIX + "student1");

ProgrammingExerciseStudentParticipation participation = participationUtilService.addStudentParticipationForProgrammingExercise(programmingExercise, student.getLogin());
participationRepository.save(participation);

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());

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);

assertThat(updatedExam).isNotNull();
assertThat(updatedExam.getWorkingTime()).isEqualTo(newWorkingTime);

verify(programmingExerciseParticipationService, times(1)).unlockStudentRepositoryAndParticipation(participation);
}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Minimize database interactions in tests by using mocks

The testUpdateWorkingTime_ShouldTriggerUnlock 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.

Comment on lines +160 to +165
@Autowired
private ProgrammingExerciseStudentParticipationRepository participationRepository;

@Autowired
private ProgrammingExerciseRepository programmingExerciseRepository;

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid direct autowiring of repositories in test classes

The test class directly autowires repositories like ProgrammingExerciseStudentParticipationRepository, ProgrammingExerciseRepository, CourseRepository, and UserUtilService. According to the coding guidelines, tests should utilize utility services or factory patterns to manage test data instead of directly accessing repositories. This approach enhances test isolation and adheres to the service-oriented architecture.

Consider refactoring to use existing utility services (e.g., ProgrammingExerciseUtilService, UserUtilService) for data setup and manipulation. If necessary, extend these utilities to cover additional functionalities required by the tests.

Also applies to: 220-225

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.

2 participants