diff --git a/src/main/java/uk/ac/ebi/eva/submission/controller/submissionws/SubmissionController.java b/src/main/java/uk/ac/ebi/eva/submission/controller/submissionws/SubmissionController.java index 1331ca1..89d36b4 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/controller/submissionws/SubmissionController.java +++ b/src/main/java/uk/ac/ebi/eva/submission/controller/submissionws/SubmissionController.java @@ -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); diff --git a/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java b/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java index 71d7f7a..364caad 100644 --- a/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java +++ b/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java @@ -593,6 +593,7 @@ public void testRequiredMetadataFieldsNotProvided() throws Exception { "could not be found in metadata json")); } + @Test @Transactional public void testSubmissionDoesNotExistException() throws Exception { @@ -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 {