Skip to content

Commit a07d21c

Browse files
Changes
1 parent 941e3cb commit a07d21c

6 files changed

Lines changed: 99 additions & 31 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
2323
- Move attachments: Provides the capability to move attachments from one entity to another entity.
2424
- Attachment changelog: Provides the capability to view complete audit trail of attachments.
2525
- Localization of error messages and UI fields: Provides the capability to have the UI fields and error messages translated to the local language of the leading application.
26+
- Attachment Upload Status: Upload Status is the new field which displays the upload status of attachment when being uploaded.
27+
2628
## Table of Contents
2729

2830
- [Pre-Requisites](#pre-requisites)
@@ -40,6 +42,7 @@ This plugin can be consumed by the CAP application deployed on BTP to store thei
4042
- [Support for Link type attachments](#support-for-link-type-attachments)
4143
- [Support for Edit of Link type attachments](#support-for-edit-of-link-type-attachments)
4244
- [Support for Localization](#support-for-localization)
45+
- [Support for Upload Status](#support-for-uploadstatus)
4346
- [Known Restrictions](#known-restrictions)
4447
- [Support, Feedback, Contributing](#support-feedback-contributing)
4548
- [Code of Conduct](#code-of-conduct)
@@ -1240,6 +1243,31 @@ Example for german language
12401243
```
12411244
SDM.Attachments.maxCountError = Maximum number of attachments reached in German......
12421245
```
1246+
1247+
## Support for Attachment Upload Status
1248+
1249+
The attachment upload process displays a status indicator for each file being uploaded.
1250+
1251+
**For repositories without virus scanning:**
1252+
The upload status transitions from "Uploading" to "Success".
1253+
1254+
**For repositories with malware scanning:**
1255+
The upload status transitions from "Uploading" to "Success" if no virus is detected. If a virus is detected, the attachment is automatically deleted.
1256+
1257+
**For repositories with Trend Micro virus scanning:**
1258+
The upload status transitions from "Uploading" to "Virus Scanning in Progress". After refreshing the page, if the scan completes successfully and the attachment is virus-free, the status changes to "Success". If a virus is detected, the status changes to "Virus Detected" and the user must manually delete the file before saving the entity.
1259+
1260+
**Note:** Files with "Virus Scanning in Progress" or "Virus Detected" status cannot be downloaded or viewed.
1261+
1262+
To display color-coded status indicators in the UI, create a `sap.attachments-UploadScanStates.csv` file in the `db/data` folder with the following content:
1263+
```
1264+
code;name;criticality
1265+
uploading;Uploading;5
1266+
Success;Success;3
1267+
Failed;Scan Failed;1
1268+
VirusDetected;Virus detected;1
1269+
VirusScanInprogress;Virus scanning inprogress(refresh page);5
1270+
```
12431271
## Known Restrictions
12441272

12451273
- UI5 Version 1.135.0: This version causes error in upload of attachments.

sdm/src/main/java/com/sap/cds/sdm/constants/SDMConstants.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,17 @@ private SDMConstants() {
166166
"\"%s\" contains unsupported characters (‘/’ or ‘\\’). Rename and try again.";
167167
public static final String SINGLE_DUPLICATE_FILENAME =
168168
"An object named \"%s\" already exists. Rename the object and try again.";
169+
public static final String VIRUS_DETECTED_ERROR_MSG =
170+
"You can't save your changes because some files are unsafe. Delete the unsafe files manually before continuing. You can use a filter to help you find the affected files.";
171+
public static final String SCAN_FAILED_ERROR_MSG =
172+
"You can't save your changes because some files not scanned. Delete the unscanned files manually before continuing.";
173+
public static final String VIRUS_SCAN_IN_PROGRESS_ERROR_MSG =
174+
"Refresh the page to see scanning is completed.";
169175

170176
// Upload Status Constants
171177
public static final String UPLOAD_STATUS_SUCCESS = "Success";
172178
public static final String UPLOAD_STATUS_VIRUS_DETECTED = "VirusDetected";
173-
public static final String UPLOAD_STATUS_IN_PROGRESS = "UploadInProgress";
179+
public static final String UPLOAD_STATUS_IN_PROGRESS = "uploading";
174180
public static final String UPLOAD_STATUS_FAILED = "Failed";
175181
public static final String UPLOAD_STATUS_SCAN_FAILED = "Failed";
176182
public static final String VIRUS_SCAN_INPROGRESS = "VirusScanInprogress";
@@ -332,4 +338,55 @@ public static String getGenericError(String event) {
332338
public static String getVirusFilesError(String filename) {
333339
return String.format(VIRUS_ERROR, filename);
334340
}
341+
342+
public static String virusDetectedFilesMessage(List<String> files) {
343+
// Create the base message
344+
String prefixMessage = "We detected a virus, for the following files: \n\n";
345+
346+
// Initialize the StringBuilder with the formatted message prefix
347+
StringBuilder bulletPoints = new StringBuilder(prefixMessage);
348+
349+
// Append each file name to the StringBuilder
350+
for (String file : files) {
351+
bulletPoints.append(String.format("\t• %%s%%n", file));
352+
}
353+
bulletPoints.append(System.lineSeparator());
354+
bulletPoints.append(VIRUS_DETECTED_ERROR_MSG);
355+
356+
return bulletPoints.toString();
357+
}
358+
359+
public static String scanFailedFilesMessage(List<String> files) {
360+
// Create the base message
361+
String prefixMessage = "The virus scan failed, for the following files: \n\n";
362+
363+
// Initialize the StringBuilder with the formatted message prefix
364+
StringBuilder bulletPoints = new StringBuilder(prefixMessage);
365+
366+
// Append each file name to the StringBuilder
367+
for (String file : files) {
368+
bulletPoints.append(String.format("\t• %s%n", file));
369+
}
370+
bulletPoints.append(System.lineSeparator());
371+
bulletPoints.append(SCAN_FAILED_ERROR_MSG);
372+
373+
return bulletPoints.toString();
374+
}
375+
376+
public static String virusScanInProgressFilesMessage(List<String> files) {
377+
// Create the base message
378+
String prefixMessage = "The virus scanning is in progress for the following files: \n\n";
379+
380+
// Initialize the StringBuilder with the formatted message prefix
381+
StringBuilder bulletPoints = new StringBuilder(prefixMessage);
382+
383+
// Append each file name to the StringBuilder
384+
for (String file : files) {
385+
bulletPoints.append(String.format("\t• %s%n", file));
386+
}
387+
bulletPoints.append(System.lineSeparator());
388+
bulletPoints.append(VIRUS_SCAN_IN_PROGRESS_ERROR_MSG);
389+
390+
return bulletPoints.toString();
391+
}
335392
}

sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMCreateAttachmentsHandler.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,20 @@ private void processEntity(
195195
|| !scanFailedFiles.isEmpty()) {
196196
StringBuilder errorMessage = new StringBuilder();
197197
if (!virusDetectedFiles.isEmpty()) {
198-
errorMessage
199-
.append("Virus detected in the following file(s): ")
200-
.append(String.join(", ", virusDetectedFiles))
201-
.append(". Please delete them.");
198+
errorMessage.append(SDMConstants.virusDetectedFilesMessage(virusDetectedFiles));
202199
}
203200
if (!virusScanInProgressFiles.isEmpty()) {
204201
if (errorMessage.length() > 0) {
205202
errorMessage.append(" ");
206203
}
207-
errorMessage
208-
.append("Virus scanning is in progress for the following file(s): ")
209-
.append(String.join(", ", virusScanInProgressFiles))
210-
.append(". Please refresh the page to see the effect.");
204+
errorMessage.append(
205+
SDMConstants.virusScanInProgressFilesMessage(virusScanInProgressFiles));
211206
}
212207
if (!scanFailedFiles.isEmpty()) {
213208
if (errorMessage.length() > 0) {
214209
errorMessage.append(" ");
215210
}
216-
errorMessage
217-
.append("Scan failed for the following file(s): ")
218-
.append(String.join(", ", scanFailedFiles))
219-
.append(". Please delete the files and retry.");
211+
errorMessage.append(SDMConstants.scanFailedFilesMessage(scanFailedFiles));
220212
}
221213
throw new ServiceException(errorMessage.toString());
222214
}

sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMUpdateAttachmentsHandler.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,28 +207,19 @@ private void processAttachments(
207207
|| !scanFailedFiles.isEmpty()) {
208208
StringBuilder errorMessage = new StringBuilder();
209209
if (!virusDetectedFiles.isEmpty()) {
210-
errorMessage
211-
.append("Virus detected in the following file(s): ")
212-
.append(String.join(", ", virusDetectedFiles))
213-
.append(". Please delete them.");
210+
errorMessage.append(SDMConstants.virusDetectedFilesMessage(virusDetectedFiles));
214211
}
215212
if (!virusScanInProgressFiles.isEmpty()) {
216213
if (errorMessage.length() > 0) {
217214
errorMessage.append(" ");
218215
}
219-
errorMessage
220-
.append("Virus scanning is in progress for the following file(s): ")
221-
.append(String.join(", ", virusScanInProgressFiles))
222-
.append(". Please refresh the page to see the effect.");
216+
errorMessage.append(SDMConstants.virusScanInProgressFilesMessage(virusScanInProgressFiles));
223217
}
224218
if (!scanFailedFiles.isEmpty()) {
225219
if (errorMessage.length() > 0) {
226220
errorMessage.append(" ");
227221
}
228-
errorMessage
229-
.append("Scan failed for the following file(s): ")
230-
.append(String.join(", ", scanFailedFiles))
231-
.append(". Please delete the files and retry.");
222+
errorMessage.append(SDMConstants.scanFailedFilesMessage(scanFailedFiles));
232223
}
233224
throw new ServiceException(errorMessage.toString());
234225
}

sdm/src/main/resources/cds/com.sap.cds/sdm/attachments.cds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using {
88

99

1010
type UploadStatusCode : String(32) enum {
11-
UploadInProgress;
11+
uploading;
1212
Success;
1313
Failed;
1414
VirusDetected;
@@ -20,7 +20,7 @@ extend aspect Attachments with {
2020
objectId : String;
2121
linkUrl : String default null;
2222
type : String @(UI: {IsImageURL: true}) default 'sap-icon://document';
23-
uploadStatus : UploadStatusCode default 'UploadInProgress' ;
23+
uploadStatus : UploadStatusCode default 'uploading' ;
2424
uploadStatusNav : Association to one UploadScanStates on uploadStatusNav.code = uploadStatus;
2525
}
2626
entity UploadScanStates : CodeList {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
code;name;criticality
2-
UploadInProgress;Upload In Progress;5
2+
uploading;Uploading;5
33
Success;Success;3
4-
Failed;Failed;1
5-
VirusDetected;Virus Detected;1
6-
VirusScanInprogress;Virus Scan In Progress(Refresh the page);5
4+
Failed;Scan Failed;1
5+
VirusDetected;Virus detected;1
6+
VirusScanInprogress;Virus scanning inprogress(refresh page);5

0 commit comments

Comments
 (0)