From 870f4cf13624d5bf250efe416082a1e10965a98b Mon Sep 17 00:00:00 2001 From: tcezard Date: Fri, 6 Dec 2024 08:59:00 +0000 Subject: [PATCH] Retrieve Submission details --- .../controller/admin/AdminController.java | 16 ++++ .../submission/service/SubmissionService.java | 4 + .../SubmissionWSIntegrationTest.java | 82 ++++++++++++++++++- 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/main/java/uk/ac/ebi/eva/submission/controller/admin/AdminController.java b/src/main/java/uk/ac/ebi/eva/submission/controller/admin/AdminController.java index 0b69e9a..e2ec879 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/controller/admin/AdminController.java +++ b/src/main/java/uk/ac/ebi/eva/submission/controller/admin/AdminController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import uk.ac.ebi.eva.submission.controller.BaseController; import uk.ac.ebi.eva.submission.entity.Submission; +import uk.ac.ebi.eva.submission.entity.SubmissionDetails; import uk.ac.ebi.eva.submission.entity.SubmissionProcessing; import uk.ac.ebi.eva.submission.exception.SubmissionDoesNotExistException; import uk.ac.ebi.eva.submission.model.SubmissionProcessingStatus; @@ -56,6 +57,21 @@ public ResponseEntity markSubmissionStatus(@PathVariable("submissionId") Stri } } + @Operation(summary = "This endpoint retrieves all the submissions from the database with given step and status") + @Parameters({ + @Parameter(name="step", description = "The processing step of the submission.", + required = true, in= ParameterIn.PATH), + @Parameter(name="status", description = "The status of the submission processing step.", + required = true, in= ParameterIn.PATH) + }) + + @GetMapping("submission/{submissionId}") + public ResponseEntity getSubmissionsDetail( + @PathVariable("submissionId") String submissionId) { + SubmissionDetails submissionDetail = submissionService.getSubmissionDetail(submissionId); + return new ResponseEntity<>(submissionDetail, HttpStatus.OK); + } + @Operation(summary = "This endpoint retrieves all the submissions of a specific status present in the database") @Parameters({ @Parameter(name="status", description = "Desired status of the submission ", diff --git a/src/main/java/uk/ac/ebi/eva/submission/service/SubmissionService.java b/src/main/java/uk/ac/ebi/eva/submission/service/SubmissionService.java index 0b6c4b7..866ebcd 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/service/SubmissionService.java +++ b/src/main/java/uk/ac/ebi/eva/submission/service/SubmissionService.java @@ -246,5 +246,9 @@ public SubmissionProcessing markSubmissionProcessStepAndStatus(String submission return submissionProcessingRepository.save(submissionProc); } + public SubmissionDetails getSubmissionDetail(String submissionId){ + return submissionDetailsRepository.findBySubmissionId(submissionId); + } + } 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 364caad..e931af3 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 @@ -1,5 +1,6 @@ package uk.ac.ebi.eva.submission.integration; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -17,6 +18,7 @@ import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; import org.springframework.transaction.annotation.Transactional; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; @@ -361,8 +363,6 @@ public void testMarkSubmissionUploadNoFileInfoInMetadatajson() throws Exception ObjectNode metadataRootNode = mapper.createObjectNode(); ArrayNode filesArrayNode = mapper.createArrayNode(); metadataRootNode.put("files", filesArrayNode); - - HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setBearerAuth(userToken); mvc.perform(put("/v1/submission/" + submissionId + "/uploaded") @@ -806,6 +806,31 @@ public void testMarkSubmissionProcessStepAndStatusSubmissionDoesNotExist() throw } + @Test + @Transactional + public void testGetSubmissionDetail() throws Exception { + SubmissionAccount submissionAccount = getWebinUserAccount(); + when(webinTokenService.getWebinUserAccountFromToken(anyString())).thenReturn(submissionAccount); + String projectTitle = "test_project_title"; + String projectDescription = "test_project_description"; + + String submissionId1 = createNewSubmissionEntry(submissionAccount, SubmissionStatus.UPLOADED); + ObjectMapper mapper = new ObjectMapper(); + JsonNode metadataRootNode = createNewMetadataJSON(mapper, projectTitle, projectDescription); + + createNewSubmissionDetailEntry(submissionId1, projectTitle, projectDescription, metadataRootNode); + + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.setBasicAuth(TEST_ADMIN_USERNAME, TEST_ADMIN_PASSWORD); + mvc.perform(get("/v1/admin/submission/" + submissionId1 ) + .headers(httpHeaders) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("submissionId").value(submissionId1)) + .andExpect(jsonPath("metadataJson.project.title").value(projectTitle)) + .andExpect(jsonPath("metadataJson.project.description").value(projectDescription)); + } + @Disabled @Test @Transactional @@ -814,7 +839,6 @@ public void testSubmissionProcessingHistory() throws Exception { when(webinTokenService.getWebinUserAccountFromToken(anyString())).thenReturn(submissionAccount); String submissionId = createNewSubmissionEntry(submissionAccount, SubmissionStatus.PROCESSING); - HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setBasicAuth(TEST_ADMIN_USERNAME, TEST_ADMIN_PASSWORD); mvc.perform(put("/v1/admin/submission-process/" + submissionId + "/" + SubmissionProcessingStep.VALIDATION + "/" + SubmissionProcessingStatus.READY_FOR_PROCESSING) @@ -895,4 +919,56 @@ private void createNewSubmissionProcessingEntry(String submissionId, SubmissionP submissionProcessing.setPriority(5); submissionProcessingRepository.save(submissionProcessing); } + + private void createNewSubmissionDetailEntry(String submissionId, String projectTitle, String projectDescription, + JsonNode metadataJson) { + SubmissionDetails submissionDetail = new SubmissionDetails(submissionId); + submissionDetail.setProjectTitle(projectTitle); + submissionDetail.setProjectDescription(projectDescription); + submissionDetail.setMetadataJson(metadataJson); + submissionDetailsRepository.save(submissionDetail); + } + + private JsonNode createNewMetadataJSON(ObjectMapper mapper, String projectTitle, String projectDescription) { + + + // create metadata json + ObjectNode metadataRootNode = mapper.createObjectNode(); + + ObjectNode projectNode = mapper.createObjectNode(); + projectNode.put("title", projectTitle); + projectNode.put("description", projectDescription); + + ArrayNode filesArrayNode = mapper.createArrayNode(); + ObjectNode fileNode1 = mapper.createObjectNode(); + fileNode1.put("fileName", "file1.vcf"); + fileNode1.put("fileSize", 12345L); + ObjectNode fileNode2 = mapper.createObjectNode(); + fileNode2.put("fileName", "file2.vcf.gz"); + fileNode2.put("fileSize", 67890L); + + filesArrayNode.add(fileNode1); + filesArrayNode.add(fileNode2); + + metadataRootNode.put("project", projectNode); + metadataRootNode.put("files", filesArrayNode); + + // create Globus list directory result json + ObjectNode globusRootNode = mapper.createObjectNode(); + + ArrayNode dataNodeArray = mapper.createArrayNode(); + ObjectNode dataNode1 = mapper.createObjectNode(); + dataNode1.put("name", "file1.vcf"); + dataNode1.put("size", 12345L); + ObjectNode dataNode2 = mapper.createObjectNode(); + dataNode2.put("name", "file2.vcf.gz"); + dataNode2.put("size", 67890L); + + dataNodeArray.add(dataNode1); + dataNodeArray.add(dataNode2); + + globusRootNode.put("DATA", dataNodeArray); + return metadataRootNode; + + } }