-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add dynamic file type support for catalog uploads (CSV, JSON, JSONL) additional changes #178
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
Conversation
* validates .csv, .json and .jsonl * derive the file extension from the uploaded file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for multiple file formats (CSV, JSON, JSONL) for catalog uploads in the Constructor.io client. Previously, only CSV format was supported; now the client dynamically detects and validates file extensions to accept JSON and JSONL formats as well.
Key Changes
- File extension validation for catalog uploads now supports
.csv,.json, and.jsonlextensions - Test utilities were added to generate temporary JSON/JSONL files for comprehensive test coverage
- Updated catalog operation methods with improved documentation reflecting multi-format support
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
Utils.java |
Added helper methods to create temporary JSON/JSONL test files and invalid files for validation testing |
ConstructorIOCatalogTest.java |
Added extensive test coverage for JSON/JSONL formats, validation edge cases, and mixed file type scenarios |
ConstructorIO.java |
Implemented file extension validation logic and updated catalog methods to support multiple formats |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| @Test | ||
| public void UpdateCatalogWithInvalidExtensionShouldError() throws Exception { |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test method has the same name as the test at line 509 (UpdateCatalogWithNoExtensionShouldError), but its implementation mirrors the test at line 492 (ReplaceCatalogWithInvalidExtensionShouldError). The test should be renamed to clearly indicate it tests updateCatalog with invalid extension, differentiating it from the other tests.
Code Review SummaryThis PR adds dynamic file type support for catalog uploads (CSV, JSON, JSONL) to the Constructor.io Java client. The implementation is solid and well-tested, with comprehensive test coverage for various scenarios. The code demonstrates good defensive programming practices with proper validation and error handling. Detailed FeedbackStrengths✅ Excellent validation logic - The ✅ Comprehensive test coverage - 18 new test cases covering:
✅ Backward compatibility - CSV files continue to work as before, with JSON/JSONL added seamlessly. ✅ Clear documentation - Javadoc comments properly document the new functionality and supported formats. Issues and Recommendations[File: 🔴 Critical: Incomplete code - Missing method body The public static File createNoExtensionFile() throws IOException {
File file = File.createTempFile("items", "");
file.deleteOnExit();
try (FileWriter writer = new FileWriter(file)) {
writer.write("This is a file with no extension for catalog upload testing.");
}
return file;
}Action required: Verify the complete implementation was committed. [File: 💡 Minor: Consider Arrays.asList vs explicit LinkedHashSet The use of Current: private static final Set<String> VALID_CATALOG_EXTENSIONS =
new LinkedHashSet<>(Arrays.asList(".csv", ".json", ".jsonl"));Simpler alternative: private static final Set<String> VALID_CATALOG_EXTENSIONS =
new HashSet<>(Arrays.asList(".csv", ".json", ".jsonl"));Or if ordering in error messages is important (which it appears to be for consistency), the current approach is fine. Just note that [File: The extension is converted to lowercase for comparison: String extension = actualFileName.substring(lastDotIndex).toLowerCase();This is good for case-insensitive matching, but consider documenting this behavior in the Javadoc so users know that Suggestion: Add to the method Javadoc: * Note: Extension matching is case-insensitive (.CSV, .csv, .Csv are all valid)[File: 📝 Code style: Diamond operator Minor style improvement - use diamond operator for better readability: Current: List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();Recommended: List<Map<String, Object>> items = new ArrayList<>();This applies to multiple locations in the file (lines 121, 138, 161, 184, 208, etc.). [File: 💡 Test cleanup: Potential resource leak prevention The cleanup logic is good, but consider using a more defensive approach that won't fail if any file is null: @After
public void teardown() throws Exception {
deleteFileIfExists(itemsFile);
deleteFileIfExists(variationsFile);
deleteFileIfExists(itemGroupsFile);
deleteFileIfExists(jsonItemsFile);
deleteFileIfExists(jsonVariationsFile);
deleteFileIfExists(jsonlItemsFile);
deleteFileIfExists(jsonlVariationsFile);
deleteFileIfExists(jsonlItemGroupsFile);
deleteFileIfExists(invalidExtensionFile);
deleteFileIfExists(noExtensionFile);
deleteFileIfExists(csvFolder);
}
private void deleteFileIfExists(File file) {
if (file != null && file.exists()) {
file.delete();
}
}This is more robust if any test setup fails partway through. [General] 📊 Test coverage suggestion Consider adding tests for:
These would further strengthen the validation logic. [General] 📖 Documentation opportunity Consider updating the README or adding a code example showing how to use the new JSON/JSONL format support. This would help users understand the feature without diving into the code. ConclusionThis is a well-implemented feature with strong validation logic and comprehensive test coverage. The code is production-ready with only minor improvements suggested. The most critical item is verifying that the Recommendation: Approve with minor fixes ✅ Great work on the thorough testing and defensive validation! |
Code Review SummaryThis PR adds dynamic file type support for catalog uploads, expanding from CSV-only to support CSV, JSON, and JSONL formats. The implementation is well-structured with a new validation method, comprehensive test coverage, and clear documentation. The changes maintain backward compatibility while introducing the new functionality cleanly. Overall Assessment: The code quality is high, but there are a few important issues that should be addressed before merging. Critical Issues[File: ConstructorIO.java Line: L38] - LinkedHashSet Import Usage
[File: ConstructorIO.java Line: L2070] - Lowercase Extension Not Preserved in Multipart Upload
[File: Utils.java Line: L122] - Gson Instance as Static Field Without Thread-Safety Consideration
Minor Issues and Suggestions[File: ConstructorIO.java Line: L2050] - Redundant Null Check
[File: Utils.java Lines: L123-L167] - Code Duplication in File Creation Methods
[File: ConstructorIOCatalogTest.java Line: L172] - Mixed Format Test Uses Hardcoded Path
Positive Observations
Testing Recommendations
ConclusionThis is a solid implementation that adds valuable functionality to the library. The core logic is sound, test coverage is comprehensive, and the code is generally well-written. Please address the critical issues around LinkedHashSet usage and the lowercase extension behavior, and consider the minor suggestions for code quality improvements. Once these issues are addressed, this PR will be ready to merge. Great work on maintaining backward compatibility and providing thorough test coverage! |
Alexey-Pavlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
constructorio-client/src/test/java/io/constructor/client/ConstructorIOCatalogTest.java
Outdated
Show resolved
Hide resolved
Code Review SummaryThis PR adds dynamic file type support for catalog uploads, extending the existing CSV-only implementation to support JSON and JSONL formats. The implementation introduces validation logic for file extensions and adds comprehensive test coverage. Overall, the code is well-structured and thoroughly tested. Detailed Feedback[File:
|
Alexey-Pavlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
No description provided.