Skip to content

Conversation

@ManojTestsigma
Copy link
Contributor

@ManojTestsigma ManojTestsigma commented Dec 17, 2025

please review this addon and publish as PUBLIC

Addon name : csv_file_update_from_upload_section
Addon accont: https://jarvis.testsigma.com/ui/tenants/2817/addons
Jira: https://testsigma.atlassian.net/browse/CUS-9787

fix

Added 4 New Nlps, 2 Nlp's to clear cell value at given index, 1 Nlp to write contents in a cell, 1 Nlp to read the contents
Updated existing class to use 1-based indexing.

Summary by CodeRabbit

  • New Features

    • Added CSV cell deletion action (delete value at specified row/column).
    • Added CSV cell deletion with updated file path storage.
    • Added CSV cell value reader action (retrieve and store in variable).
    • Added CSV cell value writer action (update cell content).
    • Added support for both local files and HTTP(S) URLs across all CSV operations.
  • Chores

    • Updated project version to 1.0.5.
    • Updated commons-lang3 dependency to 3.17.0.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

Walkthrough

This PR updates project and dependency versions, introduces four new CSV WebAction classes for cell manipulation (read, write, delete operations) with local file and HTTP(S) URL support, and enhances input validation in an existing CSV handler class.

Changes

Cohort / File(s) Summary
Build Configuration
csv_file_update_from_upload_section/pom.xml
Updated project version from 1.0.1 to 1.0.5; upgraded commons-lang3 dependency from 3.14.0 to 3.17.0.
New CSV Delete Operations
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsv.java, csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsvAndStorePath.java
Added two new WebAction classes for deleting cell content from CSV files. First class writes changes back to the original file; second class stores the updated file path in a runtime variable. Both support local paths and HTTP(S) URLs with 1-based row/column indexing.
New CSV Read/Write Operations
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/ReadCellValueFromCsv.java, csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCellValueInCsv.java
Added two new WebAction classes: one reads a cell value and stores it in a runtime variable; the other writes a value to a cell. Both validate 1-based indices, support local and URL-based CSV sources, and handle bounds checking.
Enhanced CSV Handling
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java
Improved input validation for row and column numbers with explicit 1-based minimum checks; enhanced error handling and messaging; preserved original user inputs for user-facing messages while converting to 0-based indices internally.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Multiple new implementations: Four new WebAction classes follow similar patterns but require individual logic verification
  • Consistent error handling: URL resolution, CSV parsing, and bounds validation appear across all new classes
  • Enhanced validation: WriteCsvFileandStorePath modifications add robustness but maintain existing functionality
  • Special attention areas:
    • CSV row/column bounds validation logic across all four new classes
    • URL-to-file conversion implementation consistency (helper methods in each class)
    • Error message formatting and resource cleanup (CSVReader/CSVWriter closing patterns)

Possibly related PRs

Suggested reviewers

  • Ganesh-Testsigma
  • vigneshtestsigma

Poem

🐰 CSV cells dance at my command,
Reading, writing, deleting with a hop so grand,
URLs and paths both find their way,
1-based indexing saves the day,
A fluffy refactor—hooray!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references clearing a cell value from a CSV, which is the primary focus of two of the four new NLPs added, but the PR introduces broader functionality including reading and writing cell values.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch CUS-9787

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)

169-191: Add cleanup for temporary files downloaded from URLs.

Similar to other files in this PR, temporary files created from URLs via convertToFile are not cleaned up. This can lead to disk space exhaustion over time.

Consider adding tempFile.deleteOnExit() after creating the temp file on line 187, or implement explicit cleanup logic.

Also note that this convertToFile method differs slightly from urlToCSVFileConverter used in other files. Consider consolidating these into a single shared utility method as mentioned in comments on other files.

♻️ Duplicate comments (3)
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsv.java (1)

74-74: Consolidate duplicated URL-to-file conversion logic.

This file contains the same issues as ReadCellValueFromCsv.java:

  • The urlToCSVFileConverter method is duplicated
  • Hard-coded "csvFileName" parameter
  • Temporary files are not cleaned up

Refer to the comments on ReadCellValueFromCsv.java for detailed recommendations. Consider extracting this to a shared utility class.

Also applies to: 127-149

csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCellValueInCsv.java (2)

77-77: Consolidate duplicated code and fix temp file cleanup.

This file has the same issues identified in ReadCellValueFromCsv.java and DeleteRowContentFromCsv.java:

  • urlToCSVFileConverter method duplication
  • Hard-coded "csvFileName" parameter
  • Missing temporary file cleanup

Please refer to the detailed comments on ReadCellValueFromCsv.java for recommended solutions.

Also applies to: 130-152


100-107: Use atomic file replacement pattern.

Similar to DeleteRowContentFromCsv.java, writing directly to the CSV file could cause data corruption if concurrent modifications occur or if the process crashes mid-write.

Consider adopting the pattern used in WriteCsvFileandStorePath and DeleteRowContentFromCsvAndStorePath, which use a temporary file and atomic copy operations.

🧹 Nitpick comments (4)
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/ReadCellValueFromCsv.java (3)

82-82: Replace hard-coded filename with a meaningful value.

