-
Notifications
You must be signed in to change notification settings - Fork 3
Added validation for uploaded file in create artifact log #78
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,8 +116,7 @@ | |
| <service verb="create" noun="ArtifactLog"> | ||
| <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 --> | ||
| <parameter name="uploadedFile" type="org.apache.commons.fileupload.FileItem" required="false"/> | ||
| </in-parameters> | ||
| <out-parameters> | ||
| <parameter name="filePath"/> | ||
|
|
@@ -133,33 +132,40 @@ | |
| </entity-find-count> | ||
| <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)"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complex validation And what is this |
||
| <return error="true" message="Either an uploaded file or an event message must be provided to create an Artifact Log."/> | ||
| </if> | ||
| <set field="result" from="[:]"/> | ||
| <set field="fileName" from="uploadedFile.getName()"/> | ||
| <set field="dateTime" from="ec.l10n.format((ec.user.nowTimestamp), 'yyyy-MM-dd-HH-mm-ss-SSS')"/> | ||
| <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')"/> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary change |
||
| <set field="errorDate" from="errorDate ?: ec.user.nowTimestamp"/> | ||
| <set field="fileName" from="uploadedFile != null ? uploadedFile.getName() : null"/> | ||
| <set field="extIndex" from="fileName != null ? fileName.lastIndexOf('.') : -1"/> | ||
| <set field="fileFormat" from="extIndex != -1 ? fileName.substring(extIndex + 1) : null"/> | ||
| <set field="fileName" from="extIndex != -1 ? fileName.substring(0, extIndex) : fileName"/> | ||
| <!-- Validate file extension if file exists --> | ||
| <if condition="uploadedFile != null && uploadedFile.getSize() > 0 && extIndex == -1"> | ||
| <return error="true" message="No file extension found. Supported extensions are: .csv, .json"/> | ||
| </if> | ||
|
|
||
| <set field="fileFormat" from="fileName.substring(extIndex + 1)"/> | ||
| <set field="fileName" from="fileName.substring(0, extIndex)"/> | ||
|
|
||
| <if condition="!'csv'.equals(fileFormat) && !'json'.equals(fileFormat)"> | ||
| <return message=".${fileFormat} file format is not supported. Please upload a CSV or JSON file."/> | ||
| <if condition="uploadedFile != null && uploadedFile.getSize() > 0 && !'csv'.equals(fileFormat) && !'json'.equals(fileFormat)"> | ||
| <return error="true" message=".${fileFormat} file format is not supported. Please upload a CSV or JSON file."/> | ||
| </if> | ||
|
|
||
| <set field="errorDate" from="errorDate ?: ec.user.nowTimestamp"/> | ||
| <!-- Generate file path if file exists --> | ||
| <set field="logFilePath" from="uploadedFile != null ? 'runtime://ArtifactLogs/' + fileName + '_' + dateTime + '.' + fileFormat : null"/> | ||
| <set field="fileReference" from="uploadedFile != null ? ec.resource.getLocationReference(logFilePath) : null"/> | ||
|
|
||
| <set field="logFilePath" type="String" value="runtime://ArtifactLogs/${fileName}_${dateTime}.${fileFormat}"/> | ||
| <set field="fileReference" from="ec.resource.getLocationReference(logFilePath)"/> | ||
|
Comment on lines
157
to
158
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines are redundant and will cause issues when no file is uploaded. The |
||
|
|
||
| <script><![CDATA[ | ||
| fileStream = uploadedFile.getInputStream() | ||
| if (uploadedFile != null && uploadedFile.getSize() > 0) { | ||
| fileStream = uploadedFile.getInputStream() | ||
| try { | ||
| fileReference.putStream(fileStream) | ||
| } finally { | ||
| fileStream.close() | ||
| } | ||
| } | ||
| ]]></script> | ||
|
|
||
| <entity-make-value entity-name="co.hotwax.alc.ArtifactLog" value-field="artifactLogValue" map="context"/> | ||
|
|
||
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.
Unnecessary change, removed the comment note.