Skip to content

Commit

Permalink
Add resource-data-all endpoint and MyBatis SQL methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hweej committed Oct 7, 2024
1 parent 74516be commit 728951c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1 deletion.
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;
}

}
35 changes: 35 additions & 0 deletions src/main/java/org/cbioportal/web/ResourceDataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,39 @@ public ResponseEntity<List<ResourceData>> 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<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<>(
resourceDataService.getAllResourceDataForStudyPatientSample(studyId, resourceId, projection.name(), pageSize, pageNumber,
sortBy == null ? null : sortBy.getOriginalValue(), direction.name()), HttpStatus.OK);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,38 @@
</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
<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
<include refid="whereStudy"/>
</select>

</mapper>

0 comments on commit 728951c

Please sign in to comment.