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

Prevent upload of metadata if it already exists #16

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -93,6 +93,15 @@ public ResponseEntity<?> markSubmissionUploaded(@RequestHeader("Authorization")
return new ResponseEntity<>("Unauthorized", HttpStatus.UNAUTHORIZED);
}

String submissionStatus = submissionService.getSubmissionStatus(submissionId);
System.out.println(submissionStatus);
tcezard marked this conversation as resolved.
Show resolved Hide resolved
if (! Objects.equals(submissionStatus, SubmissionStatus.OPEN.toString())){
return new ResponseEntity<>(
"Submission " + submissionId + "is not in status " + SubmissionStatus.OPEN +
tcezard marked this conversation as resolved.
Show resolved Hide resolved
". 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. " +
tcezard marked this conversation as resolved.
Show resolved Hide resolved
"It cannot be marked as UPLOADED. Current Status: UPLOADED"));
}

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