Skip to content

Conversation

@javier-godoy
Copy link
Member

@javier-godoy javier-godoy commented Jun 5, 2024

Use StreamResourceWriter instead of InputStreamFactory + Thread + PipedInput/OutputStream + implicit StreamResource pipe.

Summary by CodeRabbit

  • New Features

    • Enhanced export functionality for GridExporter, supporting direct writing to OutputStream for CSV, DOCX, PDF, and Excel formats.
  • Refactor

    • Updated internal class names and method signatures to improve clarity and functionality.

@javier-godoy javier-godoy requested a review from mlopezFC June 5, 2024 19:59
@coderabbitai
Copy link

coderabbitai bot commented Jun 5, 2024

Walkthrough

The recent changes involve updating various classes in the gridexporter package to shift from using input stream factories to stream resource writers. This includes renaming classes and methods, modifying method signatures, and updating logic for handling output streams. Additionally, a new dependency on jakarta.servlet-api has been added to the pom.xml file.

Changes

File Path Change Summary
pom.xml Added dependency on jakarta.servlet-api version 6.0.0 with scope provided.
.../BaseStreamResourceWriter.java Renamed BaseInputStreamFactory to BaseStreamResourceWriter and updated the implemented interface.
.../CsvStreamResourceWriter.java Renamed class and updated methods to handle output streams directly for CSV writing.
.../DocxStreamResourceWriter.java Renamed class and updated methods to handle output streams directly for DOCX writing, including session handling.
.../ExcelStreamResourceWriter.java Renamed class and updated methods to handle output streams directly for Excel writing, with significant logic refactoring.
.../GridExporter.java Replaced input stream factories with stream resource writers for various file formats.
.../PdfStreamResourceWriter.java Renamed class and updated methods to handle output streams directly for PDF writing.

Poem

In a code forest, changes bloom,
Stream writers now assume the room.
CSVs and PDFs, Excel too,
Flowing streams, a fresh debut.
From input streams, we now depart,
Embracing output with a rabbit's heart.
🌸✨


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>.
    • 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 show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

@javier-godoy
Copy link
Member Author

Quality Gate Failed Quality Gate failed

Failed conditions 1 Security Hotspot

See analysis details on SonarCloud

Sonar complains about a line that was already present in the codebase

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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9fafac3 and 4ad5f5f.

Files selected for processing (7)
  • pom.xml (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (3 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/PdfStreamResourceWriter.java (2 hunks)
Additional comments not posted (20)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/PdfStreamResourceWriter.java (2)

39-41: Class and logger setup looks good. The logger is correctly configured to use the class name.


43-43: Constructor correctly passes parameters to the superclass. Good use of inheritance.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java (2)

43-45: Class and logger setup looks good. The logger is correctly configured to use the class name.


47-47: Constructor correctly initializes the superclass. Good use of inheritance.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (2)

47-49: Class and logger setup looks good. The logger is correctly configured to use the class name.


54-59: Constructors are well-implemented, providing flexibility in template handling. Good use of default parameters.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (2)

58-60: Class and logger setup looks good. The logger is correctly configured to use the class name.


64-64: Constructor correctly passes parameters to the superclass. Good use of inheritance.

pom.xml (1)

116-121: The addition of jakarta.servlet-api with scope provided is appropriate for servlet API usage without including it in the final artifact. Ensure this aligns with project requirements.

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

67-67: Class definition updated to extend BaseStreamResourceWriter.

This change aligns with the PR's objective to transition from InputStreamFactory to StreamResourceWriter.


74-74: Constructor correctly initializes the superclass with parameters.

The constructor's implementation is consistent with the expected behavior of initializing the base class with specific parameters for Excel export functionality.


79-85: Method accept correctly handles the Excel workbook creation and output stream writing.

The method encapsulates the workbook creation and writing logic within a try-catch block, ensuring that any IOException is appropriately logged and handled.


Line range hint 87-153: Method createWorkbook has been refactored to include session locking and unlocking.

The session management ensures thread safety during the workbook creation. This is a critical addition given the web context of Vaadin applications.


106-107: Use of merged regions to handle titles in the Excel sheet.

This implementation allows dynamic merging based on the number of headers, which is a flexible approach to handling varying content widths.


136-139: Dynamic column sizing based on content.

Automatically resizing columns based on their content improves the readability of the exported Excel file, which enhances user experience.


142-149: Handling of additional placeholders for custom cell values.

This feature provides flexibility in managing additional data points in the Excel export, which can be particularly useful for reports that require custom formatted data.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java (4)

279-279: Ensure the PdfStreamResourceWriter constructor matches the expected parameters.

Verification successful

The constructor of PdfStreamResourceWriter matches the expected parameters (GridExporter<T> exporter, String template).

  • PdfStreamResourceWriter constructor: public PdfStreamResourceWriter(GridExporter<T> exporter, String template)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the constructor of `PdfStreamResourceWriter` accepts the correct parameters.

# Test: Search for the constructor definition. Expect: Constructor with parameters matching those in the call.
ast-grep --lang java --pattern $'class PdfStreamResourceWriter {
  PdfStreamResourceWriter(GridExporter $_, String $_) {
    $$$
  }
}'

Length of output: 136



Script:

#!/bin/bash
# Locate the file containing the PdfStreamResourceWriter class
fd -e java 'PdfStreamResourceWriter' --exec cat {} +

# Verify the constructor parameters within the located file
ast-grep --lang java --pattern $'class PdfStreamResourceWriter {
  PdfStreamResourceWriter(GridExporter $_, String $_) {
    $$$
  }
}' $(fd -e java 'PdfStreamResourceWriter')

