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: Remove atlas dependency on jgrapht and apfloat #9342

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

Conversation

MaximilianAnzinger
Copy link
Contributor

@MaximilianAnzinger MaximilianAnzinger commented Sep 20, 2024

Checklist

General

  • I tested all changes and their related features with all corresponding user types on a test server.
  • This is a small issue that I tested locally and was confirmed by another developer on a test server.
  • I chose a title conforming to the naming conventions for pull requests.

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.

Motivation and Context

jgrapht relies on apfloat which may cause serious security issues.

Description

In this PR we add our own implementation of a generic UnionFind datastructure that utilizes path compression and accounts for the rank of the nodes to achieve an amotized runtime O($\alpha$(n)) and O(n) space complexity.

Steps for Testing

Prerequisites:

  • 1 Instructor

  • Course with learning paths enabled

  • Competencies that contain relations of the type "Matching"

  • navigate to the learning paths tab of the instructor view

  • view a students learning path

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

Test Coverage

Summary by CodeRabbit

  • New Features

    • Introduced a custom UnionFind class for efficient management of disjoint sets.
    • Added comprehensive unit tests for the UnionFind functionality.
  • Bug Fixes

    • Removed outdated dependencies to enhance security and stability.
  • Refactor

    • Updated import statements to utilize the new UnionFind implementation.

@MaximilianAnzinger MaximilianAnzinger requested a review from a team as a code owner September 20, 2024 00:05
Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

The changes involve the removal of two dependencies from the build.gradle file due to security concerns. Additionally, the import of the UnionFind class has been updated in the LearningPathNgxService.java file to reference a new implementation. A new UnionFind class has been introduced in the util package, which implements a disjoint set data structure. Correspondingly, a UnionFindTest class has been added to provide unit tests for the new implementation, covering various functionalities of the UnionFind class.

Changes

File Path Change Summary
build.gradle Removed dependencies: org.jgrapht:jgrapht-core:1.5.2 and org.apfloat:apfloat:1.14.0.
src/main/java/de/tum/cit/aet/artemis/atlas/service/learningpath/LearningPathNgxService.java Updated import statement for UnionFind from org.jgrapht.alg.util to de.tum.cit.aet.artemis.atlas.service.util.
src/main/java/de/tum/cit/aet/artemis/atlas/service/util/UnionFind.java Added new UnionFind class implementing a disjoint set data structure with methods for union, find, and set management.
src/test/java/de/tum/cit/aet/artemis/UnionFindTest.java Introduced UnionFindTest class with unit tests for the UnionFind implementation, covering initialization, adding elements, finding, union operations, and set membership.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UnionFind
    participant Element

    Client->>UnionFind: Initialize with elements
    UnionFind->>Element: Set each element as its own parent
    Client->>UnionFind: Add Element
    UnionFind->>Element: Ensure no duplicates
    Client->>UnionFind: Find Element
    UnionFind->>Element: Retrieve representative
    Client->>UnionFind: Union Elements
    UnionFind->>Element: Merge sets
    Client->>UnionFind: Check inSameSet
    UnionFind->>Element: Verify membership
Loading

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.

@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) labels Sep 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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 49a75cd and 67a4aef.

Files selected for processing (4)
  • build.gradle (0 hunks)
  • src/main/java/de/tum/cit/aet/artemis/atlas/service/learningpath/LearningPathNgxService.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/atlas/service/util/UnionFind.java (1 hunks)
  • src/test/java/de/tum/cit/aet/artemis/UnionFindTest.java (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • build.gradle
Additional context used
Path-based instructions (3)
src/main/java/de/tum/cit/aet/artemis/atlas/service/learningpath/LearningPathNgxService.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/main/java/de/tum/cit/aet/artemis/atlas/service/util/UnionFind.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/UnionFindTest.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

Additional comments not posted (15)
src/test/java/de/tum/cit/aet/artemis/UnionFindTest.java (7)

24-27: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the initial state of the UnionFind instance.


30-34: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the behavior of adding a new element to the UnionFind instance.


37-40: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the behavior of finding the representative of individual elements.


43-47: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the behavior of merging sets using the union method.


50-54: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the behavior of checking if elements belong to the same set using the inSameSet method.


57-61: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the behavior of counting the number of sets after performing multiple unions.


64-68: LGTM!

The test is well-written, follows the naming convention, and uses specific assertions to verify the behavior of checking the size of the UnionFind instance before and after adding an element.

src/main/java/de/tum/cit/aet/artemis/atlas/service/util/UnionFind.java (7)

16-22: LGTM!

The constructor correctly initializes the UnionFind data structure with the provided elements, setting each element as its own parent with a rank of 0 and updating the count variable accordingly.


29-36: LGTM!

The addElement method correctly handles the addition of a new element to the UnionFind data structure, ensuring that duplicates are not added and updating the necessary data structures and variables.


44-68: LGTM!

The find method correctly implements the find operation with path compression, efficiently retrieving the representative element of the set containing the given element. The method also properly handles the case when the input element is not found in the data structure.


76-101: LGTM!

The union method correctly implements the union operation with union by rank, efficiently merging the sets containing the given elements. The method properly handles the case when either of the input elements is not found in the data structure and updates the count variable to reflect the merging of sets.


110-112: LGTM!

The inSameSet method correctly checks if the two given elements belong to the same set by comparing their representative elements (roots) obtained using the find method.


119-121: LGTM!

The numberOfSets method correctly returns the current number of disjoint sets by returning the value of the count variable.


128-130: LGTM!

The size method correctly returns the total number of elements in the UnionFind data structure by returning the size of the parentMap.

src/main/java/de/tum/cit/aet/artemis/atlas/service/learningpath/LearningPathNgxService.java (1)

26-26: Verify correctness of the custom UnionFind implementation.

The import statement change aligns with the PR objective to remove the dependency on the jgrapht library. However, please ensure that the custom UnionFind implementation located in the de.tum.cit.aet.artemis.atlas.service.util package has been thoroughly tested for correctness and provides equivalent behavior to the previous implementation from jgrapht.

To verify the correctness of the custom UnionFind implementation, you can run the following script:

The script performs the following verifications:

  1. Checks if both the UnionFind class and its corresponding test class UnionFindTest exist in the codebase.
  2. Searches for usage of core methods specific to the UnionFind class (union, find, connected) to ensure that the custom implementation provides the same functionality.
  3. Checks if the UnionFindTest class contains multiple test methods annotated with @Test to verify the correctness of the UnionFind implementation.

Please review the test results and ensure that the custom UnionFind implementation is thoroughly tested and provides the same behavior as the previous implementation.

src/test/java/de/tum/cit/aet/artemis/UnionFindTest.java Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 20, 2024
JohannesWt
JohannesWt previously approved these changes Sep 20, 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 LGTM - nice that we get rid of some dependencies

build.gradle Outdated Show resolved Hide resolved
@MaximilianAnzinger MaximilianAnzinger changed the title Development: Remove jgrapht and apfloat dependency Development: Remove atlas dependency on jgrapht and apfloat Sep 20, 2024
Copy link
Contributor

@JohannesStoehr JohannesStoehr left a comment

Choose a reason for hiding this comment

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

Nice data structure. Code looks good to me

Copy link
Contributor

@coolchock coolchock 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 ts5, works as expected, nothing seems to be broken

Copy link

@raffifasaro raffifasaro 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 TS5, working as described

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: Ready For Review
Development

Successfully merging this pull request may close these issues.

6 participants