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

Development: Convert classes into records #8571

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

Conversation

krusche
Copy link
Member

@krusche krusche commented May 11, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) database calls.
  • I strictly followed the server coding and design guidelines.
  • I documented the Java code using JavaDoc style.

Motivation and Context

The main motivation for this change is to take advantage of records, which were introduced in Java 14 and formally standardised in Java 16. Records provide a more concise and readable way to define immutable data carriers, which is the main purpose of DTOs.

  • Conciseness: Records significantly reduce boilerplate code. DTOs often require multiple lines of code to define fields, constructors, accessors, equals(), hashCode(), and toString() methods. With records, all of these are automatically provided by the compiler.
  • Immutability: Records are immutable by default. This aligns with the design principles of DTOs, which should represent data snapshots without exposing mutability.
  • Readability: By removing boilerplate code, records make the DTO definitions cleaner and more focused on the actual data they carry, improving readability and maintainability.
  • Performance: The auto-generated methods in records are optimized by the compiler, potentially offering better performance characteristics for equals(), hashCode(), and toString().

Description

  • Refactored multiple DTO classes in the project to use Java records.
  • Added an architecture test that prevents the addition of new DTO classes.
  • Updated relevant test cases to reflect the changes.

Steps for Testing

Prerequisites:

  • 1 Instructor

  • 1 Student

  • 1 Tutor

  • 1 Empty Course

  • This PR is best tested locally, as you have access to the server's logs there.

  • Look out for Bad Requests and Nullpointer Exceptions. They indicate that a Collection type that was never null by default before might be able to be null now.

  • Given the changed DTOs, try to break the communication between the client and the server (e.g. Write a complaint as a student and then answer it as an instructor to test the AssessmentUpdateDTO etc.). Please make sure to add what you've tested into your review description.

  • Likely edge cases include empty collections (e.g. an AssessmentUpdate with no feedbacks). The classes may have set these values to an empty collection by default, but the records do not, leading to potential errors when iterating directly over collections elsewhere in the code without first checking them for nullity.

Testserver States

Note

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






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

@krusche krusche changed the title convert classes into records Development: Convert classes into records May 11, 2024
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) labels May 11, 2024
# Conflicts:
#	src/main/java/de/tum/in/www1/artemis/service/connectors/apollon/ApollonConversionService.java
# Conflicts:
#	src/main/java/de/tum/in/www1/artemis/service/connectors/athena/AthenaFeedbackSuggestionsService.java
@DominikRemo DominikRemo self-assigned this May 18, 2024
coolchock and others added 11 commits May 19, 2024 10:28
# Conflicts:
#	src/main/java/de/tum/in/www1/artemis/service/exam/ExamService.java
#	src/main/java/de/tum/in/www1/artemis/web/rest/dto/ExamChecklistDTO.java
#	src/test/java/de/tum/in/www1/artemis/exam/ExamIntegrationTest.java
#	src/test/java/de/tum/in/www1/artemis/service/exam/ExamServiceTest.java
Fix AthenaSubmissionSendingServiceTest
Fix AthenaFeedbackSendingServiceTest
Improve TextAssessmentUpdateDTO
@DominikRemo DominikRemo marked this pull request as ready for review May 21, 2024 17:19
@DominikRemo DominikRemo requested a review from a team as a code owner May 21, 2024 17:19
rstief
rstief previously approved these changes May 21, 2024
Copy link
Contributor

@rstief rstief 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 overall. I have some suggestions for improvements, but those can also be added in a follow-up.

Key Points (for the future):

  • IMO DTOs should support null values for collections, so we should remove the compact constructors setting empty collections
  • IMO we should use of(...) methods in the DTO rather than asDTO(...) methods in the entity

JohannesWt
JohannesWt previously approved these changes May 22, 2024
Copy link
Contributor

@JohannesWt JohannesWt left a comment

Choose a reason for hiding this comment

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

Code looks good - few (maybe optional/debatable) changes explained in the comments

coderabbitai[bot]
coderabbitai bot previously approved these changes May 29, 2024
Copy link
Contributor

@laadvo laadvo left a comment

Choose a reason for hiding this comment

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

Tested participation and assessment of programming, text, modeling, and file upload exercises locally. Working as expected, did not encounter any null pointers or bad requests

Copy link
Contributor

@rstief rstief 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, thanks for implementing my many change requests 🙏🙏🙏

Copy link
Contributor

@DominikRemo DominikRemo left a comment

Choose a reason for hiding this comment

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

Tested in testing session on TS5. Empty commits (empty additions/deletions/completely empty commits) work for programming exercises and empty submissions for all other exercise types also work (tested as part of an exam)

Copy link
Contributor

@undernagruzez undernagruzez left a comment

Choose a reason for hiding this comment

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

tested during a testing session, works as expected for full on time submissions
found 2 issues, but guess they are not related to this pr

  1. When I am registered for the exam(as a student) and click on the exam button, I see an error message(course overview page)
  2. If the time on my machine differs from the server time, I cannot generate individual exams(as an instructor)

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.

tested in a testing session on ts5. Participated in a exam and tried various exercises and different scenarios. All work as expected.

Copy link
Contributor

@EneaGore EneaGore 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 testing session ts5. Works as expected.

Copy link
Contributor

@laadvo laadvo left a comment

Choose a reason for hiding this comment

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

Tested in the testing session on ts5, competencies are still working as expected

Copy link
Contributor

@sarpsahinalp sarpsahinalp left a comment

Choose a reason for hiding this comment

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

Tested locally works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review server Pull requests that update Java code. (Added Automatically!) tests
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.

None yet