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

Small refactor of BaseStreamResourceWriter #142

Merged
merged 4 commits into from
Sep 16, 2024
Merged

Small refactor of BaseStreamResourceWriter #142

merged 4 commits into from
Sep 16, 2024

Conversation

javier-godoy
Copy link
Member

@javier-godoy javier-godoy commented Sep 16, 2024

A small refactor reducing the visibility of some members of BaseStreamResourceWriter that do not need to be protected.

Summary by CodeRabbit

  • New Features

    • Enhanced template retrieval method in both the Docx and Excel stream resource writers for improved flexibility.
  • Improvements

    • Improved encapsulation and control over internal state in the BaseStreamResourceWriter class.
    • Updated access modifiers for various fields and methods to enhance class immutability and restrict visibility.

These changes contribute to a more robust and maintainable codebase, ultimately benefiting end-user functionality.

Copy link

coderabbitai bot commented Sep 16, 2024

Walkthrough

The changes primarily involve modifications to the visibility and accessibility of class members in the BaseStreamResourceWriter, DocxStreamResourceWriter, and ExcelStreamResourceWriter classes. Key alterations include changing certain fields and methods from protected to private, enhancing encapsulation. Additionally, the retrieval of template resources has been updated to use a method instead of direct variable references, allowing for more flexible access to template data.

Changes

Files Change Summary
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java - Changed protected GridExporter<T> exporter to protected final GridExporter<T> exporter
- Changed protected String template to private String template
- Added protected String getTemplate()
- Changed protected Stream<T> obtainFlattenedHierarchicalDataStream(...) to private Stream<T> obtainFlattenedHierarchicalDataStream(...)
- Changed protected ArrayList<T> fetchDataRecursive(...) to private ArrayList<T> fetchDataRecursive(...)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java - Updated template retrieval from this.getClass().getResourceAsStream(template) to this.getClass().getResourceAsStream(getTemplate())
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java - Updated template retrieval from direct variable reference to getTemplate() method call in private Workbook getBaseTemplateWorkbook()

Possibly related PRs

🐇 In the code we hop and play,
Fields and methods change today.
Templates now are fetched with care,
Encapsulation fills the air.
A final touch, a private glance,
In our code, we take a chance! 🎉


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a018427 and f301285.

Files selected for processing (3)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (3 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java
Additional comments not posted (6)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (5)

51-51: LGTM!

Making the exporter field final is a good practice to ensure immutability and prevent accidental reassignment. The field remains protected, allowing access from subclasses.


52-52: LGTM!

Changing the template field from protected to private is a good practice to improve encapsulation. The field is now effectively encapsulated within the class, preventing direct access from subclasses.


66-68: LGTM!

Introducing the protected getTemplate method is a good way to provide controlled access to the private template field. This allows subclasses to retrieve the value of template without exposing the field directly, maintaining encapsulation.


176-179: LGTM!

Changing the obtainFlattenedHierarchicalDataStream method from protected to private is a good practice to improve encapsulation. This clarifies that the method is intended for internal use only and should not be exposed to subclasses.


Line range hint 181-218: LGTM!

Changing the fetchDataRecursive method from protected to private is a good practice to improve encapsulation. This clarifies that the method is intended for internal use only and should not be exposed to subclasses.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (1)

394-394: Approved: The change aligns with the PR objective and promotes encapsulation.

Invoking the getTemplate() method instead of directly referencing the template variable is a good refactor that aligns with the PR objective of reducing member visibility. This change encapsulates the template retrieval logic, promoting better information hiding and allowing for potential future modifications to the retrieval process without affecting other parts of the code. The overall functionality remains intact.


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 generate interesting stats about this repository and render them as a table.
    -- @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 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.

Copy link

Copy link
Member

@paodb paodb left a comment

Choose a reason for hiding this comment

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

LGTM

@paodb paodb merged commit 211151d into master Sep 16, 2024
3 checks passed
@paodb paodb deleted the small-refactor branch September 16, 2024 16:58
@javier-godoy
Copy link
Member Author

Part of #149

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