From 728951cc3305f7ca577b1beef9a33d2e2d15fd48 Mon Sep 17 00:00:00 2001 From: Jason Hwee <1216418+hweej@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:22:40 -0400 Subject: [PATCH] Add resource-data-all endpoint and MyBatis SQL methods --- .../persistence/ResourceDataRepository.java | 7 ++++ .../mybatis/ResourceDataMapper.java | 6 ++++ .../ResourceDataMyBatisRepository.java | 16 +++++++++ .../service/ResourceDataService.java | 3 ++ .../service/impl/ResourceDataServiceImpl.java | 18 ++++++++++ .../web/ResourceDataController.java | 35 ++++++++++++++++++ .../mybatis/ResourceDataMapper.xml | 36 ++++++++++++++++++- 7 files changed, 120 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cbioportal/persistence/ResourceDataRepository.java b/src/main/java/org/cbioportal/persistence/ResourceDataRepository.java index a4f0661a02b..c93898dd2ce 100644 --- a/src/main/java/org/cbioportal/persistence/ResourceDataRepository.java +++ b/src/main/java/org/cbioportal/persistence/ResourceDataRepository.java @@ -18,5 +18,12 @@ List getAllResourceDataOfPatientInStudy(String studyId, String pat @Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()") List getAllResourceDataForStudy(String studyId, String resourceId, String projection, Integer pageSize, Integer pageNumber, String sortBy, String direction); + + @Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()") + List getResourceDataForAllPatientsInStudy(String studyId, String resourceId, String projection, + Integer pageSize, Integer pageNumber, String sortBy, String direction); + @Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()") + List getResourceDataForAllSamplesInStudy(String studyId, String resourceId, String projection, + Integer pageSize, Integer pageNumber, String sortBy, String direction); } diff --git a/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMapper.java b/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMapper.java index c498baf7c7b..ec3ea25ab9d 100644 --- a/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMapper.java +++ b/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMapper.java @@ -15,4 +15,10 @@ List getResourceDataOfPatientInStudy(String studyId, String patien List getResourceDataForStudy(String studyId, String resourceId, String projection, Integer limit, Integer offset, String sortBy, String direction); + List getResourceDataForAllPatientsInStudy(String studyId, String resourceId, String projection, Integer limit, + Integer offset, String sortBy, String direction); + + List getResourceDataForAllSamplesInStudy(String studyId, String resourceId, String projection, Integer limit, + Integer offset, String sortBy, String direction); + } diff --git a/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMyBatisRepository.java b/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMyBatisRepository.java index 5fce1144019..79a66956f5c 100644 --- a/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMyBatisRepository.java +++ b/src/main/java/org/cbioportal/persistence/mybatis/ResourceDataMyBatisRepository.java @@ -38,4 +38,20 @@ public List getAllResourceDataForStudy(String studyId, String reso PaginationCalculator.offset(pageSize, pageNumber), sortBy, direction); } + @Override + public List getResourceDataForAllPatientsInStudy(String studyId, String resourceId, String projection, + Integer pageSize, Integer pageNumber, String sortBy, String direction) { + + return resourceDataMapper.getResourceDataForAllPatientsInStudy(studyId, resourceId, projection, pageSize, + PaginationCalculator.offset(pageSize, pageNumber), sortBy, direction); + } + + @Override + public List getResourceDataForAllSamplesInStudy(String studyId, String resourceId, String projection, + Integer pageSize, Integer pageNumber, String sortBy, String direction) { + + return resourceDataMapper.getResourceDataForAllSamplesInStudy(studyId, resourceId, projection, pageSize, + PaginationCalculator.offset(pageSize, pageNumber), sortBy, direction); + } + } diff --git a/src/main/java/org/cbioportal/service/ResourceDataService.java b/src/main/java/org/cbioportal/service/ResourceDataService.java index 24108f57eb3..5727906394c 100644 --- a/src/main/java/org/cbioportal/service/ResourceDataService.java +++ b/src/main/java/org/cbioportal/service/ResourceDataService.java @@ -20,4 +20,7 @@ List getAllResourceDataOfPatientInStudy(String studyId, String pat List getAllResourceDataForStudy(String studyId, String resourceId, String projection, Integer pageSize, Integer pageNumber, String sortBy, String direction) throws StudyNotFoundException; + List getAllResourceDataForStudyPatientSample(String studyId, String resourceId, String projection, + Integer pageSize, Integer pageNumber, String sortBy, String direction) throws StudyNotFoundException; + } diff --git a/src/main/java/org/cbioportal/service/impl/ResourceDataServiceImpl.java b/src/main/java/org/cbioportal/service/impl/ResourceDataServiceImpl.java index c9b37f1d937..6e1d94ebe77 100644 --- a/src/main/java/org/cbioportal/service/impl/ResourceDataServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/ResourceDataServiceImpl.java @@ -1,6 +1,7 @@ package org.cbioportal.service.impl; import java.util.List; +import java.util.ArrayList; import org.cbioportal.model.ResourceData; import org.cbioportal.persistence.ResourceDataRepository; @@ -56,5 +57,22 @@ public List getAllResourceDataForStudy(String studyId, String reso return resourceDataRepository.getAllResourceDataForStudy(studyId, resourceId, projection, pageSize, pageNumber, sortBy, direction); } + + @Override + public List getAllResourceDataForStudyPatientSample(String studyId, String resourceId, String projection, + Integer pageSize, Integer pageNumber, String sortBy, String direction) throws StudyNotFoundException { + + studyService.getStudy(studyId); + + List results = new ArrayList(); + + results.addAll(resourceDataRepository.getAllResourceDataForStudy(studyId, resourceId, projection, pageSize, pageNumber, + sortBy, direction)); + results.addAll(resourceDataRepository.getResourceDataForAllPatientsInStudy(studyId, resourceId, projection, pageSize, pageNumber, + sortBy, direction)); + results.addAll(resourceDataRepository.getResourceDataForAllSamplesInStudy(studyId, resourceId, projection, pageSize, pageNumber, + sortBy, direction)); + return results; + } } diff --git a/src/main/java/org/cbioportal/web/ResourceDataController.java b/src/main/java/org/cbioportal/web/ResourceDataController.java index 4b5e1e43502..ef1c6a3fd52 100644 --- a/src/main/java/org/cbioportal/web/ResourceDataController.java +++ b/src/main/java/org/cbioportal/web/ResourceDataController.java @@ -157,4 +157,39 @@ public ResponseEntity> getAllStudyResourceDataInStudy( } } + // NEW COMBINED GET METHOD FOR RESOURCE-DATA + @PreAuthorize("hasPermission(#studyId, 'CancerStudyId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/studies/{studyId}/resource-data-all", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(description = "Get all resource data for for all patients and all samples within a study") + @ApiResponse(responseCode = "200", description = "OK", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ResourceData.class)))) + public ResponseEntity> getAllStudyResourceDataInStudyPatientSample( + @Parameter(required = true, description = "Study ID e.g. acc_tcga") + @PathVariable String studyId, + @Parameter(description = "Resource ID") + @RequestParam(required = false) String resourceId, + @Parameter(description = "Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection, + @Parameter(description = "Page size of the result list") + @Max(RESOURCE_DATA_MAX_PAGE_SIZE) + @Min(PagingConstants.MIN_PAGE_SIZE) + @RequestParam(defaultValue = RESOURCE_DATA_DEFAULT_PAGE_SIZE) Integer pageSize, + @Parameter(description = "Page number of the result list") + @Min(PagingConstants.MIN_PAGE_NUMBER) + @RequestParam(defaultValue = PagingConstants.DEFAULT_PAGE_NUMBER) Integer pageNumber, + @Parameter(description = "Name of the property that the result list is sorted by") + @RequestParam(required = false) ResourceDataSortBy sortBy, + @Parameter(description = "Direction of the sort") + @RequestParam(defaultValue = "ASC") Direction direction) throws StudyNotFoundException { + + if (projection == Projection.META) { + throw new UnsupportedOperationException("Requested API is not implemented yet"); + } else { + return new ResponseEntity<>( + resourceDataService.getAllResourceDataForStudyPatientSample(studyId, resourceId, projection.name(), pageSize, pageNumber, + sortBy == null ? null : sortBy.getOriginalValue(), direction.name()), HttpStatus.OK); + } + } + } diff --git a/src/main/resources/org/cbioportal/persistence/mybatis/ResourceDataMapper.xml b/src/main/resources/org/cbioportal/persistence/mybatis/ResourceDataMapper.xml index e4afbdb6f60..2e6eea52092 100644 --- a/src/main/resources/org/cbioportal/persistence/mybatis/ResourceDataMapper.xml +++ b/src/main/resources/org/cbioportal/persistence/mybatis/ResourceDataMapper.xml @@ -171,4 +171,38 @@ - + + + + + \ No newline at end of file