The parameter "csvFileName" is a hard-coded placeholder. Consider deriving a meaningful name from the URL or using a descriptive prefix.

Apply this diff:

-            File tempFile = urlToCSVFileConverter("csvFileName", filePathString);
+            File tempFile = urlToCSVFileConverter("csv_download", filePathString);

146-151: Use appropriate log level for error conditions.

Lines 146 and 151 use logger.info for error conditions. Use logger.error or logger.warn for exceptions and failures.

Apply this diff:

         } catch (Exception e) {
-            logger.info("Error while accessing: " + url);
+            logger.error("Error while accessing: " + url, e);
             throw new RuntimeException("Unable to access or validate the CSV file. Please check the inputs.", e);
         }

96-96: Remove redundant bounds check.

The condition rowIndex < rows.size() is sufficient. The check rowIndex >= 0 is redundant since line 66 already validates targetRow >= 1, ensuring rowIndex = targetRow - 1 >= 0.

Apply this diff:

-            if (rowIndex < rows.size()) {
+            if (rowIndex < rows.size()) {

Actually, the current code already has the correct logic. Consider this a note that rowIndex >= 0 is always true and could be removed from similar checks in other files for clarity.

csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)

125-125: Address the inline comment about logger usage.

The comment suggests using logger.error for exceptions, but the code still uses logger.warn. Either update the code to match the comment or remove the comment if logger.warn is the intended level.

Apply this diff:

-                logger.warn("Error processing CSV file: " + e); // Use logger.error for exceptions
+                logger.error("Error processing CSV file: " + e);
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d22206f and e641a7e.

📒 Files selected for processing (6)
  • csv_file_update_from_upload_section/pom.xml (2 hunks)
  • csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsv.java (1 hunks)
  • csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsvAndStorePath.java (1 hunks)
  • csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/ReadCellValueFromCsv.java (1 hunks)
  • csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCellValueInCsv.java (1 hunks)
  • csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (7 hunks)
🔇 Additional comments (4)
csv_file_update_from_upload_section/pom.xml (1)

9-9: LGTM!

The version bump to 1.0.5 and the commons-lang3 upgrade to 3.17.0 align with the new CSV manipulation features being added.

Also applies to: 78-78

csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)

57-76: LGTM!

The addition of robust input validation for row and column numbers is well-implemented. The validation ensures numeric inputs and enforces 1-based indexing constraints with clear error messages.

csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsvAndStorePath.java (2)

80-158: LGTM - Good use of atomic file replacement pattern!

This implementation correctly uses a temporary file and Files.copy with REPLACE_EXISTING to atomically replace the original file. This approach prevents data corruption from concurrent modifications or crashes mid-write, which is superior to the direct file write approach used in DeleteRowContentFromCsv and WriteCellValueInCsv.


153-153: Add missing space in log message.

The log message is missing a space after the colon.

Apply this diff:

-                logger.info("Successfully copied content to original file: " + csvFile.getAbsolutePath());
+                logger.info("Successfully copied content to original file: " + csvFile.getAbsolutePath());

Wait, checking the code again... the message already has the space. This is correct. Disregard this comment.

