Skip to content

Commit

Permalink
Add cacheable method for fetching all data resources by study
Browse files Browse the repository at this point in the history
  • Loading branch information
hweej committed Oct 24, 2024
1 parent 728951c commit b50a31f
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 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,7 +172,6 @@ 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)
Expand Down Expand Up @@ -186,10 +200,21 @@ public ResponseEntity<List<ResourceData>> getAllStudyResourceDataInStudyPatientS
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);
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);
}

}

0 comments on commit b50a31f

Please sign in to comment.