Skip to content

Generalize reading and writing crates #247

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

Merged
merged 16 commits into from
Apr 29, 2025

Conversation

Pfeil
Copy link
Member

@Pfeil Pfeil commented Apr 22, 2025

Notes:

  • I always first adjusted the code before the tests to ensure backwards compatibility. The only exception is ZipStreamStrategy (previously ZipStreamReader), as this is not yet released.
  • Deprecated classes may be removed in a future major version, but not before.
  • The deprecated classes are kind of aliased towards the new implementations in order to not lower the code coverage too much, but it will have a small impact.

Introduce generic readers instead of the StreamReaderStrategy. This means a location may be given using any type T, which will make implementations more flexible (for example, allow other types of streams). The same is planned for writers later.

Deprecates (but still possible to use):

  • RoCrateReader -> use CrateReader
    • CrateReader is generic and can be used with ZipStreamStrategy and possibly others in future.
    • RoCrateReader is kind of an alias for compatibility until removal
  • FolderReader -> use FolderStrategy
    • renamed, but old class name is kept for compatibility (no code duplication)
  • ZipReader -> use ZipStrategy
    • renamed, but old class name is kept for compatibility (no code duplication)
  • ReaderStrategy -> use GenericReaderStrategy
    • ReaderStrategy is kind of an alias for compatibility until removal

To simplify the construction of readers, a new static factory class "Readers" is available.

This has several advantages:

  • no instanceof
  • no handling of non-intended use required
  • only one interface with no restrictions on type T

Also provides a helper/factory function for the construction of available readers.

Downsides:

  • Deprecates some existing API for the next major version (but no code should break!)
  • Generics required in reading code (e.g. CrateReader) in future

TODOs

  • Rewrite readers
    • ...
    • Adapt tests to new API to avoid warnings about usage of deprecated APIs
  • Do the same for the writers
    • basic implementation with the tests still running
    • adjust old writers to the new interface
    • "rename" writers to strategy, so people tend to use the writer, which also does validation
    • Fix warnings about deprecations in readers
    • Fix warnings about deprecations in writers
    • check if the strategies have code in common that should be placed in the writer postponed, not too important for now
  • ask for a review

This has several advantages:
- no instanceof
- no handling of non-intended use required
- only one interface with no restrictions on type T

Also provides a helper/factory function for the construction of available readers.

Downsides:
- Deprecates some existing API for the next major version
- Generics required in reading code (e.g. CrateReader<String> in future)
@Pfeil Pfeil changed the base branch from main to development April 22, 2025 13:46
Copy link

coderabbitai bot commented Apr 22, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@coveralls
Copy link

coveralls commented Apr 22, 2025

Pull Request Test Coverage Report for Build #373

Details

  • 249 of 278 (89.57%) changed or added relevant lines in 16 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.9%) to 86.891%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/main/java/edu/kit/datamanager/ro_crate/reader/FolderReader.java 0 1 0.0%
src/main/java/edu/kit/datamanager/ro_crate/reader/RoCrateReader.java 0 1 0.0%
src/main/java/edu/kit/datamanager/ro_crate/writer/ZipStreamStrategy.java 2 3 66.67%
src/main/java/edu/kit/datamanager/ro_crate/reader/FolderStrategy.java 8 10 80.0%
src/main/java/edu/kit/datamanager/ro_crate/reader/Readers.java 3 5 60.0%
src/main/java/edu/kit/datamanager/ro_crate/writer/ZipStrategy.java 28 30 93.33%
src/main/java/edu/kit/datamanager/ro_crate/reader/ZipReader.java 0 3 0.0%
src/main/java/edu/kit/datamanager/ro_crate/writer/FolderStrategy.java 24 28 85.71%
src/main/java/edu/kit/datamanager/ro_crate/reader/CrateReader.java 139 145 95.86%
src/main/java/edu/kit/datamanager/ro_crate/reader/ZipStrategy.java 29 36 80.56%
Files with Coverage Reduction New Missed Lines %
src/main/java/edu/kit/datamanager/ro_crate/reader/RoCrateReader.java 1 0.0%
src/main/java/edu/kit/datamanager/ro_crate/reader/ZipReader.java 1 0.0%
Totals Coverage Status
Change from base Build #366: 0.9%
Covered Lines: 1889
Relevant Lines: 2174

💛 - Coveralls

@Pfeil Pfeil force-pushed the generalize-reading-and-writing-crates branch from 71e7caa to bef5f67 Compare April 25, 2025 14:07
@Pfeil Pfeil requested a review from ThomasJejkal April 25, 2025 14:12
@Pfeil Pfeil self-assigned this Apr 25, 2025
@Pfeil Pfeil removed the request for review from ThomasJejkal April 28, 2025 17:38
@Pfeil Pfeil marked this pull request as ready for review April 28, 2025 17:39
@Pfeil
Copy link
Member Author

Pfeil commented Apr 29, 2025

The tests will be fixed in #253 (Issue is #254 ).

@Pfeil Pfeil merged commit 5f59145 into development Apr 29, 2025
1 of 7 checks passed
@Pfeil Pfeil deleted the generalize-reading-and-writing-crates branch April 29, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants