Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions service/co/hotwax/alc/ArtifactLifeCycleServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Copy link
Copy Markdown
Contributor

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.

<parameter name="uploadedFile" type="org.apache.commons.fileupload.FileItem" required="false"/>
</in-parameters>
<out-parameters>
<parameter name="filePath"/>
Expand All @@ -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) &amp;&amp; ec.util.isEmpty(eventMessage)">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Complex validation

And what is this ec.util.isEmpty()? Does this method even exist?

<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')"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 &amp;&amp; uploadedFile.getSize() &gt; 0 &amp;&amp; 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) &amp;&amp; !'json'.equals(fileFormat)">
<return message=".${fileFormat} file format is not supported. Please upload a CSV or JSON file."/>
<if condition="uploadedFile != null &amp;&amp; uploadedFile.getSize() &gt; 0 &amp;&amp; !'csv'.equals(fileFormat) &amp;&amp; !'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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

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.


<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"/>
Expand Down