Comment on lines +97 to +104
try (CSVWriter writer = new CSVWriter(new FileWriter(csvFilePath))) {
writer.writeAll(rows);
} catch (IOException e) {
logger.warn("Error writing to CSV file: " + ExceptionUtils.getStackTrace(e));
setErrorMessage("Error writing to CSV file: " + e.getMessage());
result = com.testsigma.sdk.Result.FAILED;
return result;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Potential data loss if concurrent modifications occur.

When processing a URL-based CSV, the downloaded temp file is modified and written back to the same temp file. For local file paths, writing back to the original file could cause data corruption if multiple actions run concurrently or if the process crashes mid-write.

Consider using the same pattern as DeleteRowContentFromCsvAndStorePath and WriteCsvFileandStorePath, which create a separate temporary file for the modified content and then copy it back atomically using Files.copy with StandardCopyOption.REPLACE_EXISTING.

🤖 Prompt for AI Agents
In
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsv.java
around lines 97 to 104, the current code writes modified CSV rows directly back
to the same file which risks data loss/corruption on concurrent runs or crashes;
change the logic to write to a new temporary file (use Files.createTempFile or
the same temp pattern used in DeleteRowContentFromCsvAndStorePath and
WriteCsvFileandStorePath), close the writer, then atomically replace the
original target file by copying the temp file to the original path with
Files.copy(tempPath, originalPath, StandardCopyOption.REPLACE_EXISTING); ensure
proper try-with-resources, exception handling, and cleanup of the temp file in
finally so partial writes do not corrupt the original.

Comment on lines +176 to +198
private File convertToFile(String pathOrUrl) throws IOException {
if (pathOrUrl.startsWith("https://") || pathOrUrl.startsWith("http://")) {
// Extract the original file name from the URL
String originalFileName = FilenameUtils.getName(new URL(pathOrUrl).getPath());
// Generate a unique file name by appending a timestamp
String uniqueFileName = "temp_" + System.currentTimeMillis() + "_" + originalFileName;
logger.info("Given is a URL... Original file name: " + originalFileName + ", Unique file name: "
+ uniqueFileName);

// Create the full path for the temporary file
String filePath = String.format("%s%s%s", FileUtils.getTempDirectoryPath(), File.separator, uniqueFileName);
File tempFile = new File(filePath);

// Download the file from the URL to the temporary location
FileUtils.copyURLToFile(new URL(pathOrUrl), tempFile, 10000, 10000);
logger.info("Temp file created for URL file: " + uniqueFileName + " at path " + filePath);

return tempFile;
} else {
logger.info("Given is a local file path...");
return new File(pathOrUrl);
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Consolidate convertToFile with similar methods and add temp file cleanup.

The convertToFile method is duplicated in WriteCsvFileandStorePath. Additionally, this method is functionally similar to urlToCSVFileConverter used in other CSV action classes, though with slightly different implementation details.

  1. Extract this method to a shared utility class to eliminate duplication
  2. Add tempFile.deleteOnExit() after line 187 to clean up downloaded files
  3. Consider adding connection/read timeouts to FileUtils.copyURLToFile (note: this file already has 10-second timeouts on line 190, which is good)
🤖 Prompt for AI Agents
In
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/DeleteRowContentFromCsvAndStorePath.java
around lines 176 to 198, the convertToFile method is duplicated elsewhere and
lacks automatic cleanup of downloaded temp files; extract this logic into a
shared utility class (e.g., CsvFileUtils or FileDownloadUtils) and replace
duplicate implementations in WriteCsvFileandStorePath and other CSV action
classes with calls to the new utility, add tempFile.deleteOnExit() immediately
after creating the tempFile (after line 187) so downloaded files are scheduled
for removal, and keep the existing FileUtils.copyURLToFile call with the 10s
connect/read timeouts (or make them configurable in the utility) to avoid
blocking.

Comment on lines +132 to +154
public File urlToCSVFileConverter(String fileName, String url) {
try {
logger.info("Given is URL... File name: " + fileName);
URL urlObject = new URL(url);

// Extract file extension if present
String baseName = fileName;
String extension = ".csv"; // default csv format
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex > 0) {
baseName = fileName.substring(0, lastDotIndex);
extension = fileName.substring(lastDotIndex);
}

File tempFile = File.createTempFile(baseName, extension);
FileUtils.copyURLToFile(urlObject, tempFile);
logger.info("CSV file created: " + tempFile.getAbsolutePath());
return tempFile;
} catch (Exception e) {
logger.info("Error while accessing: " + url);
throw new RuntimeException("Unable to access or validate the CSV file. Please check the inputs.", e);
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Extract duplicated helper method to a shared utility class.

The urlToCSVFileConverter method is duplicated across ReadCellValueFromCsv, DeleteRowContentFromCsv, and WriteCellValueInCsv. Additionally, WriteCsvFileandStorePath and DeleteRowContentFromCsvAndStorePath have a similar convertToFile method with slightly different implementation.

Consider creating a shared utility class (e.g., CsvFileHelper) to consolidate these URL-to-file conversion methods and ensure consistent behavior across all CSV actions.

🤖 Prompt for AI Agents
In
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/ReadCellValueFromCsv.java
around lines 132 to 154, the urlToCSVFileConverter implementation is duplicated
across multiple classes; extract this logic into a new shared utility class
(e.g., com.testsigma.addons.web.util.CsvFileHelper) with a single public static
method (e.g., urlToCSVFileConverter(String fileName, String url)) that contains
the file-extension extraction, temp file creation, FileUtils.copyURLToFile call,
consistent logging, and exception wrapping; replace the duplicated methods in
ReadCellValueFromCsv, DeleteRowContentFromCsv, WriteCellValueInCsv,
WriteCsvFileandStorePath, and DeleteRowContentFromCsvAndStorePath with calls to
CsvFileHelper.urlToCSVFileConverter, keep identical behavior (default .csv
extension, same log messages, and same RuntimeException wrapping) and add a
small unit test for the helper to validate extension handling and URL copy.

⚠️ Potential issue | 🟠 Major

Add cleanup for temporary files created from URLs.

Temporary files downloaded from URLs are not cleaned up, which can lead to disk space exhaustion over time.

Consider one of these approaches:

  1. Call tempFile.deleteOnExit() after creating the temp file
  2. Use try-with-resources with a custom AutoCloseable wrapper
  3. Explicitly delete the file in a finally block after CSV processing completes

Example:

 File tempFile = File.createTempFile(baseName, extension);
+tempFile.deleteOnExit();
 FileUtils.copyURLToFile(urlObject, tempFile);
🤖 Prompt for AI Agents
In
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/ReadCellValueFromCsv.java
around lines 132 to 154, the method creates temporary files from URLs but never
schedules or performs cleanup; to fix this, after creating the tempFile call
tempFile.deleteOnExit() to ensure JVM cleans it up as a minimal change, or
alternatively (preferred for long-running processes) change the API so the
caller is responsible for deletion (document it) or provide a try-with-resources
style wrapper/AutoCloseable that deletes the file in close() so the file is
explicitly deleted after CSV processing completes.

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