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

feat: add support for multiple header rows #154

Merged
merged 1 commit into from
Oct 30, 2024
Merged

feat: add support for multiple header rows #154

merged 1 commit into from
Oct 30, 2024

Conversation

mlopezFC
Copy link
Member

@mlopezFC mlopezFC commented Oct 28, 2024

Add support for multiple header rows only for excel files
Closes #147

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced header management for grid exports, allowing multiple header texts per column in Excel and Word formats.
    • Introduced a demo showcasing multiple header rows in the grid exporter.
  • Bug Fixes

    • Improved header processing logic in the DocxStreamResourceWriter and ExcelStreamResourceWriter classes.

These updates enhance the flexibility and functionality of the grid exporting features, providing users with more options for data presentation.

@mlopezFC mlopezFC requested a review from javier-godoy October 28, 2024 16:50
Copy link

coderabbitai bot commented Oct 28, 2024

Walkthrough

The pull request introduces several modifications across multiple classes in the com.flowingcode.vaadin.addons.gridexporter package. Key changes include updates to the getGridHeaders method to return a list of pairs containing multiple header texts, adjustments to methods for rendering cell content, and the addition of new methods for handling headers and footers in Excel and Word exports. A new demo class is also introduced to showcase the functionality of multiple header rows in grid exporters.

Changes

File Change Summary
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java - Updated getGridHeaders method signature to return List<Pair<List<String>, Column<T>>>.
- Added getHeaderTexts method.
- Updated renderCellTextContent method to accept an additional parameter.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java - Modified createDoc method to change how headers are processed using a stream operation.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java - Updated getGridHeaders method signature to return List<Pair<List<String>, Column<T>>>.
- Split fillHeaderOrFooter into fillFooter and updated fillHeaderOrFooter.
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterDemoView.java - Added demo for multiple header rows in the constructor.
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java - Introduced a new demo class for grid exporters supporting multiple header rows.

Possibly related PRs

Suggested reviewers

  • scardanzan
  • paodb

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

@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

🧹 Outside diff range and nitpick comments (4)
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (1)

61-61: Consider using more meaningful demo data.

The "Big column" uses random Lorem ipsum text which might not effectively demonstrate the multiple header rows feature. Consider using more realistic data that better represents a real-world use case.

-    grid.addColumn(item -> Faker.instance().lorem().characters(30, 50)).setHeader("Big column");
+    grid.addColumn(item -> Faker.instance().commerce().productDescription())
+        .setHeader("Product Description");
src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (1)

131-134: Consider architectural changes for multiple header support

Supporting multiple header rows in Word documents might require broader architectural changes:

  1. Table structure modifications to accommodate multiple header rows
  2. Template updates to handle variable header row counts
  3. Cell merging and formatting adjustments for complex headers

Consider creating a design document outlining:

  • Required changes to Word template structure
  • Header row rendering strategy (e.g., cell merging, formatting)
  • Template compatibility and migration plan
  • Performance implications of multiple header processing
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (1)

414-419: Consider renaming the isHeader parameter

The method hardcodes isHeader=false when calling fillHeaderOrFooter. Consider renaming this parameter to something more descriptive like isHeaderSection to better convey its purpose.

