Skip to content

Commit

Permalink
Merge pull request #301 from folio-org/tmp-release-3.2.1
Browse files Browse the repository at this point in the history
Release 3.2.1
  • Loading branch information
obozhko-folio authored Apr 16, 2024
2 parents 72e217d + 93587dd commit 15a39f2
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 18 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2024-04-16 v3.2.1

[Full Changelog](https://github.com/folio-org/mod-data-export-spring/compare/v3.2.0...v3.2.1)

### Bug fixes
* [MODEXPS-261](https://folio-org.atlassian.net/browse/MODEXPS-261) "Request has expired" or "Expired token" errors

## 2024-03-19 v3.2.0

[Full Changelog](https://github.com/folio-org/mod-data-export-spring/compare/v3.1.0...v3.2.0)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<groupId>org.folio</groupId>
<artifactId>mod-data-export-spring</artifactId>
<description>Data Export Spring module</description>
<version>3.2.1-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<licenses>
Expand Down
6 changes: 3 additions & 3 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) {
log.info("downloadExportedFileByJobId:: with id={}.", id);
return ResponseEntity.ok(new InputStreamResource(service.downloadExportedFile(id)));
public ResponseEntity<Resource> downloadExportedFileByJobId(UUID id, String key) {
log.info("downloadExportedFileByJobId:: with id={}, key={}.", id, key);
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);

}
14 changes: 11 additions & 3 deletions src/main/java/org/folio/des/service/impl/JobServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.folio.des.service.impl;

import static java.util.Objects.nonNull;
import static org.folio.des.domain.dto.ExportType.BULK_EDIT_IDENTIFIERS;
import static org.folio.des.domain.dto.ExportType.BULK_EDIT_QUERY;
import static org.folio.des.domain.dto.ExportType.BULK_EDIT_UPDATE;
Expand Down Expand Up @@ -247,7 +248,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,14 +257,14 @@ 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");
conn.setConnectTimeout(CONNECTION_TIMEOUT);
return conn.getInputStream();
} catch (Exception e) {
log.error("Error downloading a file: {} for jobId: {}", e.getMessage(), job.getId());
log.error("Error downloading a file: {} for jobId: {} and key: {}", e.getMessage(), job.getId(), key);
throw new FileDownloadException(String.format("Error downloading a file: %s", e));
}
}
Expand Down Expand Up @@ -311,4 +312,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 (nonNull(key)) {
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
37 changes: 27 additions & 10 deletions src/test/java/org/folio/des/controller/JobsControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void getJobs() throws Exception {
matchAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON_VALUE),
jsonPath("$.totalRecords", is(8)),
jsonPath("$.jobRecords", hasSize(8))));
jsonPath("$.totalRecords", is(9)),
jsonPath("$.jobRecords", hasSize(9))));
}

@Test
Expand All @@ -115,7 +115,7 @@ void findSortedJobs() throws Exception {
matchAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON_VALUE),
jsonPath("$.totalRecords", is(8)),
jsonPath("$.totalRecords", is(9)),
jsonPath("$.jobRecords", hasSize(3))));
}

Expand All @@ -131,7 +131,7 @@ void findSortedJobsByExportMethodName() throws Exception {
matchAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON_VALUE),
jsonPath("$.totalRecords", is(8)),
jsonPath("$.totalRecords", is(9)),
jsonPath("$.jobRecords", hasSize(3))));
}

Expand Down Expand Up @@ -177,8 +177,8 @@ void excludeJobById() throws Exception {
matchAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON_VALUE),
jsonPath("$.totalRecords", is(7)),
jsonPath("$.jobRecords", hasSize(7))));
jsonPath("$.totalRecords", is(8)),
jsonPath("$.jobRecords", hasSize(8))));
}

@Test
Expand All @@ -193,8 +193,8 @@ void findJobsBySourceOrDesc() throws Exception {
matchAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON_VALUE),
jsonPath("$.totalRecords", is(7)),
jsonPath("$.jobRecords", hasSize(7))));
jsonPath("$.totalRecords", is(8)),
jsonPath("$.jobRecords", hasSize(8))));
}

@Test
Expand Down Expand Up @@ -239,8 +239,8 @@ void findJobsByQuery() throws Exception {
matchAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON_VALUE),
jsonPath("$.totalRecords", is(3)),
jsonPath("$.jobRecords", hasSize(3))));
jsonPath("$.totalRecords", is(4)),
jsonPath("$.jobRecords", hasSize(4))));
}

@Test
Expand Down Expand Up @@ -289,6 +289,23 @@ void shouldFailedDownloadWithBadRequest() throws Exception {
status().is5xxServerError()));
}

@Test
@DisplayName("Should succeed download file with key to storage")
void shouldSucceedDownloadWithKey() throws Exception {
PresignedUrl presignedUrl = new PresignedUrl();
presignedUrl.setUrl("http://localhost:" + WIRE_MOCK_PORT + "/TestFile.csv");
when(exportWorkerClient.getRefreshedPresignedUrl(anyString())).thenReturn(presignedUrl);
mockMvc
.perform(
get("/data-export-spring/jobs/22ae5d0f-6425-82a1-a361-1bc9b88e8172/download?key=TestFile.csv")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.headers(defaultHeaders()))
.andExpect(
matchAll(
status().is2xxSuccessful(),
content().bytes("Test file content".getBytes())));
}

@Test
@DisplayName("Can not fetch job with wrong id")
void notFoundJob() throws Exception {
Expand Down
14 changes: 14 additions & 0 deletions src/test/resources/job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ VALUES ('42ae5d0f-6425-82a1-a361-1bc9b88e8172', '000101', 'test-desc', 'data-exp
'data-export-system-user', 'Fees & Fines Bursar Report', null, 'COMPLETED', '{
"exitCode": "COMPLETED"
}');
INSERT INTO diku_mod_data_export_spring.job (id, name, description, source, is_system_source, type,
export_type_specific_parameters, status, files, file_names,
start_time, end_time, created_date, created_by_user_id,
created_by_username, updated_date, updated_by_user_id,
updated_by_username, output_format, error_details,
batch_status, exit_status)
VALUES ('22ae5d0f-6425-82a1-a361-1bc9b88e8172', '000102', 'test-desc', 'data-export-system-user', true,
'BULK_EDIT_IDENTIFIERS',
'{}',
'SUCCESSFUL', '["http://localhost/test-url/"]', '["TestFile.csv"]', '2021-03-16 09:29:54.250000', '2021-03-16 09:30:09.831000', '2021-03-16 09:29:54.170000',
null, 'data-export-system-user', '2021-03-16 09:30:09.968000', null,
'data-export-system-user', 'Bulk Edit report', null, 'COMPLETED', '{
"exitCode": "COMPLETED"
}');
INSERT INTO diku_mod_data_export_spring.job (id, name, description, source, is_system_source, type,
export_type_specific_parameters, status, files,
start_time, end_time, created_date, created_by_user_id,
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/mappings/files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"mappings": [
{
"request": {
"method": "GET",
"url": "/TestFile.csv"
},
"response": {
"status": 200,
"body": "Test file content",
"headers": {
"Content-Type": "text/plain"
}
}
}
]
}

0 comments on commit 15a39f2

Please sign in to comment.