Added validation for uploaded file in create artifact log#78
Added validation for uploaded file in create artifact log#78parnikarangnekar wants to merge 1 commit intodevelopfrom
Conversation
Summary of ChangesHello @parnikarangnekar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds necessary validation for file uploads when creating an artifact log. It correctly makes the uploadedFile parameter optional and ensures that either a file or an eventMessage is provided. The logic to handle an optional file, including file extension validation and file saving, is mostly well-implemented. However, I've found a critical issue with redundant code that could cause errors when no file is uploaded. Please see my detailed comment.
| <set field="logFilePath" type="String" value="runtime://ArtifactLogs/${fileName}_${dateTime}.${fileFormat}"/> | ||
| <set field="fileReference" from="ec.resource.getLocationReference(logFilePath)"/> |
There was a problem hiding this comment.
These lines are redundant and will cause issues when no file is uploaded. The logFilePath and fileReference variables are already correctly set on lines 154-155, which handle the case where uploadedFile is null. These redundant lines will overwrite logFilePath with a malformed value (e.g., runtime://ArtifactLogs/null_..._....null) when no file is present, which will likely lead to an error. Please remove these two lines.
puru-khedre
left a comment
There was a problem hiding this comment.
The current changes does not look correct to me.
IMO, we just needed one conditional block that handles everything only when a file is uploaded. If no file is uploaded, none of the file-related handling should be executed.
| <in-parameters> | ||
| <auto-parameters entity-name="co.hotwax.alc.ArtifactLog" include="nonpk"/> | ||
| <parameter name="uploadedFile" type="org.apache.commons.fileupload.FileItem" required="true"/> | ||
| <!-- TODO: Do validation --> |
There was a problem hiding this comment.
Unnecessary change, removed the comment note.
| <if condition="userGroupCount == 0"><then><return error="true" message="You must be a member of the tenant group to create an Artifact Log"/></then></if> | ||
|
|
||
| <!-- Validate uploadedFile or eventMessage presence --> | ||
| <if condition="(uploadedFile == null || uploadedFile.getSize() == 0) && ec.util.isEmpty(eventMessage)"> |
There was a problem hiding this comment.
Complex validation
And what is this ec.util.isEmpty()? Does this method even exist?
| <set field="extIndex" from="fileName.lastIndexOf('.')"/> | ||
| <if condition="extIndex == -1"> | ||
| <return message="No file extension found. Please upload a file with an extension, Supported extensions are: .csv, .json" error="true"/> | ||
| <set field="dateTime" from="ec.l10n.format(ec.user.nowTimestamp, 'yyyy-MM-dd-HH-mm-ss-SSS')"/> |
Closes- #77