@@ -178,6 +178,9 @@ private void processAttachments(
178178 Map <String , String > secondaryPropertiesWithInvalidDefinitions ,
179179 List <String > noSDMRoles )
180180 throws IOException {
181+ List <String > virusDetectedFiles = new ArrayList <>();
182+ List <String > virusScanInProgressFiles = new ArrayList <>();
183+
181184 Iterator <Map <String , Object >> iterator = attachments .iterator ();
182185 while (iterator .hasNext ()) {
183186 Map <String , Object > attachment = iterator .next ();
@@ -191,8 +194,32 @@ private void processAttachments(
191194 filesWithUnsupportedProperties ,
192195 badRequest ,
193196 secondaryPropertiesWithInvalidDefinitions ,
194- noSDMRoles );
197+ noSDMRoles ,
198+ virusDetectedFiles ,
199+ virusScanInProgressFiles );
200+ }
201+
202+ // Throw exception if any files failed virus scan
203+ if (!virusDetectedFiles .isEmpty () || !virusScanInProgressFiles .isEmpty ()) {
204+ StringBuilder errorMessage = new StringBuilder ();
205+ if (!virusDetectedFiles .isEmpty ()) {
206+ errorMessage
207+ .append ("Virus detected in the following file(s): " )
208+ .append (String .join (", " , virusDetectedFiles ))
209+ .append (". Please delete them." );
210+ }
211+ if (!virusScanInProgressFiles .isEmpty ()) {
212+ if (errorMessage .length () > 0 ) {
213+ errorMessage .append (" " );
214+ }
215+ errorMessage
216+ .append ("Virus scanning is in progress for the following file(s): " )
217+ .append (String .join (", " , virusScanInProgressFiles ))
218+ .append (". Please refresh the page to see the effect." );
219+ }
220+ throw new ServiceException (errorMessage .toString ());
195221 }
222+
196223 SecondaryPropertiesKey secondaryPropertiesKey = new SecondaryPropertiesKey ();
197224 secondaryPropertiesKey .setRepositoryId (SDMConstants .REPOSITORY_ID );
198225 Cache <SecondaryPropertiesKey , ?> cache = CacheConfig .getSecondaryPropertiesCache ();
@@ -211,7 +238,9 @@ public void processAttachment(
211238 List <String > filesWithUnsupportedProperties ,
212239 Map <String , String > badRequest ,
213240 Map <String , String > secondaryPropertiesWithInvalidDefinitions ,
214- List <String > noSDMRoles )
241+ List <String > noSDMRoles ,
242+ List <String > virusDetectedFiles ,
243+ List <String > virusScanInProgressFiles )
215244 throws IOException {
216245 String id = (String ) attachment .get ("ID" );
217246 String filenameInRequest = (String ) attachment .get ("fileName" );
@@ -223,22 +252,23 @@ public void processAttachment(
223252 Map <String , String > secondaryTypeProperties =
224253 SDMUtils .getSecondaryTypeProperties (attachmentEntity , attachment );
225254 String fileNameInDB ;
226- Optional <CdsEntity > attachmentDraftEntity =
227- context .getModel ().findEntity (attachmentEntity .get ().getQualifiedName () + "_drafts" );
228255 CmisDocument cmisDocument =
229- dbQuery .getAttachmentForID (
230- attachmentEntity .get (), persistenceService , id , attachmentDraftEntity .get ());
256+ dbQuery .getAttachmentForID (attachmentEntity .get (), persistenceService , id );
231257 SDMCredentials sdmCredentials = tokenHandler .getSDMCredentials ();
232258 fileNameInDB = cmisDocument .getFileName ();
233- if (cmisDocument .getUploadStatus () != null
234- && cmisDocument
235- .getUploadStatus ()
236- .equalsIgnoreCase (SDMConstants .UPLOAD_STATUS_VIRUS_DETECTED ))
237- throw new ServiceException ("Virus Detected in this file kindly delete it." );
238- if (cmisDocument .getUploadStatus () != null
239- && cmisDocument .getUploadStatus ().equalsIgnoreCase (SDMConstants .VIRUS_SCAN_INPROGRESS ))
240- throw new ServiceException (
241- "Virus Scanning is in Progress. Refresh the page to see the effect" );
259+
260+ // Collect files with virus-related upload statuses
261+ if (attachment .get ("uploadStatus" ) != null ) {
262+ String uploadStatus = attachment .get ("uploadStatus" ).toString ();
263+ if (uploadStatus .equalsIgnoreCase (SDMConstants .UPLOAD_STATUS_VIRUS_DETECTED )) {
264+ virusDetectedFiles .add (fileNameInDB != null ? fileNameInDB : filenameInRequest );
265+ return ; // Skip further processing for this attachment
266+ }
267+ if (uploadStatus .equalsIgnoreCase (SDMConstants .VIRUS_SCAN_INPROGRESS )) {
268+ virusScanInProgressFiles .add (fileNameInDB != null ? fileNameInDB : filenameInRequest );
269+ return ; // Skip further processing for this attachment
270+ }
271+ }
242272
243273 // Fetch from SDM if not in DB
244274 String descriptionInDB = null ;
0 commit comments