Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-3590 Update get status method for a submission to not require authentication #12

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import uk.ac.ebi.eva.submission.entity.Submission;
import uk.ac.ebi.eva.submission.entity.SubmissionAccount;
import uk.ac.ebi.eva.submission.exception.RequiredFieldsMissingException;
import uk.ac.ebi.eva.submission.exception.SubmissionDoesNotExistException;
import uk.ac.ebi.eva.submission.model.SubmissionStatus;
import uk.ac.ebi.eva.submission.service.LsriTokenService;
import uk.ac.ebi.eva.submission.service.SubmissionService;
Expand Down Expand Up @@ -100,23 +101,18 @@ public ResponseEntity<?> markSubmissionUploaded(@RequestHeader("Authorization")
}
}

@Operation(summary = "Given a submission id, this endpoint retrieves the current status of a submission")
@Operation(summary = "Given a submission id, this endpoint retrieves the current status of the submission")
@Parameters({
@Parameter(name = "Authorization", description = "Token (bearerToken) for authenticating the user",
required = true, in = ParameterIn.HEADER),
@Parameter(name = "submissionId", description = "Id of the submission whose status needs to be retrieved",
required = true, in = ParameterIn.PATH)
})
@GetMapping("submission/{submissionId}/status")
public ResponseEntity<?> getSubmissionStatus(@RequestHeader("Authorization") String bearerToken,
@PathVariable("submissionId") String submissionId) {
SubmissionAccount submissionAccount = this.getSubmissionAccount(bearerToken);
if (Objects.isNull(submissionAccount) || !submissionService.checkUserHasAccessToSubmission(submissionAccount, submissionId)) {
return new ResponseEntity<>("Unauthorized", HttpStatus.UNAUTHORIZED);
public ResponseEntity<?> getSubmissionStatus(@PathVariable("submissionId") String submissionId) {
try {
String submissionStatus = submissionService.getSubmissionStatus(submissionId);
return new ResponseEntity<>(submissionStatus, HttpStatus.OK);
} catch (SubmissionDoesNotExistException ex) {
return new ResponseEntity<>(ex.getMessage(), HttpStatus.NOT_FOUND);
}

String submissionStatus = submissionService.getSubmissionStatus(submissionId);
return new ResponseEntity<>(submissionStatus, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public Submission uploadMetadataJsonAndMarkUploaded(String submissionId, JsonNod

public String getSubmissionStatus(String submissionId) {
Submission submission = submissionRepository.findBySubmissionId(submissionId);
if (submission == null) {
throw new SubmissionDoesNotExistException("Submission with Id " + submissionId + " does not exist");
}

return submission.getStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ public void testSubmissionGetStatus() throws Exception {
.andExpectAll(status().isOk(), content().string(SubmissionStatus.OPEN.toString()));
}

@Test
@Transactional
public void testSubmissionGetStatusSubmissionDoesNotExist() throws Exception {
String userToken = "webinUserToken";
String submissionId = "test123";
SubmissionAccount submissionAccount = getWebinUserAccount();
when(webinTokenService.getWebinUserAccountFromToken(anyString())).thenReturn(submissionAccount);

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setBearerAuth(userToken);
mvc.perform(get("/v1/submission/" + submissionId + "/status")
.headers(httpHeaders)
.contentType(MediaType.APPLICATION_JSON))
.andExpectAll(status().isNotFound(), content().string("Submission with Id test123 does not exist"));
}

@Test
@Transactional
public void testUploadMetadataJsonAndMarkUploadedd() throws Exception {
Expand Down
Loading