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

Add resource-data-all endpoint and MyBatis SQL methods #11051

Merged
merged 3 commits into from
Oct 28, 2024
Merged
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 @@ -18,5 +18,12 @@ List<ResourceData> getAllResourceDataOfPatientInStudy(String studyId, String pat
@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
List<ResourceData> getAllResourceDataForStudy(String studyId, String resourceId, String projection,
Integer pageSize, Integer pageNumber, String sortBy, String direction);

@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
List<ResourceData> getResourceDataForAllPatientsInStudy(String studyId, String resourceId, String projection,
Integer pageSize, Integer pageNumber, String sortBy, String direction);

@Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()")
List<ResourceData> getResourceDataForAllSamplesInStudy(String studyId, String resourceId, String projection,
Integer pageSize, Integer pageNumber, String sortBy, String direction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ List<ResourceData> getResourceDataOfPatientInStudy(String studyId, String patien
List<ResourceData> getResourceDataForStudy(String studyId, String resourceId, String projection, Integer limit,
Integer offset, String sortBy, String direction);

List<ResourceData> getResourceDataForAllPatientsInStudy(String studyId, String resourceId, String projection, Integer limit,
Integer offset, String sortBy, String direction);

List<ResourceData> getResourceDataForAllSamplesInStudy(String studyId, String resourceId, String projection, Integer limit,
Integer offset, String sortBy, String direction);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ public List<ResourceData> getAllResourceDataForStudy(String studyId, String reso
PaginationCalculator.offset(pageSize, pageNumber), sortBy, direction);
}

@Override
public List<ResourceData> 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<ResourceData> 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);
}

}
3 changes: 3 additions & 0 deletions src/main/java/org/cbioportal/service/ResourceDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ List<ResourceData> getAllResourceDataOfPatientInStudy(String studyId, String pat
List<ResourceData> getAllResourceDataForStudy(String studyId, String resourceId, String projection,
Integer pageSize, Integer pageNumber, String sortBy, String direction) throws StudyNotFoundException;

List<ResourceData> getAllResourceDataForStudyPatientSample(String studyId, String resourceId, String projection,
Integer pageSize, Integer pageNumber, String sortBy, String direction) throws StudyNotFoundException;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -56,5 +57,22 @@ public List<ResourceData> getAllResourceDataForStudy(String studyId, String reso
return resourceDataRepository.getAllResourceDataForStudy(studyId, resourceId, projection, pageSize, pageNumber,
sortBy, direction);
}

@Override
public List<ResourceData> getAllResourceDataForStudyPatientSample(String studyId, String resourceId, String projection,
Integer pageSize, Integer pageNumber, String sortBy, String direction) throws StudyNotFoundException {

studyService.getStudy(studyId);

List<ResourceData> results = new ArrayList<ResourceData>();

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;
}

}
60 changes: 60 additions & 0 deletions src/main/java/org/cbioportal/web/ResourceDataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;

import org.cbioportal.model.ResourceData;
import org.cbioportal.service.ResourceDataService;
import org.cbioportal.service.exception.PatientNotFoundException;
Expand All @@ -21,6 +22,8 @@
import org.cbioportal.web.parameter.Projection;
import org.cbioportal.web.parameter.sort.ResourceDataSortBy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -33,6 +36,7 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

@InternalApi
@RestController()
Expand All @@ -47,6 +51,17 @@ public class ResourceDataController {
@Autowired
private ResourceDataService resourceDataService;

@Autowired
private ApplicationContext applicationContext;
ResourceDataController instance;

private ResourceDataController getInstance() {
if (Objects.isNull(instance)) {
instance = applicationContext.getBean(ResourceDataController.class);
}
return instance;
}

@PreAuthorize("hasPermission(#studyId, 'CancerStudyId', T(org.cbioportal.utils.security.AccessLevel).READ)")
@RequestMapping(value = "/studies/{studyId}/samples/{sampleId}/resource-data", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -157,4 +172,49 @@ public ResponseEntity<List<ResourceData>> getAllStudyResourceDataInStudy(
}
}

@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<List<ResourceData>> 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<>(this.getInstance().cacheableFetchAllResourceDataForStudyPatientSample(
studyId, resourceId, projection.name(), pageSize, pageNumber, sortBy == null ? null : sortBy.getOriginalValue(),
direction.name()) , HttpStatus.OK);
}
}

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver"
//condition = "@cacheEnabledConfig.getEnabled() && #unfilteredQuery && (#sortBy == null || #sortBy.isEmpty())"
)
public List<ResourceData> cacheableFetchAllResourceDataForStudyPatientSample(String studyId, String resourceId, String projectionName,
Integer pageSize, Integer pageNumber, String sortBy, String directionName) throws StudyNotFoundException {

return resourceDataService.getAllResourceDataForStudyPatientSample(studyId, resourceId, projectionName, pageSize, pageNumber,
sortBy, directionName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,40 @@
</if>
</select>

</mapper>
<select id="getResourceDataForAllPatientsInStudy" resultType="org.cbioportal.model.ResourceData">
SELECT
<include refid="selectPatientResource">
<property name="prefix" value=""/>
</include>
FROM
cancer_study
JOIN
patient ON patient.CANCER_STUDY_ID=cancer_study.CANCER_STUDY_ID
JOIN
resource_patient ON resource_patient.INTERNAL_ID=patient.INTERNAL_ID
JOIN
resource_definition ON (resource_definition.RESOURCE_ID=resource_patient.RESOURCE_ID
AND cancer_study.CANCER_STUDY_ID=resource_definition.CANCER_STUDY_ID)
<include refid="whereStudy"/>
</select>

<select id="getResourceDataForAllSamplesInStudy" resultType="org.cbioportal.model.ResourceData">
SELECT
<include refid="selectSampleResource">
<property name="prefix" value=""/>
</include>
FROM
cancer_study
JOIN
patient ON patient.CANCER_STUDY_ID=cancer_study.CANCER_STUDY_ID
JOIN
sample ON sample.PATIENT_ID=patient.INTERNAL_ID
JOIN
resource_sample ON resource_sample.INTERNAL_ID=sample.INTERNAL_ID
JOIN
resource_definition ON (resource_definition.RESOURCE_ID=resource_sample.RESOURCE_ID
AND cancer_study.CANCER_STUDY_ID=resource_definition.CANCER_STUDY_ID)
<include refid="whereStudy"/>
</select>

</mapper>
Loading