Skip to content

Commit

Permalink
MODEXPS-261 Changed endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
obozhko-folio committed Apr 8, 2024
1 parent 28d8fef commit aa1dc10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/folio/des/controller/JobsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public ResponseEntity resendExportedFile(UUID jobId) {
}

@Override
public ResponseEntity<Resource> downloadExportedFileByJobId(UUID id) {
public ResponseEntity<Resource> 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
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/folio/des/service/JobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
11 changes: 9 additions & 2 deletions src/main/java/org/folio/des/service/impl/JobServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void deleteJobs(List<Job> 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())) {
Expand All @@ -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");
Expand Down Expand Up @@ -311,4 +311,11 @@ private String getUserName(FolioExecutionContext context) {
Optional<JWTokenUtils.UserInfo> 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));
}
}
6 changes: 6 additions & 0 deletions src/main/resources/swagger.api/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa1dc10

Please sign in to comment.