33import bio .terra .pearl .api .participant .service .AuthUtilService ;
44import bio .terra .pearl .core .model .EnvironmentName ;
55import bio .terra .pearl .core .model .file .ParticipantFile ;
6+ import bio .terra .pearl .core .model .file .ScannedParticipantFileDto ;
67import bio .terra .pearl .core .model .participant .Enrollee ;
78import bio .terra .pearl .core .model .participant .ParticipantUser ;
89import bio .terra .pearl .core .service .exception .NotFoundException ;
910import bio .terra .pearl .core .service .file .ParticipantFileService ;
11+ import bio .terra .pearl .core .service .file .VirusScanResult ;
1012import bio .terra .pearl .core .service .file .backends .FileStorageBackend ;
1113import bio .terra .pearl .core .service .file .backends .FileStorageBackendProvider ;
1214import java .io .IOException ;
@@ -34,7 +36,7 @@ public ParticipantFileExtService(
3436 this .fileStorageBackend = fileStorageBackendProvider .get ();
3537 }
3638
37- public ParticipantFile get (
39+ public ScannedParticipantFileDto get (
3840 String portalShortcode ,
3941 EnvironmentName envName ,
4042 ParticipantUser participantUser ,
@@ -43,9 +45,13 @@ public ParticipantFile get(
4345 authUtilService .authParticipantToPortal (participantUser .getId (), portalShortcode , envName );
4446 Enrollee enrollee =
4547 authUtilService .authParticipantUserToEnrollee (participantUser .getId (), enrolleeShortcode );
46- return participantFileService
47- .findByEnrolleeIdAndFileName (enrollee .getId (), fileName )
48- .orElseThrow (() -> new NotFoundException ("Could not find file" ));
48+
49+ ParticipantFile file =
50+ participantFileService
51+ .findByEnrolleeIdAndFileName (enrollee .getId (), fileName )
52+ .orElseThrow (() -> new NotFoundException ("Could not find file" ));
53+
54+ return participantFileService .attachVirusScanResult (file );
4955 }
5056
5157 public InputStream downloadFile (
@@ -62,6 +68,13 @@ public InputStream downloadFile(
6268 .findByEnrolleeIdAndFileName (enrollee .getId (), fileName )
6369 .orElseThrow (() -> new NotFoundException ("Could not find file" ));
6470
71+ VirusScanResult virusScanResult =
72+ participantFileService .getVirusScanResult (participantFile .getExternalFileId ());
73+
74+ if (virusScanResult == VirusScanResult .QUARANTINED ) {
75+ throw new IllegalArgumentException ("Virus detected in file" );
76+ }
77+
6578 return fileStorageBackend .downloadFile (participantFile .getExternalFileId ());
6679 }
6780
0 commit comments