Skip to content

Commit

Permalink
Merge pull request #16 from tcezard/Prevent_mulitple_upload
Browse files Browse the repository at this point in the history
Prevent upload of metadata if it already exists
  • Loading branch information
tcezard authored Oct 21, 2024
2 parents 5c99a98 + 6a8fd5d commit 46d12d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public ResponseEntity<?> markSubmissionUploaded(@RequestHeader("Authorization")
return new ResponseEntity<>("Unauthorized", HttpStatus.UNAUTHORIZED);
}

String submissionStatus = submissionService.getSubmissionStatus(submissionId);
if (! Objects.equals(submissionStatus, SubmissionStatus.OPEN.toString())){
return new ResponseEntity<>(
"Submission " + submissionId + " is not in status " + SubmissionStatus.OPEN +
". It cannot be marked as " + SubmissionStatus.UPLOADED +
". Current Status: " + submissionStatus,
HttpStatus.BAD_REQUEST);
}
try {
submissionService.checkMetadataFileInfoMatchesWithUploadedFiles(submissionAccount, submissionId, metadataJson);
Submission submission = this.submissionService.uploadMetadataJsonAndMarkUploaded(submissionId, metadataJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ public void testRequiredMetadataFieldsNotProvided() throws Exception {
"could not be found in metadata json"));
}


@Test
@Transactional
public void testSubmissionDoesNotExistException() throws Exception {
Expand All @@ -615,6 +616,27 @@ public void testSubmissionDoesNotExistException() throws Exception {
.andExpect(content().string("Submission with id " + submissionId + " does not exist"));
}

@Test
@Transactional
public void testSubmissionAlreadyUploaded() throws Exception {
String userToken = "webinUserToken";
SubmissionAccount submissionAccount = getWebinUserAccount();
when(webinTokenService.getWebinUserAccountFromToken(anyString())).thenReturn(submissionAccount);
String projectTitle = "test_project_title";
String projectDescription = "test_project_description";
String submissionId = createNewSubmissionEntry(submissionAccount, SubmissionStatus.UPLOADED);
String metadataJson = "{\"project\": {\"title\":\"" + projectTitle + "\",\"description\":\"" + projectDescription + "\"}}";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setBearerAuth(userToken);
mvc.perform(put("/v1/submission/" + submissionId + "/uploaded")
.headers(httpHeaders)
.content(metadataJson)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andExpect(content().string("Submission " + submissionId + " is not in status OPEN. " +
"It cannot be marked as UPLOADED. Current Status: UPLOADED"));
}

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

0 comments on commit 46d12d2

Please sign in to comment.