From 41f5c9857033625f322e690cbc4a41fd1bf3aff6 Mon Sep 17 00:00:00 2001 From: tcezard Date: Wed, 2 Oct 2024 13:40:54 +0100 Subject: [PATCH 1/3] Prevent upload of metadata if it already exists --- .../controller/submissionws/SubmissionController.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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..646f3be 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,15 @@ public ResponseEntity markSubmissionUploaded(@RequestHeader("Authorization") return new ResponseEntity<>("Unauthorized", HttpStatus.UNAUTHORIZED); } + submissionService.checkMetadataFileInfoMatchesWithUploadedFiles(submissionAccount, submissionId, metadataJson); + String submissionStatus = submissionService.getSubmissionStatus(submissionId); + if (! Objects.equals(submissionStatus, SubmissionStatus.OPEN.toString())){ + return new ResponseEntity<>( + "Submission " + submissionId + "is not in status " + SubmissionStatus.OPEN + + " so 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); From 6db78ce1487f66e0f7f1edc43cd7a513bf5daef5 Mon Sep 17 00:00:00 2001 From: tcezard Date: Wed, 2 Oct 2024 17:31:30 +0100 Subject: [PATCH 2/3] Add test --- .../submissionws/SubmissionController.java | 6 ++--- .../SubmissionWSIntegrationTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) 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 646f3be..7cb0b9e 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,13 +93,13 @@ public ResponseEntity markSubmissionUploaded(@RequestHeader("Authorization") return new ResponseEntity<>("Unauthorized", HttpStatus.UNAUTHORIZED); } - submissionService.checkMetadataFileInfoMatchesWithUploadedFiles(submissionAccount, submissionId, metadataJson); String submissionStatus = submissionService.getSubmissionStatus(submissionId); + System.out.println(submissionStatus); if (! Objects.equals(submissionStatus, SubmissionStatus.OPEN.toString())){ return new ResponseEntity<>( "Submission " + submissionId + "is not in status " + SubmissionStatus.OPEN + - " so cannot be marked as " + SubmissionStatus.UPLOADED + - "Current Status: " + submissionStatus, + ". It cannot be marked as " + SubmissionStatus.UPLOADED + + ". Current Status: " + submissionStatus, HttpStatus.BAD_REQUEST); } try { 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..8aeef77 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 { From 6a8fd5d5c936ceb1d9bd308ab2a64f6fbba64eff Mon Sep 17 00:00:00 2001 From: Timothee Cezard Date: Thu, 3 Oct 2024 17:47:41 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: April Shen --- .../controller/submissionws/SubmissionController.java | 3 +-- .../submission/integration/SubmissionWSIntegrationTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) 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 7cb0b9e..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 @@ -94,10 +94,9 @@ public ResponseEntity markSubmissionUploaded(@RequestHeader("Authorization") } String submissionStatus = submissionService.getSubmissionStatus(submissionId); - System.out.println(submissionStatus); if (! Objects.equals(submissionStatus, SubmissionStatus.OPEN.toString())){ return new ResponseEntity<>( - "Submission " + submissionId + "is not in status " + SubmissionStatus.OPEN + + "Submission " + submissionId + " is not in status " + SubmissionStatus.OPEN + ". It cannot be marked as " + SubmissionStatus.UPLOADED + ". Current Status: " + submissionStatus, HttpStatus.BAD_REQUEST); 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 8aeef77..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 @@ -633,7 +633,7 @@ public void testSubmissionAlreadyUploaded() throws Exception { .content(metadataJson) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()) - .andExpect(content().string("Submission " + submissionId + "is not in status OPEN. " + + .andExpect(content().string("Submission " + submissionId + " is not in status OPEN. " + "It cannot be marked as UPLOADED. Current Status: UPLOADED")); }