Skip to content

Commit

Permalink
Update get status method for a submission to not require authenticati…
Browse files Browse the repository at this point in the history
…on (#12)
  • Loading branch information
nitin-ebi authored Jun 13, 2024
1 parent 8b1d94f commit 2a03076
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
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

0 comments on commit 2a03076

Please sign in to comment.