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

EVA-3696 - Retrieve Submission details endpoint #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -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;
Expand Down Expand Up @@ -56,6 +57,22 @@ public ResponseEntity<?> markSubmissionStatus(@PathVariable("submissionId") Stri
}
}

@Operation(summary = "This endpoint retrieves detail of submission including the metadata json")
@Parameters({
@Parameter(name="submissionId", description = "Id of the submission whose status needs to be updated",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Parameter(name="submissionId", description = "Id of the submission whose status needs to be updated",
@Parameter(name="submissionId", description = "Id of the submission to fetch",

required = true, in= ParameterIn.PATH)
})
@GetMapping("submission/{submissionId}")
public ResponseEntity<?> getSubmissionDetails(
@PathVariable("submissionId") String submissionId) {
try {
SubmissionDetails submissionDetail = submissionService.getSubmissionDetail(submissionId);
return new ResponseEntity<>(submissionDetail, HttpStatus.OK);
} catch (SubmissionDoesNotExistException ex) {
return new ResponseEntity<>(ex.getMessage(), HttpStatus.NOT_FOUND);
}
}

@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 ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,9 @@ public SubmissionProcessing markSubmissionProcessStepAndStatus(String submission
return submissionProcessingRepository.save(submissionProc);
}

public SubmissionDetails getSubmissionDetail(String submissionId) {
return submissionDetailsRepository.findBySubmissionId(submissionId);
}


}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -895,4 +919,54 @@ 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;

}
}
Loading