-  private void fillFooter(Sheet sheet, Cell headersOrFootersCell,
-      List<Pair<String, Column<T>>> headersOrFooters, boolean isHeader) {
+  private void fillFooter(Sheet sheet, Cell headersOrFootersCell,
+      List<Pair<String, Column<T>>> headersOrFooters, boolean isHeaderSection) {
    List<Pair<List<String>, Column<T>>> headersOrFootersCellSingleRow = headersOrFooters.stream()
        .map(pair -> Pair.of(List.of(pair.getLeft()), pair.getRight())).collect(Collectors.toList());
-    fillHeaderOrFooter(sheet, headersOrFootersCell, headersOrFootersCellSingleRow, isHeader);
+    fillHeaderOrFooter(sheet, headersOrFootersCell, headersOrFootersCellSingleRow, isHeaderSection);
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (1)

149-156: Restrict the scope of the component variable

The variable component is declared outside the conditional block but is only used within the else clause starting at line 153. Moving its declaration inside the else block will limit its scope and enhance code readability.

Apply this diff to adjust the variable scope:

- Component component;
if (obtainCellFunction != null) {
  headerOrFooter = obtainCellFunction.apply(column);
} else {
+  Component component;
  component = getHeaderOrFooterComponent.apply(column);
  if (component != null) {
    headerOrFooter = component.getElement().getTextRecursively();
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 864a072 and d704168.

📒 Files selected for processing (5)
  • 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 (3 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterDemoView.java (1 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (1 hunks)
🧰 Additional context used
🪛 ast-grep
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java

[warning] 56-57: Detected a cookie where the Secure flag is either missing or disabled. The Secure cookie flag instructs the browser to forbid sending the cookie over an insecure HTTP request. Set the Secure flag to true so the cookie will only be sent over HTTPS.
Context: (
LitRenderer.of("${item.name}").withProperty("name", Person::getName))
Note: [CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 93-93: Detected a cookie where the Secure flag is either missing or disabled. The Secure cookie flag instructs the browser to forbid sending the cookie over an insecure HTTP request. Set the Secure flag to true so the cookie will only be sent over HTTPS.
Context: (new Span(columnHeader + " 1"))
Note: [CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 95-95: Detected a cookie where the Secure flag is either missing or disabled. The Secure cookie flag instructs the browser to forbid sending the cookie over an insecure HTTP request. Set the Secure flag to true so the cookie will only be sent over HTTPS.
Context: (new Span(columnHeader + " 2"))
Note: [CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 56-57: Detected a cookie where the HttpOnly flag is either missing or disabled. The HttpOnly cookie flag instructs the browser to forbid client-side JavaScript to read the cookie. If JavaScript interaction is required, you can ignore this finding. However, set the HttpOnly flag to true` in all other cases.
Context: (
LitRenderer.of("${item.name}").withProperty("name", Person::getName))
Note: [CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 93-93: Detected a cookie where the HttpOnly flag is either missing or disabled. The HttpOnly cookie flag instructs the browser to forbid client-side JavaScript to read the cookie. If JavaScript interaction is required, you can ignore this finding. However, set the HttpOnly flag to true` in all other cases.
Context: (new Span(columnHeader + " 1"))
Note: [CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 95-95: Detected a cookie where the HttpOnly flag is either missing or disabled. The HttpOnly cookie flag instructs the browser to forbid client-side JavaScript to read the cookie. If JavaScript interaction is required, you can ignore this finding. However, set the HttpOnly flag to true` in all other cases.
Context: (new Span(columnHeader + " 2"))
Note: [CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration

🔇 Additional comments (9)
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterDemoView.java (1)

42-42: LGTM! The demo integration looks good.

The addition of GridExporterMultipleHeaderRowsDemo follows the established pattern and aligns well with the PR objective of showcasing the multiple header rows feature.

Let's verify that the new demo class exists and is properly implemented:

✅ Verification successful

Let me gather more information about the demo class implementation since the previous results only confirmed its existence.


The demo class is properly implemented and follows the expected patterns

The verification confirms that:

  • The demo class exists and is properly implemented
  • It extends Div as expected for a Vaadin component
  • It demonstrates the multiple header rows feature by:
    • Creating a grid with sample data
    • Adding multiple header rows using appendHeaderRow()
    • Properly configuring the GridExporter with all necessary settings
    • Following the same patterns as other demos in the codebase

The integration of this demo class into GridExporterDemoView is correct and well-implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and basic structure of the new demo class

# Test 1: Check if the demo class exists
echo "Checking for the demo class file..."
fd "GridExporterMultipleHeaderRowsDemo.java"

# Test 2: Verify the class structure
echo -e "\nVerifying the class structure..."
ast-grep --pattern 'class GridExporterMultipleHeaderRowsDemo {
  $$$
}'

Length of output: 377


Script:

#!/bin/bash
# Let's examine the actual implementation of the demo class
echo "Checking the demo class implementation..."
cat src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java

# Also verify if it extends the base demo class pattern
echo -e "\nVerifying class inheritance..."
ast-grep --pattern 'class GridExporterMultipleHeaderRowsDemo extends $_ {
  $$$
}'

Length of output: 5126

src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (1)

85-87: LGTM!

The layout configuration is appropriate for the demo.

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

131-134: Consider supporting multiple header rows in Word exports

The current implementation only uses the first header text (get(0)) from the list of headers, which seems to discard additional header rows. While the PR objective is to add support for multiple header rows in Excel exports, it might be worth considering extending this functionality to Word exports as well for consistency across export formats.

Let's check how this is implemented in other exporters:

Consider the following options:

  1. If multiple header rows are intentionally not supported in Word exports, document this limitation
  2. If multiple header rows should be supported, implement similar functionality as in Excel exports
  3. Extract common header processing logic into a shared utility class to ensure consistent behavior
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (2)

98-98: LGTM: Type change supports multiple header rows

The updated return type properly supports the new multiple header rows feature.


434-436: Verify impact of row shifting on existing content

The row shifting operation could potentially affect existing content in the sheet. Please ensure that this operation is safe when there's content below the headers.

✅ Verification successful

Let me gather more context about the row shifting implementation and its usage.


Let me search for test files specifically to see if there's test coverage for this functionality.


Let me check the implementation details of the row shifting logic and its safety measures.


Based on the code analysis, I can now provide a final response about the row shifting concern.

Row shifting implementation is safe for existing content

The implementation is well-designed and safe for the following reasons:

  • Row shifting only occurs once (shiftFirstTime flag) at the beginning of header/footer processing
  • The shift amount is precisely calculated based on the actual needed space (headerOrFooterTexts.size()-1)
  • The operation preserves existing content by shifting all rows from startRow to sheet.getLastRowNum()
  • Subsequent row and cell creation is properly handled with null checks and style preservation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests or code that verifies row shifting behavior
rg -l "shiftRows.*sheet\.getLastRowNum" --type java

Length of output: 141


Script:

#!/bin/bash
# Get more context around the shiftRows usage
rg -B 10 -A 10 "shiftRows.*sheet\.getLastRowNum" --type java

# Look for tests related to headers/footers
rg -l "test.*header|test.*footer" --type java

Length of output: 2828


Script:

#!/bin/bash
# Look for test files
fd "Test.*\.java$"

# Search for any usage of ExcelStreamResourceWriter in test files
rg -l "ExcelStreamResourceWriter" --type java

Length of output: 485


Script:

#!/bin/bash
# Get the full context of fillHeaderOrFooter method
ast-grep --pattern 'fillHeaderOrFooter($$$) {
  $$$
}'

# Check for any error handling or validation around headerOrFooterTexts
rg -B 5 -A 5 "headerOrFooterTexts" --type java

Length of output: 4340

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

128-130: Consistent usage of renderCellTextContent with obtainCellFunction

In the getGridFooters method, renderCellTextContent is called with null for obtainCellFunction. Ensure that passing null is appropriate and that the method handles this case without issues. If footer cells might require custom handling similar to headers, consider implementing an appropriate function.


Line range hint 134-157: Validate null handling in renderCellTextContent method

The method now accepts a SerializableFunction<Column<T>, String> obtainCellFunction. Confirm that when obtainCellFunction is null, the method correctly defaults to the existing logic without causing exceptions. Additionally, verify that the method retrieves the correct text content for both headers and footers when components are involved.


26-34: Imports align with new functionality

The added imports for HeaderRow and SerializableFunction are necessary for handling multiple header rows and custom cell rendering functions. This aligns with the new features introduced.


104-121: ⚠️ Potential issue

Ensure proper handling of header texts in getHeaderTexts method

The new method getHeaderTexts aggregates header texts from multiple HeaderRow instances. Please verify that it correctly handles scenarios where header cells might contain components without text, empty strings, or null values to prevent potential NullPointerExceptions or incorrect header representations.

Consider adding unit tests to cover cases such as:

  • Headers with empty or null text.
  • Headers containing only components.
  • Grids with varying numbers of header rows.

Copy link
Member

@javier-godoy javier-godoy left a comment

Choose a reason for hiding this comment

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

🐇

Add support for multiple header rows only for excel files
Copy link

@mlopezFC mlopezFC requested a review from javier-godoy October 29, 2024 18:31
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: 2

🧹 Outside diff range and nitpick comments (6)
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (4)

46-46: Consider a more specific page title.

The current page title "Multiple Header Rows" is too generic. Consider making it more specific to the grid exporter context, e.g., "Grid Exporter - Multiple Header Rows Demo".


64-64: Remove or replace the "Big column".

The column with random Lorem ipsum text doesn't contribute to demonstrating the multiple header rows functionality. Consider removing it or replacing it with a more meaningful example that showcases the feature's practical use case.


67-73: Document data generation strategy.

The data generation logic includes specific probabilities and ranges that would benefit from explanatory comments. Consider documenting:

  • Why 30% of records have null last names
  • The significance of the budget range (10000-100000)
  • The reason for generating exactly 100 records

103-104: Enhance export file name.

The current file name "GridExport" is generic. Consider including more context about the exported data, such as:

  • The type of data (People)
  • Number of records
  • Export format (Excel/Word)

Example: "PeopleReport_100Records_"

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

98-103: Add API documentation for the new return type.

Since BaseStreamResourceWriter will be exposed as public API in the future, this method should be properly documented to explain:

  1. The structure of the returned list
  2. The relationship between the list of strings and header rows
  3. The order of header texts in the list

Add JavaDoc:

+  /**
+   * Returns a list of pairs containing header texts and their corresponding columns.
+   * Each pair contains a list of header texts (one for each header row) and the associated column.
+   * The header texts are ordered from top to bottom header row.
+   *
+   * @param grid the grid to get headers from
+   * @return list of pairs containing header texts and columns
+   */
   protected List<Pair<List<String>, Column<T>>> getGridHeaders(Grid<T> grid) {
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (1)

414-419: LGTM: Clean adapter implementation for footer handling

The method efficiently converts single-row footers to the new multi-row format while maintaining backward compatibility.

Consider adding a Javadoc comment to clarify the adapter role of this method:

/**
 * Adapter method that converts single-row footer data to the multi-row format
 * for backward compatibility with existing footer implementations.
 */
private void fillFooter(Sheet sheet, Cell headersOrFootersCell,
    List<Pair<String, Column<T>>> headersOrFooters, boolean isHeader) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d704168 and 5cc6d15.

📒 Files selected for processing (5)
  • 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 (3 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterDemoView.java (1 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterDemoView.java
🧰 Additional context used
📓 Learnings (2)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (2)
Learnt from: javier-godoy
PR: FlowingCode/GridExporterAddon#119
File: src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java:77-93
Timestamp: 2024-06-05T20:11:58.436Z
Learning: User javier-godoy requested to open a follow-up GitHub issue to discuss resource management in the refactored code of CsvStreamResourceWriter, highlighting the absence of try-with-resources in the previous implementation.
Learnt from: javier-godoy
PR: FlowingCode/GridExporterAddon#154
File: src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java:98-103
Timestamp: 2024-10-28T17:35:31.077Z
Learning: `BaseStreamResourceWriter` and its extending classes are not public API currently, but the return type must be refactored as we are going to expose `BaseStreamResourceWriter` in the near future.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (1)
Learnt from: mlopezFC
PR: FlowingCode/GridExporterAddon#154
File: src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java:428-429
Timestamp: 2024-10-29T18:31:41.821Z
Learning: In `ExcelStreamResourceWriter.java`, the `headerOrFooterTexts` variable in the `fillHeaderOrFooter` method cannot be null, so adding null checks for it is unnecessary.
🪛 ast-grep
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java

[warning] 59-60: Detected a cookie where the HttpOnly flag is either missing or disabled. The HttpOnly cookie flag instructs the browser to forbid client-side JavaScript to read the cookie. If JavaScript interaction is required, you can ignore this finding. However, set the HttpOnly flag to true` in all other cases.
Context: (
LitRenderer.of("${item.name}").withProperty("name", Person::getName))
Note: [CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 88-88: Detected a cookie where the HttpOnly flag is either missing or disabled. The HttpOnly cookie flag instructs the browser to forbid client-side JavaScript to read the cookie. If JavaScript interaction is required, you can ignore this finding. However, set the HttpOnly flag to true` in all other cases.
Context: (new Span(columnHeader + " 1"))
Note: [CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 90-90: Detected a cookie where the HttpOnly flag is either missing or disabled. The HttpOnly cookie flag instructs the browser to forbid client-side JavaScript to read the cookie. If JavaScript interaction is required, you can ignore this finding. However, set the HttpOnly flag to true` in all other cases.
Context: (new Span(columnHeader + " 2"))
Note: [CWE-1004]: Sensitive Cookie Without 'HttpOnly' Flag [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 59-60: Detected a cookie where the Secure flag is either missing or disabled. The Secure cookie flag instructs the browser to forbid sending the cookie over an insecure HTTP request. Set the Secure flag to true so the cookie will only be sent over HTTPS.
Context: (
LitRenderer.of("${item.name}").withProperty("name", Person::getName))
Note: [CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 88-88: Detected a cookie where the Secure flag is either missing or disabled. The Secure cookie flag instructs the browser to forbid sending the cookie over an insecure HTTP request. Set the Secure flag to true so the cookie will only be sent over HTTPS.
Context: (new Span(columnHeader + " 1"))
Note: [CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration


[warning] 90-90: Detected a cookie where the Secure flag is either missing or disabled. The Secure cookie flag instructs the browser to forbid sending the cookie over an insecure HTTP request. Set the Secure flag to true so the cookie will only be sent over HTTPS.
Context: (new Span(columnHeader + " 2"))
Note: [CWE-614]: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute [OWASP A05:2021]: Security Misconfiguration [REFERENCES]
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration

🔇 Additional comments (5)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (3)

26-26: LGTM!

The new imports are appropriate for supporting multiple header rows functionality.

Also applies to: 34-34


Line range hint 134-157: LGTM! Well-structured text content rendering.

The implementation:

  • Maintains backward compatibility with existing header/footer handling
  • Properly separates concerns between text extraction and component handling
  • Includes appropriate error handling

104-121: Verify handling of empty header rows.

The implementation looks good but consider these edge cases:

  1. Grid with no header rows
  2. Header rows with mixed content (some cells with text, some with components)
  3. Header rows with null cells
✅ Verification successful

Let me search for test files and header row related code to verify the edge cases.


Let me examine the implementation details and test scenarios to verify the edge case handling.


Edge cases are properly handled in the implementation

The code already handles the key edge cases appropriately:

  • Empty header rows: The getHeaderRows() returns a list which is safely iterated
  • Mixed content: The code first checks for direct text via getText(), then falls back to component text if blank
  • Null components: There's an explicit null check before accessing component text (if (component != null))

The demo code also validates the implementation by testing with both text and component-based header cells.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test cases covering header row edge cases
rg -l "getHeaderRows|setHeaderRows" --type java test/

Length of output: 101


Script:

#!/bin/bash
# Search for test files in the entire repository
fd ".*Test\.java$"

# Search for header row related tests in all java files
rg -l "getHeaderRows|setHeaderRows" --type java

Length of output: 421


Script:

#!/bin/bash
# Check the demo file for header row test scenarios
rg -A 10 "getHeaderRows|setHeaderRows" src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java

# Look for any null checks or edge case handling in the main implementation
rg -A 5 "headerRows|headerRow" src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java

Length of output: 1464

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

98-98: LGTM: Header structure supports multiple rows

The updated return type List<Pair<List<String>, Column<T>>> correctly implements the multiple header rows feature.


420-438: Verify impact of row shifting on existing content

The row shifting implementation correctly handles multiple header rows, but we should verify its impact on existing sheet content.

Let's check for potential issues with row shifting in the codebase:

✅ Verification successful

Let me gather more context about how the row shifting is used in the codebase.


Let me check how the sheet content is managed before and after the row shifting to better understand the impact.


Based on the code analysis, I can now provide a final response about the row shifting implementation:

Row shifting implementation is safe and properly managed

The implementation correctly handles content preservation because:

  • Row shifting is performed only once per operation and only when necessary (headerOrFooterTexts.size() > 1)
  • Existing content is properly preserved through careful row management:
    • New rows are created only when needed (row == null check)
    • Cell styles and content are properly maintained
    • The shift operation is performed before populating the new content
  • The implementation follows Apache POI's recommended patterns for row manipulation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any tests or code that might be affected by row shifting
rg -l "shiftRows|getLastRowNum" --type java

Length of output: 133


Script:

#!/bin/bash
# Get more context around shiftRows usage
rg "shiftRows" -B 5 -A 5 --type java

# Also check for any test cases
fd "Test.*\.java" --exec rg -l "shiftRows|getLastRowNum" {}

Length of output: 1485


Script:

#!/bin/bash
# Get broader context around the sheet content management
rg "sheet\.(create|get)Row|getLastRowNum" -B 3 -A 3 --type java

# Also check for any cell content management
rg "cell\.(get|set)Value|setCellStyle" -B 3 -A 3 --type java

Length of output: 11729

@javier-godoy javier-godoy merged commit e963f24 into master Oct 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pending release
Development

Successfully merging this pull request may close these issues.

2 participants