Length of output: 2555


291-291: Ensure the ExcelStreamResourceWriter constructor matches the expected parameters.

Verification successful

The constructor for ExcelStreamResourceWriter matches the expected parameters.

  • ExcelStreamResourceWriter(GridExporter<T> exporter, String template)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the constructor of `ExcelStreamResourceWriter` accepts the correct parameters.

# Test: Search for the constructor definition. Expect: Constructor with parameters matching those in the call.
ast-grep --lang java --pattern $'class ExcelStreamResourceWriter {
  ExcelStreamResourceWriter(GridExporter $_, String $_) {
    $$$
  }
}'

Length of output: 140



Script:

#!/bin/bash
# Description: Search for the `ExcelStreamResourceWriter` class definition and its constructor.

# Step 1: Search for the `ExcelStreamResourceWriter` class definition.
ast-grep --lang java --pattern 'class ExcelStreamResourceWriter { $$$ }'

# Step 2: Search for the constructor within the `ExcelStreamResourceWriter` class.
ast-grep --lang java --pattern 'class ExcelStreamResourceWriter {
  ExcelStreamResourceWriter($$$) {
    $$$
  }
}'

Length of output: 192



Script:

#!/bin/bash
# Description: Search for the `ExcelStreamResourceWriter` class definition and its constructor using broader search patterns.

# Step 1: Search for the `ExcelStreamResourceWriter` class definition.
rg 'class ExcelStreamResourceWriter' -t java

# Step 2: Search for the constructor within the `ExcelStreamResourceWriter` class.
rg 'ExcelStreamResourceWriter\(.*\)' -t java

Length of output: 422


283-283: Ensure the CsvStreamResourceWriter constructor matches the expected parameters.

Verification successful

The constructor of CsvStreamResourceWriter accepts a GridExporter parameter, which matches the expected parameter in the code snippet provided.

  • CsvStreamResourceWriter constructor: public CsvStreamResourceWriter(GridExporter<T> exporter)

This confirms that the constructor call in the code snippet is correct.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the constructor of `CsvStreamResourceWriter` accepts the correct parameters.

# Test: Search for the constructor definition. Expect: Constructor with parameters matching those in the call.
ast-grep --lang java --pattern $'class CsvStreamResourceWriter {
  CsvStreamResourceWriter(GridExporter $_) {
    $$$
  }
}'

Length of output: 125



Script:

#!/bin/bash
# Locate the CsvStreamResourceWriter class definition
fd -e java -x grep -Hn 'class CsvStreamResourceWriter' {} +

# Verify the constructor parameters of the CsvStreamResourceWriter class
ast-grep --lang java --pattern 'class CsvStreamResourceWriter {
  CsvStreamResourceWriter($_) {
    $$$
  }
}'

Length of output: 1283



Script:

#!/bin/bash
# Display the contents of the CsvStreamResourceWriter class file to inspect its constructor
cat src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java

Length of output: 3755


271-271: Ensure the DocxStreamResourceWriter constructor matches the expected parameters.

Verification successful

The constructor for DocxStreamResourceWriter matches the expected parameters (GridExporter<T> exporter, String template).

  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java: public DocxStreamResourceWriter(GridExporter<T> exporter, String template)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the constructor of `DocxStreamResourceWriter` accepts the correct parameters.

# Test: Search for the constructor definition. Expect: Constructor with parameters matching those in the call.
ast-grep --lang java --pattern $'class DocxStreamResourceWriter {
  DocxStreamResourceWriter(GridExporter $_, String $_) {
    $$$
  }
}'

Length of output: 138



Script:

#!/bin/bash
# Description: Verify the existence of the `DocxStreamResourceWriter` class and its constructor.

# Step 1: Search for the `DocxStreamResourceWriter` class definition.
ast-grep --lang java --pattern 'class DocxStreamResourceWriter { $$$ }'

# Step 2: If the class exists, search for its constructor with the expected parameters.
ast-grep --lang java --pattern $'class DocxStreamResourceWriter {
  DocxStreamResourceWriter(GridExporter $_, String $_) {
    $$$
  }
}'

Length of output: 212



Script:

#!/bin/bash
# Description: Verify the existence of the `DocxStreamResourceWriter` class and inspect its constructors.

# Step 1: Search for the `DocxStreamResourceWriter` class definition in the entire codebase.
rg 'class DocxStreamResourceWriter' -t java

# Step 2: If the class exists, search for all constructors of the `DocxStreamResourceWriter` class.
rg 'DocxStreamResourceWriter(' -t java

Length of output: 346



Script:

#!/bin/bash
# Description: Inspect constructors of the `DocxStreamResourceWriter` class.

# Search for all constructors of the `DocxStreamResourceWriter` class.
rg 'DocxStreamResourceWriter\(' -t java

Length of output: 207

@javier-godoy
Copy link
Member Author

Actionable comments posted: 6

Ears twitch, hops abound,
Annoying rabbit's antics,
Test patience, yet charm.

🐇😕

@javier-godoy javier-godoy requested a review from paodb June 7, 2024 17:27
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.

for me it looks ok

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.

3 participants