diff --git a/src/main/java/org/folio/des/controller/JobsController.java b/src/main/java/org/folio/des/controller/JobsController.java index c70e5789..3eef71fa 100644 --- a/src/main/java/org/folio/des/controller/JobsController.java +++ b/src/main/java/org/folio/des/controller/JobsController.java @@ -66,9 +66,9 @@ public ResponseEntity resendExportedFile(UUID jobId) { } @Override - public ResponseEntity downloadExportedFileByJobId(UUID id) { + public ResponseEntity downloadExportedFileByJobId(UUID id, String key) { log.info("downloadExportedFileByJobId:: with id={}.", id); - return ResponseEntity.ok(new InputStreamResource(service.downloadExportedFile(id))); + return ResponseEntity.ok(new InputStreamResource(service.downloadExportedFile(id, key))); } @Override diff --git a/src/main/java/org/folio/des/service/JobService.java b/src/main/java/org/folio/des/service/JobService.java index 8759d8ba..29330e32 100644 --- a/src/main/java/org/folio/des/service/JobService.java +++ b/src/main/java/org/folio/des/service/JobService.java @@ -59,8 +59,9 @@ public interface JobService { /** * Downloading the exported file. A job can have only one exported file. * @param jobId the job id + * @param key the key of the file in the storage * @return Input stream of exported file. */ - InputStream downloadExportedFile(UUID jobId); + InputStream downloadExportedFile(UUID jobId, String key); } diff --git a/src/main/java/org/folio/des/service/impl/JobServiceImpl.java b/src/main/java/org/folio/des/service/impl/JobServiceImpl.java index 4fab1cd8..fbc8823e 100644 --- a/src/main/java/org/folio/des/service/impl/JobServiceImpl.java +++ b/src/main/java/org/folio/des/service/impl/JobServiceImpl.java @@ -247,7 +247,7 @@ public void deleteJobs(List jobs) { } @Override - public InputStream downloadExportedFile(UUID jobId) { + public InputStream downloadExportedFile(UUID jobId, String key) { log.debug("downloadExportedFile:: download exported files for jobId={}.", jobId); Job job = getJobEntity(jobId); if (CollectionUtils.isEmpty(job.getFileNames())) { @@ -256,7 +256,7 @@ public InputStream downloadExportedFile(UUID jobId) { } log.debug("Refreshing download url for jobId: {}", job.getId()); try { - PresignedUrl presignedUrl = exportWorkerClient.getRefreshedPresignedUrl(job.getFiles().get(0)); + PresignedUrl presignedUrl = getPresignedUrl(job, key); URL url = new URL(presignedUrl.getUrl()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); @@ -311,4 +311,11 @@ private String getUserName(FolioExecutionContext context) { Optional userInfo = StringUtils.isBlank(jwt) ? Optional.empty() : JWTokenUtils.parseToken(jwt); return StringUtils.substring(userInfo.map(JWTokenUtils.UserInfo::getUserName).orElse(null), 0, 50); } + + private PresignedUrl getPresignedUrl(Job job, String key) { + if (job.getType() == BULK_EDIT_IDENTIFIERS || job.getType() == BULK_EDIT_UPDATE || job.getType() == BULK_EDIT_QUERY) { + return exportWorkerClient.getRefreshedPresignedUrl(key); + } + return exportWorkerClient.getRefreshedPresignedUrl(job.getFiles().get(0)); + } } diff --git a/src/main/resources/swagger.api/jobs.yaml b/src/main/resources/swagger.api/jobs.yaml index 280b70b9..d6479e34 100644 --- a/src/main/resources/swagger.api/jobs.yaml +++ b/src/main/resources/swagger.api/jobs.yaml @@ -177,6 +177,12 @@ paths: description: UUID of the job schema: $ref: "#/components/schemas/UUID" + - name: key + in: query + required: false + description: Key of the file in storage to be downloaded + schema: + type: string responses: "200": description: Export file successfully retrieved