From aad755a4eded74f70a510ba2b5d0f44d0f22eeb0 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Jagannathan <37613906+jagnathan@users.noreply.github.com> Date: Tue, 8 Mar 2022 17:06:50 -0500 Subject: [PATCH 1/5] Changes to API endpoints Changes to API endpoints - SV, Generic Assay, Info --- .../web/GenericAssayController.java | 81 ------------ .../web/GenericAssayDataController.java | 119 ++++++++++++++++++ .../org/cbioportal/web/InfoController.java | 7 +- .../web/ServerStatusController.java | 3 +- .../web/StructuralVariantController.java | 8 +- .../web/config/InternalApiTags.java | 1 + .../cbioportal/web/config/PublicApiTags.java | 3 +- .../cbioportal/web/config/SwaggerConfig.java | 3 +- 8 files changed, 134 insertions(+), 91 deletions(-) create mode 100644 web/src/main/java/org/cbioportal/web/GenericAssayDataController.java diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayController.java b/web/src/main/java/org/cbioportal/web/GenericAssayController.java index a26ce032605..c8f564ff934 100644 --- a/web/src/main/java/org/cbioportal/web/GenericAssayController.java +++ b/web/src/main/java/org/cbioportal/web/GenericAssayController.java @@ -71,85 +71,4 @@ public ResponseEntity> fetchGenericAssayMetaData( return new ResponseEntity<>(result, HttpStatus.OK); } - @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch", - method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("fetch generic_assay_data in a molecular profile") - public ResponseEntity> fetchGenericAssayDataInMolecularProfile( - @ApiParam(required = true, value = "Molecular Profile ID") - @PathVariable String molecularProfileId, - @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Generic Assay IDs") - @Valid @RequestBody GenericAssayFilter genericAssayDataFilter, - @ApiParam("Level of detail of the response") - @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { - - List result; - if (genericAssayDataFilter.getSampleListId() != null) { - result = filterEmptyGenericAssayData(genericAssayService.getGenericAssayData(molecularProfileId, - genericAssayDataFilter.getSampleListId(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); - } else { - result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId, - genericAssayDataFilter.getSampleIds(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); - } - - if (projection == Projection.META) { - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); - return new ResponseEntity<>(responseHeaders, HttpStatus.OK); - } else { - return new ResponseEntity<>(result, HttpStatus.OK); - } - } - - @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/generic_assay_data/fetch", method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Fetch generic_assay_data") - public ResponseEntity> fetchGenericAssayDataInMultipleMolecularProfiles( - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface - @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. - @RequestAttribute(required = false, value = "interceptedGenericAssayDataMultipleStudyFilter") GenericAssayDataMultipleStudyFilter interceptedGenericAssayDataMultipleStudyFilter, - @ApiParam(required = true, value = "List of Molecular Profile ID and Sample ID pairs or List of Molecular" + - "Profile IDs and Generic Assay IDs") - @Valid @RequestBody(required = false) GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter, - @ApiParam("Level of detail of the response") - @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { - - List result; - if (interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds() != null) { - result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData( - interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds(), null, - interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); - } else { - - List molecularProfileIds = new ArrayList<>(); - List sampleIds = new ArrayList<>(); - extractMolecularProfileAndSampleIds(interceptedGenericAssayDataMultipleStudyFilter, molecularProfileIds, sampleIds); - result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileIds, - sampleIds, interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); - } - - if (projection == Projection.META) { - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); - return new ResponseEntity<>(responseHeaders, HttpStatus.OK); - } else { - return new ResponseEntity<>(result, HttpStatus.OK); - } - } - - private void extractMolecularProfileAndSampleIds(GenericAssayDataMultipleStudyFilter molecularDataMultipleStudyFilter, List molecularProfileIds, List sampleIds) { - for (SampleMolecularIdentifier sampleMolecularIdentifier : molecularDataMultipleStudyFilter.getSampleMolecularIdentifiers()) { - molecularProfileIds.add(sampleMolecularIdentifier.getMolecularProfileId()); - sampleIds.add(sampleMolecularIdentifier.getSampleId()); - } - } - - private List filterEmptyGenericAssayData(List genericAssayDataList) { - return genericAssayDataList.stream() - .filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA")) - .collect(Collectors.toList()); - } } diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java new file mode 100644 index 00000000000..e6057a510b7 --- /dev/null +++ b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java @@ -0,0 +1,119 @@ +package org.cbioportal.web; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.apache.commons.lang3.StringUtils; +import org.cbioportal.model.GenericAssayData; +import org.cbioportal.service.GenericAssayService; +import org.cbioportal.service.exception.MolecularProfileNotFoundException; +import org.cbioportal.web.config.PublicApiTags; +import org.cbioportal.web.config.annotation.PublicApi; +import org.cbioportal.web.parameter.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +@PublicApi +@RestController +@Validated +@Api(tags = PublicApiTags.GENERIC_ASSAY_DATA, description = " ") +public class GenericAssayDataController { + + @Autowired + private GenericAssayService genericAssayService; + + @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch", + method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("fetch generic_assay_data in a molecular profile") + public ResponseEntity> fetchGenericAssayDataInMolecularProfile( + @ApiParam(required = true, value = "Molecular Profile ID") + @PathVariable String molecularProfileId, + @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Generic Assay IDs") + @Valid @RequestBody GenericAssayFilter genericAssayDataFilter, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { + + List result; + if (genericAssayDataFilter.getSampleListId() != null) { + result = filterEmptyGenericAssayData(genericAssayService.getGenericAssayData(molecularProfileId, + genericAssayDataFilter.getSampleListId(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); + } else { + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId, + genericAssayDataFilter.getSampleIds(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); + } + + if (projection == Projection.META) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); + } else { + return new ResponseEntity<>(result, HttpStatus.OK); + } + } + + @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/generic_assay_data/fetch", method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch generic_assay_data") + public ResponseEntity> fetchGenericAssayDataInMultipleMolecularProfiles( + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface + @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. + @RequestAttribute(required = false, value = "interceptedGenericAssayDataMultipleStudyFilter") GenericAssayDataMultipleStudyFilter interceptedGenericAssayDataMultipleStudyFilter, + @ApiParam(required = true, value = "List of Molecular Profile ID and Sample ID pairs or List of Molecular" + + "Profile IDs and Generic Assay IDs") + @Valid @RequestBody(required = false) GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { + + List result; + if (interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds() != null) { + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData( + interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds(), null, + interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); + } else { + + List molecularProfileIds = new ArrayList<>(); + List sampleIds = new ArrayList<>(); + extractMolecularProfileAndSampleIds(interceptedGenericAssayDataMultipleStudyFilter, molecularProfileIds, sampleIds); + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileIds, + sampleIds, interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); + } + + if (projection == Projection.META) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); + } else { + return new ResponseEntity<>(result, HttpStatus.OK); + } + } + + private void extractMolecularProfileAndSampleIds(GenericAssayDataMultipleStudyFilter molecularDataMultipleStudyFilter, List molecularProfileIds, List sampleIds) { + for (SampleMolecularIdentifier sampleMolecularIdentifier : molecularDataMultipleStudyFilter.getSampleMolecularIdentifiers()) { + molecularProfileIds.add(sampleMolecularIdentifier.getMolecularProfileId()); + sampleIds.add(sampleMolecularIdentifier.getSampleId()); + } + } + + private List filterEmptyGenericAssayData(List genericAssayDataList) { + return genericAssayDataList.stream() + .filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA")) + .collect(Collectors.toList()); + } +} diff --git a/web/src/main/java/org/cbioportal/web/InfoController.java b/web/src/main/java/org/cbioportal/web/InfoController.java index edc990a5179..567771176e5 100644 --- a/web/src/main/java/org/cbioportal/web/InfoController.java +++ b/web/src/main/java/org/cbioportal/web/InfoController.java @@ -3,7 +3,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.cbioportal.model.Info; -import org.cbioportal.web.config.annotation.InternalApi; +import org.cbioportal.web.config.PublicApiTags; +import org.cbioportal.web.config.annotation.PublicApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -13,10 +14,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -@InternalApi +@PublicApi @RestController @Validated -@Api(tags = "Info", description = " ") +@Api(tags = PublicApiTags.INFO, description = " ") public class InfoController { @Value("${portal.version}") diff --git a/web/src/main/java/org/cbioportal/web/ServerStatusController.java b/web/src/main/java/org/cbioportal/web/ServerStatusController.java index ffc8b71714f..6a24a017581 100644 --- a/web/src/main/java/org/cbioportal/web/ServerStatusController.java +++ b/web/src/main/java/org/cbioportal/web/ServerStatusController.java @@ -3,6 +3,7 @@ import org.cbioportal.service.ServerStatusService; import org.cbioportal.service.impl.ServerStatusServiceImpl.ServerStatusMessage; import org.cbioportal.web.config.annotation.InternalApi; +import org.cbioportal.web.config.annotation.PublicApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -15,7 +16,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -@InternalApi +@PublicApi @RestController @Validated @Api(tags = "Server running status", description = "This end point does not require authentication") diff --git a/web/src/main/java/org/cbioportal/web/StructuralVariantController.java b/web/src/main/java/org/cbioportal/web/StructuralVariantController.java index 39f68879490..2d67d4c9b59 100644 --- a/web/src/main/java/org/cbioportal/web/StructuralVariantController.java +++ b/web/src/main/java/org/cbioportal/web/StructuralVariantController.java @@ -31,8 +31,8 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.cbioportal.web.config.PublicApiTags; -import org.cbioportal.web.config.annotation.PublicApi; +import org.cbioportal.web.config.InternalApiTags; +import org.cbioportal.web.config.annotation.InternalApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -49,10 +49,10 @@ import javax.validation.Valid; import java.util.*; -@PublicApi +@InternalApi @RestController @Validated -@Api(tags = PublicApiTags.STRUCTURAL_VARIANTS, description = " ") +@Api(tags = InternalApiTags.STRUCTURAL_VARIANTS, description = " ") public class StructuralVariantController { @Autowired private StructuralVariantService structuralVariantService; diff --git a/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java b/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java index 19aafd8481f..810cbb21939 100644 --- a/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java +++ b/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java @@ -8,4 +8,5 @@ public class InternalApiTags { public static final String REFERENCE_GENOME_GENES = "Reference Genome Genes"; public static final String RESOURCE_DEFINITIONS = "Resource Definitions"; public static final String RESOURCE_DATA = "Resource Data"; + public static final String STRUCTURAL_VARIANTS = "Structural Variants"; } diff --git a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java index a0ec96adbd6..b6f62a3df33 100644 --- a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java +++ b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java @@ -16,5 +16,6 @@ public class PublicApiTags { public static final String GENES = "Genes"; public static final String GENE_PANELS = "Gene Panels"; public static final String GENERIC_ASSAYS = "Generic Assays"; - public static final String STRUCTURAL_VARIANTS = "Structural Variants"; + public static final String GENERIC_ASSAY_DATA = "Generic Assay Data"; + public static final String INFO = "Info"; } \ No newline at end of file diff --git a/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java b/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java index e0cd06ceba8..29fae7fc3b3 100644 --- a/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java +++ b/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java @@ -47,7 +47,8 @@ public Docket publicApi() { new Tag(PublicApiTags.GENES, "", 12), new Tag(PublicApiTags.GENE_PANELS, "", 13), new Tag(PublicApiTags.GENERIC_ASSAYS, "", 14), - new Tag(PublicApiTags.STRUCTURAL_VARIANTS, "", 15) + new Tag(PublicApiTags.GENERIC_ASSAY_DATA, "", 15), + new Tag(PublicApiTags.INFO, "", 16) ); return d; From 6693cbd88812b5ee8cf6881bc03c1465aa8935d2 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Jagannathan <37613906+jagnathan@users.noreply.github.com> Date: Tue, 12 Apr 2022 17:22:39 -0400 Subject: [PATCH 2/5] fix 9342 API endpoint changes fix #9342 API endpoint changes ; Split Gene Panel into Meta and Data, Added Generic assay Data. Added tests for all. --- .../cbioportal/web/GenePanelController.java | 54 ----- .../web/GenePanelDataController.java | 98 ++++++++ .../web/GenericAssayController.java | 34 ++- .../web/GenericAssayDataController.java | 28 +++ .../cbioportal/web/config/PublicApiTags.java | 1 + .../web/GenePanelControllerTest.java | 98 +------- .../web/GenePanelDataControllerTest.java | 181 +++++++++++++++ .../web/GenericAssayControllerTest.java | 178 +++++---------- .../web/GenericAssayDataControllerTest.java | 214 ++++++++++++++++++ 9 files changed, 608 insertions(+), 278 deletions(-) create mode 100644 web/src/main/java/org/cbioportal/web/GenePanelDataController.java create mode 100644 web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java create mode 100644 web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java diff --git a/web/src/main/java/org/cbioportal/web/GenePanelController.java b/web/src/main/java/org/cbioportal/web/GenePanelController.java index 1a9047996a5..93e3c293f14 100644 --- a/web/src/main/java/org/cbioportal/web/GenePanelController.java +++ b/web/src/main/java/org/cbioportal/web/GenePanelController.java @@ -98,58 +98,4 @@ public ResponseEntity> fetchGenePanels( return new ResponseEntity<>(genePanelService.fetchGenePanels(genePanelIds, projection.name()), HttpStatus.OK); } - - @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/molecular-profiles/{molecularProfileId}/gene-panel-data/fetch", method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Get gene panel data") - public ResponseEntity> getGenePanelData( - @ApiParam(required = true, value = "Molecular Profile ID e.g. nsclc_unito_2016_mutations") - @PathVariable String molecularProfileId, - @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Entrez Gene IDs") - @Valid @RequestBody GenePanelDataFilter genePanelDataFilter) throws MolecularProfileNotFoundException { - - List genePanelDataList; - if (genePanelDataFilter.getSampleListId() != null) { - genePanelDataList = genePanelService.getGenePanelData(molecularProfileId, - genePanelDataFilter.getSampleListId()); - } else { - genePanelDataList = genePanelService.fetchGenePanelData(molecularProfileId, - genePanelDataFilter.getSampleIds()); - } - - return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); - } - - @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/gene-panel-data/fetch", method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Fetch gene panel data") - public ResponseEntity> fetchGenePanelDataInMultipleMolecularProfiles( - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface - @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. - @Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter, - @ApiParam(required = true, value = "Gene panel data filter object") - @RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) { - - List genePanelDataList; - if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) { - List molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers() - .stream() - .map(sampleMolecularIdentifier -> { - MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier(); - profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId()); - profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId()); - return profileCaseIdentifier; - }) - .collect(Collectors.toList()); - - genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers); - } else { - genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())); - } - - return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); - } } diff --git a/web/src/main/java/org/cbioportal/web/GenePanelDataController.java b/web/src/main/java/org/cbioportal/web/GenePanelDataController.java new file mode 100644 index 00000000000..03ebec52c4f --- /dev/null +++ b/web/src/main/java/org/cbioportal/web/GenePanelDataController.java @@ -0,0 +1,98 @@ +package org.cbioportal.web; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.cbioportal.model.GenePanel; +import org.cbioportal.model.GenePanelData; +import org.cbioportal.model.MolecularProfileCaseIdentifier; +import org.cbioportal.service.GenePanelService; +import org.cbioportal.service.exception.GenePanelNotFoundException; +import org.cbioportal.service.exception.MolecularProfileNotFoundException; +import org.cbioportal.web.config.PublicApiTags; +import org.cbioportal.web.config.annotation.PublicApi; +import org.cbioportal.web.parameter.*; +import org.cbioportal.web.parameter.sort.GenePanelSortBy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.util.CollectionUtils; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.Size; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; + +@PublicApi +@RestController +@Validated +@Api(tags = PublicApiTags.GENE_PANEL_DATA, description = " ") +public class GenePanelDataController { + + @Autowired + private GenePanelService genePanelService; + + @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/molecular-profiles/{molecularProfileId}/gene-panel-data/fetch", method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Get gene panel data") + public ResponseEntity> getGenePanelData( + @ApiParam(required = true, value = "Molecular Profile ID e.g. nsclc_unito_2016_mutations") + @PathVariable String molecularProfileId, + @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Entrez Gene IDs") + @Valid @RequestBody GenePanelDataFilter genePanelDataFilter) throws MolecularProfileNotFoundException { + + List genePanelDataList; + if (genePanelDataFilter.getSampleListId() != null) { + genePanelDataList = genePanelService.getGenePanelData(molecularProfileId, + genePanelDataFilter.getSampleListId()); + } else { + genePanelDataList = genePanelService.fetchGenePanelData(molecularProfileId, + genePanelDataFilter.getSampleIds()); + } + + return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); + } + + @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/gene-panel-data/fetch", method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch gene panel data") + public ResponseEntity> fetchGenePanelDataInMultipleMolecularProfiles( + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface + @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. + @Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter, + @ApiParam(required = true, value = "Gene panel data filter object") + @RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) { + + List genePanelDataList; + if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) { + List molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers() + .stream() + .map(sampleMolecularIdentifier -> { + MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier(); + profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId()); + profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId()); + return profileCaseIdentifier; + }) + .collect(Collectors.toList()); + + genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers); + } else { + genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())); + } + + return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); + } +} diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayController.java b/web/src/main/java/org/cbioportal/web/GenericAssayController.java index c8f564ff934..652ffe3e97d 100644 --- a/web/src/main/java/org/cbioportal/web/GenericAssayController.java +++ b/web/src/main/java/org/cbioportal/web/GenericAssayController.java @@ -7,6 +7,7 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -54,7 +55,7 @@ public class GenericAssayController { @RequestMapping(value = "/generic_assay_meta/fetch", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Fetch meta data for generic-assay by ID") - public ResponseEntity> fetchGenericAssayMetaData( + public ResponseEntity> fetchGenericAssayMeta( @ApiParam(required = true, value = "List of Molecular Profile ID or List of Stable ID") @Valid @RequestBody GenericAssayMetaFilter genericAssayMetaFilter, @ApiParam("Level of detail of the response") @@ -71,4 +72,35 @@ public ResponseEntity> fetchGenericAssayMetaData( return new ResponseEntity<>(result, HttpStatus.OK); } + // PreAuthorize is removed for performance reason + @RequestMapping(value = "/generic-assay-meta/{molecularProfileId}", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch meta data for generic-assay by ID") + public ResponseEntity> getGenericAssayMeta( + @ApiParam(required = true, value = "Molecular Profile ID") + @PathVariable String molecularProfileId, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws GenericAssayNotFoundException { + List result; + + result = genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(null, Arrays.asList(molecularProfileId), projection.name()); + + return new ResponseEntity<>(result, HttpStatus.OK); + } + + @RequestMapping(value = "/generic-assay-meta/generic-assay/{genericAssayStableId}", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch meta data for generic-assay by ID") + public ResponseEntity> getGenericAssayMeta_ga( + @ApiParam(required = false, value = "Generic Assay stable ID") + @PathVariable String genericAssayStableId, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws GenericAssayNotFoundException { + List result; + result = genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Arrays.asList(genericAssayStableId), null, projection.name()); + + return new ResponseEntity<>(result, HttpStatus.OK); + } + + } diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java index e6057a510b7..5b546f63889 100644 --- a/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java +++ b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java @@ -4,8 +4,10 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; +import org.cbioportal.model.GenePanel; import org.cbioportal.model.GenericAssayData; import org.cbioportal.service.GenericAssayService; +import org.cbioportal.service.exception.GenePanelNotFoundException; import org.cbioportal.service.exception.MolecularProfileNotFoundException; import org.cbioportal.web.config.PublicApiTags; import org.cbioportal.web.config.annotation.PublicApi; @@ -22,6 +24,7 @@ import javax.validation.Valid; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -34,6 +37,31 @@ public class GenericAssayDataController { @Autowired private GenericAssayService genericAssayService; + + @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/generic-assay-data/{molecularProfileId}/generic-assay/{genericAssayStableId}", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Get generic_assay_data in a molecular profile") + public ResponseEntity> getGenericAssayDataInMolecularProfile( + @ApiParam(required = true, value = "Molecular Profile ID") + @PathVariable String molecularProfileId, + @ApiParam(required = true, value = "Generic Assay stable ID") + @PathVariable String genericAssayStableId, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { + + List result; + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId, + null, Arrays.asList(genericAssayStableId) , projection.name())); + + if (projection == Projection.META) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); + } else { + return new ResponseEntity<>(result, HttpStatus.OK); + } + } @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") @RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch", diff --git a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java index b6f62a3df33..55952192cfa 100644 --- a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java +++ b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java @@ -15,6 +15,7 @@ public class PublicApiTags { public static final String COPY_NUMBER_SEGMENTS = "Copy Number Segments"; public static final String GENES = "Genes"; public static final String GENE_PANELS = "Gene Panels"; + public static final String GENE_PANEL_DATA = "Gene Panel Data"; public static final String GENERIC_ASSAYS = "Generic Assays"; public static final String GENERIC_ASSAY_DATA = "Generic Assay Data"; public static final String INFO = "Info"; diff --git a/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java b/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java index 0c88160c2b6..bc30903590c 100644 --- a/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java @@ -164,8 +164,7 @@ public void getAllGenePanelsMetaProjection() throws Exception { .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.header().string(HeaderKeyConstants.TOTAL_COUNT, "2")); } - - + @Test public void getGenePanelNotFound() throws Exception { @@ -214,98 +213,5 @@ public void getGenePanel() throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$.genes[1].entrezGeneId").value(TEST_ENTREZ_GENE_ID_2)) .andExpect(MockMvcResultMatchers.jsonPath("$.genes[1].hugoGeneSymbol").value(TEST_HUGO_GENE_SYMBOL_2)); } - - @Test - public void getGenePanelData() throws Exception { - - List genePanelDataList = createExampleGenePanelData(); - - Mockito.when(genePanelService.getGenePanelData(Mockito.anyString(), Mockito.anyString())).thenReturn(genePanelDataList); - - GenePanelDataFilter genePanelDataFilter = new GenePanelDataFilter(); - genePanelDataFilter.setSampleListId(TEST_SAMPLE_LIST_ID); - - mockMvc.perform(MockMvcRequestBuilders.post( - "/molecular-profiles/test_molecular_profile_id/gene-panel-data/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genePanelDataFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); - } - - @Test - public void fetchGenePanelData() throws Exception { - - List genePanelDataList = createExampleGenePanelData(); - - Mockito.when(genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(Mockito.anyList())).thenReturn(genePanelDataList); - - List sampleMolecularIdentifiers = new ArrayList<>(); - SampleMolecularIdentifier sampleMolecularIdentifier1 = new SampleMolecularIdentifier(); - sampleMolecularIdentifier1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); - sampleMolecularIdentifier1.setSampleId(TEST_SAMPLE_ID_1); - sampleMolecularIdentifiers.add(sampleMolecularIdentifier1); - SampleMolecularIdentifier sampleMolecularIdentifier2 = new SampleMolecularIdentifier(); - sampleMolecularIdentifier2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); - sampleMolecularIdentifier2.setSampleId(TEST_SAMPLE_ID_2); - sampleMolecularIdentifiers.add(sampleMolecularIdentifier2); - GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter = new GenePanelDataMultipleStudyFilter(); - genePanelDataMultipleStudyFilter.setSampleMolecularIdentifiers(sampleMolecularIdentifiers); - - mockMvc.perform(MockMvcRequestBuilders.post( - "/gene-panel-data/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genePanelDataMultipleStudyFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); - } - - private List createExampleGenePanelData() { - - List genePanelDataList = new ArrayList<>(); - GenePanelData genePanelData1 = new GenePanelData(); - genePanelData1.setGenePanelId(TEST_GENE_PANEL_ID_1); - genePanelData1.setSampleId(TEST_SAMPLE_ID_1); - genePanelData1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); - genePanelData1.setPatientId(TEST_PATIENT_ID_1); - genePanelData1.setStudyId(TEST_STUDY_ID_1); - genePanelData1.setProfiled(true); - genePanelDataList.add(genePanelData1); - GenePanelData genePanelData2 = new GenePanelData(); - genePanelData2.setSampleId(TEST_SAMPLE_ID_2); - genePanelData2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); - genePanelData2.setPatientId(TEST_PATIENT_ID_2); - genePanelData2.setStudyId(TEST_STUDY_ID_2); - genePanelData2.setProfiled(true); - genePanelDataList.add(genePanelData2); - return genePanelDataList; - } + } diff --git a/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java b/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java new file mode 100644 index 00000000000..b810260b874 --- /dev/null +++ b/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java @@ -0,0 +1,181 @@ +package org.cbioportal.web; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.cbioportal.model.GenePanel; +import org.cbioportal.model.GenePanelData; +import org.cbioportal.model.GenePanelToGene; +import org.cbioportal.model.meta.BaseMeta; +import org.cbioportal.service.GenePanelService; +import org.cbioportal.service.exception.GenePanelNotFoundException; +import org.cbioportal.web.parameter.GenePanelDataFilter; +import org.cbioportal.web.parameter.GenePanelDataMultipleStudyFilter; +import org.cbioportal.web.parameter.HeaderKeyConstants; +import org.cbioportal.web.parameter.SampleMolecularIdentifier; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration("/applicationContext-web-test.xml") +@Configuration +public class GenePanelDataControllerTest { + + private static final String TEST_GENE_PANEL_ID_1 = "test_gene_panel_id_1"; + private static final int TEST_INTERNAL_ID_1 = 1; + private static final String TEST_DESCRIPTION_1 = "test_description_1"; + private static final String TEST_SAMPLE_ID_1 = "test_sample_id_1"; + private static final String TEST_PATIENT_ID_1 = "test_patient_id_1"; + private static final String TEST_STUDY_ID_1 = "test_study_id_1"; + private static final String TEST_MOLECULAR_PROFILE_ID_1 = "test_molecular_profile_id_1"; + private static final int TEST_ENTREZ_GENE_ID_1 = 100; + private static final String TEST_HUGO_GENE_SYMBOL_1 = "test_hugo_gene_symbol_1"; + private static final int TEST_ENTREZ_GENE_ID_2 = 200; + private static final String TEST_HUGO_GENE_SYMBOL_2 = "test_hugo_gene_symbol_2"; + private static final String TEST_GENE_PANEL_ID_2 = "test_gene_panel_id_2"; + private static final int TEST_INTERNAL_ID_2 = 2; + private static final String TEST_DESCRIPTION_2 = "test_description_2"; + private static final String TEST_SAMPLE_ID_2 = "test_sample_id_2"; + private static final String TEST_PATIENT_ID_2 = "test_patient_id_2"; + private static final String TEST_STUDY_ID_2 = "test_study_id_2"; + private static final String TEST_MOLECULAR_PROFILE_ID_2 = "test_molecular_profile_id_2"; + private static final int TEST_ENTREZ_GENE_ID_3 = 300; + private static final String TEST_HUGO_GENE_SYMBOL_3 = "test_hugo_gene_symbol_3"; + private static final int TEST_ENTREZ_GENE_ID_4 = 400; + private static final String TEST_HUGO_GENE_SYMBOL_4 = "test_hugo_gene_symbol_4"; + private static final String TEST_SAMPLE_LIST_ID = "test_sample_list_id"; + + @Autowired + private WebApplicationContext wac; + + @Autowired + private GenePanelService genePanelService; + + private ObjectMapper objectMapper = new ObjectMapper(); + + private MockMvc mockMvc; + + @Bean + public GenePanelService genePanelService() { + return Mockito.mock(GenePanelService.class); + } + + @Before + public void setUp() throws Exception { + + Mockito.reset(genePanelService); + mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); + } + + @Test + public void getGenePanelData() throws Exception { + + List genePanelDataList = createExampleGenePanelData(); + + Mockito.when(genePanelService.getGenePanelData(Mockito.anyString(), Mockito.anyString())).thenReturn(genePanelDataList); + + GenePanelDataFilter genePanelDataFilter = new GenePanelDataFilter(); + genePanelDataFilter.setSampleListId(TEST_SAMPLE_LIST_ID); + + mockMvc.perform(MockMvcRequestBuilders.post( + "/molecular-profiles/test_molecular_profile_id/gene-panel-data/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genePanelDataFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); + } + + @Test + public void fetchGenePanelData() throws Exception { + + List genePanelDataList = createExampleGenePanelData(); + + Mockito.when(genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(Mockito.anyList())).thenReturn(genePanelDataList); + + List sampleMolecularIdentifiers = new ArrayList<>(); + SampleMolecularIdentifier sampleMolecularIdentifier1 = new SampleMolecularIdentifier(); + sampleMolecularIdentifier1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); + sampleMolecularIdentifier1.setSampleId(TEST_SAMPLE_ID_1); + sampleMolecularIdentifiers.add(sampleMolecularIdentifier1); + SampleMolecularIdentifier sampleMolecularIdentifier2 = new SampleMolecularIdentifier(); + sampleMolecularIdentifier2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); + sampleMolecularIdentifier2.setSampleId(TEST_SAMPLE_ID_2); + sampleMolecularIdentifiers.add(sampleMolecularIdentifier2); + GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter = new GenePanelDataMultipleStudyFilter(); + genePanelDataMultipleStudyFilter.setSampleMolecularIdentifiers(sampleMolecularIdentifiers); + + mockMvc.perform(MockMvcRequestBuilders.post( + "/gene-panel-data/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genePanelDataMultipleStudyFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); + } + + private List createExampleGenePanelData() { + + List genePanelDataList = new ArrayList<>(); + GenePanelData genePanelData1 = new GenePanelData(); + genePanelData1.setGenePanelId(TEST_GENE_PANEL_ID_1); + genePanelData1.setSampleId(TEST_SAMPLE_ID_1); + genePanelData1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); + genePanelData1.setPatientId(TEST_PATIENT_ID_1); + genePanelData1.setStudyId(TEST_STUDY_ID_1); + genePanelData1.setProfiled(true); + genePanelDataList.add(genePanelData1); + GenePanelData genePanelData2 = new GenePanelData(); + genePanelData2.setSampleId(TEST_SAMPLE_ID_2); + genePanelData2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); + genePanelData2.setPatientId(TEST_PATIENT_ID_2); + genePanelData2.setStudyId(TEST_STUDY_ID_2); + genePanelData2.setProfiled(true); + genePanelDataList.add(genePanelData2); + return genePanelDataList; + } +} diff --git a/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java b/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java index e46d3da34db..d1f4a5662c9 100644 --- a/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java @@ -78,73 +78,15 @@ public void setUp() throws Exception { Mockito.reset(genericAssayService); mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } - - @Test - public void testGenericAssayDataFetch() throws Exception { - List genericAssayDataItems = createGenericAssayDataItemsList(); - Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyString(), Mockito.anyList(), - Mockito.anyList(), Mockito.anyString())).thenReturn(genericAssayDataItems); - - GenericAssayFilter genericAssayDataFilter = new GenericAssayFilter(); - genericAssayDataFilter.setSampleIds(Arrays.asList(SAMPLE_ID)); - genericAssayDataFilter.setGenericAssayStableIds(Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ASSAY_STABLE_ID_3, GENERIC_ASSAY_STABLE_ID_4)); - - mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/" + PROF_ID + "/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genericAssayDataFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); - } - - @Test - public void testGenericAssayDataFetchInMultipleMolecularProfiles() throws Exception { - List genericAssayDataItems = createGenericAssayDataItemsList(); - GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter = new GenericAssayDataMultipleStudyFilter(); - genericAssayDataMultipleStudyFilter.setSampleMolecularIdentifiers(createSampleMolecularIdentifiers()); - - Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyList(), Mockito.any(), - Mockito.any(), Mockito.any())).thenReturn(genericAssayDataItems); - - mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genericAssayDataMultipleStudyFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); - } - + @Test - public void testGenericAssayMetaDataFetch() throws Exception { + public void testGenericAssayMetaGetMolecularProfileId() throws Exception { List genericAssayMetaItems = createGenericAssayMetaItemsList(); - List genericAssayStableIds = Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2); - GenericAssayMetaFilter genericAssayMetaFilter = new GenericAssayMetaFilter(); - genericAssayMetaFilter.setGenericAssayStableIds(genericAssayStableIds); Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); - mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_meta/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genericAssayMetaFilter))) + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-meta/" + PROF_ID) + .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) @@ -158,81 +100,63 @@ public void testGenericAssayMetaDataFetch() throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); } - private List createGenericAssayMetaItemsList() { - - List genericAssayMetaItems = new ArrayList<>(); - - GenericAssayMeta item1 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_1); - genericAssayMetaItems.add(item1); - GenericAssayMeta item2 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ENTITY_META_PROPERTIES); - genericAssayMetaItems.add(item2); + @Test + public void testGenericAssayMetaGetGenericAssayStableId() throws Exception { + List genericAssayMetaItems = createGenericAssayMetaItemsList(); - return genericAssayMetaItems; - } + Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); - private List createGenericAssayDataItemsList() { - - List genericAssayDataItems = new ArrayList<>(); - - GenericAssayData item1 = new GenericAssayData(); - item1.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_1); - item1.setMolecularProfileId(PROF_ID); - item1.setSampleId(SAMPLE_ID); - item1.setValue(VALUE_1); - genericAssayDataItems.add(item1); - - GenericAssayData item2 = new GenericAssayData(); - item2.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_2); - item2.setMolecularProfileId(PROF_ID); - item2.setSampleId(SAMPLE_ID); - item2.setValue(VALUE_2); - genericAssayDataItems.add(item2); - - // This item should be filtered out in api result - GenericAssayData item3 = new GenericAssayData(); - item3.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_3); - item3.setMolecularProfileId(PROF_ID); - item3.setSampleId(SAMPLE_ID); - item3.setValue(VALUE_3); - genericAssayDataItems.add(item3); - - // This item should be filtered out in api result - GenericAssayData item4 = new GenericAssayData(); - item4.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_4); - item4.setMolecularProfileId(PROF_ID); - item4.setSampleId(SAMPLE_ID); - item4.setValue(VALUE_4); - genericAssayDataItems.add(item4); - - return genericAssayDataItems; + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-meta/" + PROF_ID + "/generic-assay/" + GENERIC_ASSAY_STABLE_ID_2) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].entityType").value(ENTITY_TYPE)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].stableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasKey(TEST_NAME))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasValue(TEST_NAME_VALUE))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasKey(TEST_DESCRIPTION))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); } - private List createSampleMolecularIdentifiers() { + @Test + public void testGenericAssayMetaFetch() throws Exception { + List genericAssayMetaItems = createGenericAssayMetaItemsList(); + List genericAssayStableIds = Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2); + GenericAssayMetaFilter genericAssayMetaFilter = new GenericAssayMetaFilter(); + genericAssayMetaFilter.setGenericAssayStableIds(genericAssayStableIds); - List sampleMolecularIdentifiers = new ArrayList<>(); + Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); - SampleMolecularIdentifier identifier1 = new SampleMolecularIdentifier(); - identifier1.setSampleId(SAMPLE_ID); - identifier1.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_1); - sampleMolecularIdentifiers.add(identifier1); + mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_meta/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genericAssayMetaFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].entityType").value(ENTITY_TYPE)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].stableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].entityType").value(ENTITY_TYPE)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].stableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasKey(TEST_NAME))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_NAME_VALUE))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasKey(TEST_DESCRIPTION))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); + } + + private List createGenericAssayMetaItemsList() { - SampleMolecularIdentifier identifier2 = new SampleMolecularIdentifier(); - identifier2.setSampleId(SAMPLE_ID); - identifier2.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_2); - sampleMolecularIdentifiers.add(identifier2); + List genericAssayMetaItems = new ArrayList<>(); - SampleMolecularIdentifier identifier3 = new SampleMolecularIdentifier(); - identifier3.setSampleId(SAMPLE_ID); - identifier3.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_3); - sampleMolecularIdentifiers.add(identifier3); + GenericAssayMeta item1 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_1); + genericAssayMetaItems.add(item1); - SampleMolecularIdentifier identifier4 = new SampleMolecularIdentifier(); - identifier4.setSampleId(SAMPLE_ID); - identifier4.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_4); - sampleMolecularIdentifiers.add(identifier4); + GenericAssayMeta item2 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ENTITY_META_PROPERTIES); + genericAssayMetaItems.add(item2); - return sampleMolecularIdentifiers; + return genericAssayMetaItems; } - } \ No newline at end of file diff --git a/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java b/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java new file mode 100644 index 00000000000..d017d88e1b5 --- /dev/null +++ b/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java @@ -0,0 +1,214 @@ +package org.cbioportal.web; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.cbioportal.model.GenericAssayData; +import org.cbioportal.model.meta.GenericAssayMeta; +import org.cbioportal.service.GenericAssayService; +import org.cbioportal.web.parameter.GenericAssayDataMultipleStudyFilter; +import org.cbioportal.web.parameter.GenericAssayFilter; +import org.cbioportal.web.parameter.GenericAssayMetaFilter; +import org.cbioportal.web.parameter.SampleMolecularIdentifier; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration("/applicationContext-web.xml") +@Configuration +public class GenericAssayDataControllerTest { + + private static final String PROF_ID = "test_prof_id"; + private static final String ENTITY_TYPE = "test_type"; + public static final String GENERIC_ASSAY_STABLE_ID_1 = "genericAssayStableId1"; + public static final String GENERIC_ASSAY_STABLE_ID_2 = "genericAssayStableId2"; + public static final String GENERIC_ASSAY_STABLE_ID_3 = "genericAssayStableId3"; + public static final String GENERIC_ASSAY_STABLE_ID_4 = "genericAssayStableId4"; + private static final String SAMPLE_ID = "test_sample_stable_id_1"; + private static final String VALUE_1 = "0.25"; + private static final String VALUE_2 = "-0.75"; + private static final String VALUE_3 = ""; + private static final String VALUE_4 = "NA"; + private static final String TEST_NAME = "name"; + private static final String TEST_NAME_VALUE = "test_name"; + private static final String TEST_DESCRIPTION = "description"; + private static final String TEST_DESCRIPTION_VALUE = "test_description"; + private static final HashMap GENERIC_ENTITY_META_PROPERTIES = new HashMap() {{ + put(TEST_NAME,TEST_NAME_VALUE); + put(TEST_DESCRIPTION,TEST_DESCRIPTION_VALUE); + }}; + + @Autowired + private WebApplicationContext wac; + + @Autowired + private GenericAssayService genericAssayService; + private MockMvc mockMvc; + + private ObjectMapper objectMapper = new ObjectMapper(); + + @Bean + public GenericAssayService genericAssayService() { + return Mockito.mock(GenericAssayService.class); + } + + @Before + public void setUp() throws Exception { + + Mockito.reset(genericAssayService); + mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); + } + + @Test + public void testGenericAssayDataFetch() throws Exception { + List genericAssayDataItems = createGenericAssayDataItemsList(); + Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyString(), Mockito.anyList(), + Mockito.anyList(), Mockito.anyString())).thenReturn(genericAssayDataItems); + + GenericAssayFilter genericAssayDataFilter = new GenericAssayFilter(); + genericAssayDataFilter.setSampleIds(Arrays.asList(SAMPLE_ID)); + genericAssayDataFilter.setGenericAssayStableIds(Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ASSAY_STABLE_ID_3, GENERIC_ASSAY_STABLE_ID_4)); + + mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/" + PROF_ID + "/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genericAssayDataFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); + } + + @Test + public void testGenericAssayDataFetchInMultipleMolecularProfiles() throws Exception { + List genericAssayDataItems = createGenericAssayDataItemsList(); + GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter = new GenericAssayDataMultipleStudyFilter(); + genericAssayDataMultipleStudyFilter.setSampleMolecularIdentifiers(createSampleMolecularIdentifiers()); + + Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyList(), Mockito.any(), + Mockito.any(), Mockito.any())).thenReturn(genericAssayDataItems); + + mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genericAssayDataMultipleStudyFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); + } + + public void testGenericAssayDataGet() throws Exception { + List genericAssayDataItems = createGenericAssayDataItemsList(); + Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyString(), Mockito.anyList(), + Mockito.anyList(), Mockito.anyString())).thenReturn(genericAssayDataItems); + + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-data/" + PROF_ID + "/generic-assay/" + GENERIC_ASSAY_STABLE_ID_1) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)); + } + + private List createGenericAssayDataItemsList() { + + List genericAssayDataItems = new ArrayList<>(); + + GenericAssayData item1 = new GenericAssayData(); + item1.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_1); + item1.setMolecularProfileId(PROF_ID); + item1.setSampleId(SAMPLE_ID); + item1.setValue(VALUE_1); + genericAssayDataItems.add(item1); + + GenericAssayData item2 = new GenericAssayData(); + item2.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_2); + item2.setMolecularProfileId(PROF_ID); + item2.setSampleId(SAMPLE_ID); + item2.setValue(VALUE_2); + genericAssayDataItems.add(item2); + + // This item should be filtered out in api result + GenericAssayData item3 = new GenericAssayData(); + item3.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_3); + item3.setMolecularProfileId(PROF_ID); + item3.setSampleId(SAMPLE_ID); + item3.setValue(VALUE_3); + genericAssayDataItems.add(item3); + + // This item should be filtered out in api result + GenericAssayData item4 = new GenericAssayData(); + item4.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_4); + item4.setMolecularProfileId(PROF_ID); + item4.setSampleId(SAMPLE_ID); + item4.setValue(VALUE_4); + genericAssayDataItems.add(item4); + + return genericAssayDataItems; + } + + private List createSampleMolecularIdentifiers() { + + List sampleMolecularIdentifiers = new ArrayList<>(); + + SampleMolecularIdentifier identifier1 = new SampleMolecularIdentifier(); + identifier1.setSampleId(SAMPLE_ID); + identifier1.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_1); + sampleMolecularIdentifiers.add(identifier1); + + SampleMolecularIdentifier identifier2 = new SampleMolecularIdentifier(); + identifier2.setSampleId(SAMPLE_ID); + identifier2.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_2); + sampleMolecularIdentifiers.add(identifier2); + + SampleMolecularIdentifier identifier3 = new SampleMolecularIdentifier(); + identifier3.setSampleId(SAMPLE_ID); + identifier3.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_3); + sampleMolecularIdentifiers.add(identifier3); + + SampleMolecularIdentifier identifier4 = new SampleMolecularIdentifier(); + identifier4.setSampleId(SAMPLE_ID); + identifier4.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_4); + sampleMolecularIdentifiers.add(identifier4); + + return sampleMolecularIdentifiers; + } + +} \ No newline at end of file From 821e1bc9255694d9b971f353967ae8df3ceaaeea Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Jagannathan <37613906+jagnathan@users.noreply.github.com> Date: Tue, 8 Mar 2022 17:06:50 -0500 Subject: [PATCH 3/5] Changes to API endpoints Changes to API endpoints - SV, Generic Assay, Info --- .../web/GenericAssayController.java | 81 ------------ .../web/GenericAssayDataController.java | 119 ++++++++++++++++++ .../org/cbioportal/web/InfoController.java | 7 +- .../web/ServerStatusController.java | 3 +- .../web/StructuralVariantController.java | 8 +- .../web/config/InternalApiTags.java | 1 + .../cbioportal/web/config/PublicApiTags.java | 3 +- .../cbioportal/web/config/SwaggerConfig.java | 3 +- 8 files changed, 134 insertions(+), 91 deletions(-) create mode 100644 web/src/main/java/org/cbioportal/web/GenericAssayDataController.java diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayController.java b/web/src/main/java/org/cbioportal/web/GenericAssayController.java index a26ce032605..c8f564ff934 100644 --- a/web/src/main/java/org/cbioportal/web/GenericAssayController.java +++ b/web/src/main/java/org/cbioportal/web/GenericAssayController.java @@ -71,85 +71,4 @@ public ResponseEntity> fetchGenericAssayMetaData( return new ResponseEntity<>(result, HttpStatus.OK); } - @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch", - method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("fetch generic_assay_data in a molecular profile") - public ResponseEntity> fetchGenericAssayDataInMolecularProfile( - @ApiParam(required = true, value = "Molecular Profile ID") - @PathVariable String molecularProfileId, - @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Generic Assay IDs") - @Valid @RequestBody GenericAssayFilter genericAssayDataFilter, - @ApiParam("Level of detail of the response") - @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { - - List result; - if (genericAssayDataFilter.getSampleListId() != null) { - result = filterEmptyGenericAssayData(genericAssayService.getGenericAssayData(molecularProfileId, - genericAssayDataFilter.getSampleListId(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); - } else { - result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId, - genericAssayDataFilter.getSampleIds(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); - } - - if (projection == Projection.META) { - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); - return new ResponseEntity<>(responseHeaders, HttpStatus.OK); - } else { - return new ResponseEntity<>(result, HttpStatus.OK); - } - } - - @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/generic_assay_data/fetch", method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Fetch generic_assay_data") - public ResponseEntity> fetchGenericAssayDataInMultipleMolecularProfiles( - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface - @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. - @RequestAttribute(required = false, value = "interceptedGenericAssayDataMultipleStudyFilter") GenericAssayDataMultipleStudyFilter interceptedGenericAssayDataMultipleStudyFilter, - @ApiParam(required = true, value = "List of Molecular Profile ID and Sample ID pairs or List of Molecular" + - "Profile IDs and Generic Assay IDs") - @Valid @RequestBody(required = false) GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter, - @ApiParam("Level of detail of the response") - @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { - - List result; - if (interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds() != null) { - result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData( - interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds(), null, - interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); - } else { - - List molecularProfileIds = new ArrayList<>(); - List sampleIds = new ArrayList<>(); - extractMolecularProfileAndSampleIds(interceptedGenericAssayDataMultipleStudyFilter, molecularProfileIds, sampleIds); - result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileIds, - sampleIds, interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); - } - - if (projection == Projection.META) { - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); - return new ResponseEntity<>(responseHeaders, HttpStatus.OK); - } else { - return new ResponseEntity<>(result, HttpStatus.OK); - } - } - - private void extractMolecularProfileAndSampleIds(GenericAssayDataMultipleStudyFilter molecularDataMultipleStudyFilter, List molecularProfileIds, List sampleIds) { - for (SampleMolecularIdentifier sampleMolecularIdentifier : molecularDataMultipleStudyFilter.getSampleMolecularIdentifiers()) { - molecularProfileIds.add(sampleMolecularIdentifier.getMolecularProfileId()); - sampleIds.add(sampleMolecularIdentifier.getSampleId()); - } - } - - private List filterEmptyGenericAssayData(List genericAssayDataList) { - return genericAssayDataList.stream() - .filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA")) - .collect(Collectors.toList()); - } } diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java new file mode 100644 index 00000000000..e6057a510b7 --- /dev/null +++ b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java @@ -0,0 +1,119 @@ +package org.cbioportal.web; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.apache.commons.lang3.StringUtils; +import org.cbioportal.model.GenericAssayData; +import org.cbioportal.service.GenericAssayService; +import org.cbioportal.service.exception.MolecularProfileNotFoundException; +import org.cbioportal.web.config.PublicApiTags; +import org.cbioportal.web.config.annotation.PublicApi; +import org.cbioportal.web.parameter.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +@PublicApi +@RestController +@Validated +@Api(tags = PublicApiTags.GENERIC_ASSAY_DATA, description = " ") +public class GenericAssayDataController { + + @Autowired + private GenericAssayService genericAssayService; + + @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch", + method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("fetch generic_assay_data in a molecular profile") + public ResponseEntity> fetchGenericAssayDataInMolecularProfile( + @ApiParam(required = true, value = "Molecular Profile ID") + @PathVariable String molecularProfileId, + @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Generic Assay IDs") + @Valid @RequestBody GenericAssayFilter genericAssayDataFilter, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { + + List result; + if (genericAssayDataFilter.getSampleListId() != null) { + result = filterEmptyGenericAssayData(genericAssayService.getGenericAssayData(molecularProfileId, + genericAssayDataFilter.getSampleListId(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); + } else { + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId, + genericAssayDataFilter.getSampleIds(), genericAssayDataFilter.getGenericAssayStableIds(), projection.name())); + } + + if (projection == Projection.META) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); + } else { + return new ResponseEntity<>(result, HttpStatus.OK); + } + } + + @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/generic_assay_data/fetch", method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch generic_assay_data") + public ResponseEntity> fetchGenericAssayDataInMultipleMolecularProfiles( + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface + @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. + @RequestAttribute(required = false, value = "interceptedGenericAssayDataMultipleStudyFilter") GenericAssayDataMultipleStudyFilter interceptedGenericAssayDataMultipleStudyFilter, + @ApiParam(required = true, value = "List of Molecular Profile ID and Sample ID pairs or List of Molecular" + + "Profile IDs and Generic Assay IDs") + @Valid @RequestBody(required = false) GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { + + List result; + if (interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds() != null) { + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData( + interceptedGenericAssayDataMultipleStudyFilter.getMolecularProfileIds(), null, + interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); + } else { + + List molecularProfileIds = new ArrayList<>(); + List sampleIds = new ArrayList<>(); + extractMolecularProfileAndSampleIds(interceptedGenericAssayDataMultipleStudyFilter, molecularProfileIds, sampleIds); + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileIds, + sampleIds, interceptedGenericAssayDataMultipleStudyFilter.getGenericAssayStableIds(), projection.name())); + } + + if (projection == Projection.META) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); + } else { + return new ResponseEntity<>(result, HttpStatus.OK); + } + } + + private void extractMolecularProfileAndSampleIds(GenericAssayDataMultipleStudyFilter molecularDataMultipleStudyFilter, List molecularProfileIds, List sampleIds) { + for (SampleMolecularIdentifier sampleMolecularIdentifier : molecularDataMultipleStudyFilter.getSampleMolecularIdentifiers()) { + molecularProfileIds.add(sampleMolecularIdentifier.getMolecularProfileId()); + sampleIds.add(sampleMolecularIdentifier.getSampleId()); + } + } + + private List filterEmptyGenericAssayData(List genericAssayDataList) { + return genericAssayDataList.stream() + .filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA")) + .collect(Collectors.toList()); + } +} diff --git a/web/src/main/java/org/cbioportal/web/InfoController.java b/web/src/main/java/org/cbioportal/web/InfoController.java index edc990a5179..567771176e5 100644 --- a/web/src/main/java/org/cbioportal/web/InfoController.java +++ b/web/src/main/java/org/cbioportal/web/InfoController.java @@ -3,7 +3,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.cbioportal.model.Info; -import org.cbioportal.web.config.annotation.InternalApi; +import org.cbioportal.web.config.PublicApiTags; +import org.cbioportal.web.config.annotation.PublicApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -13,10 +14,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -@InternalApi +@PublicApi @RestController @Validated -@Api(tags = "Info", description = " ") +@Api(tags = PublicApiTags.INFO, description = " ") public class InfoController { @Value("${portal.version}") diff --git a/web/src/main/java/org/cbioportal/web/ServerStatusController.java b/web/src/main/java/org/cbioportal/web/ServerStatusController.java index ffc8b71714f..6a24a017581 100644 --- a/web/src/main/java/org/cbioportal/web/ServerStatusController.java +++ b/web/src/main/java/org/cbioportal/web/ServerStatusController.java @@ -3,6 +3,7 @@ import org.cbioportal.service.ServerStatusService; import org.cbioportal.service.impl.ServerStatusServiceImpl.ServerStatusMessage; import org.cbioportal.web.config.annotation.InternalApi; +import org.cbioportal.web.config.annotation.PublicApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -15,7 +16,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -@InternalApi +@PublicApi @RestController @Validated @Api(tags = "Server running status", description = "This end point does not require authentication") diff --git a/web/src/main/java/org/cbioportal/web/StructuralVariantController.java b/web/src/main/java/org/cbioportal/web/StructuralVariantController.java index 39f68879490..2d67d4c9b59 100644 --- a/web/src/main/java/org/cbioportal/web/StructuralVariantController.java +++ b/web/src/main/java/org/cbioportal/web/StructuralVariantController.java @@ -31,8 +31,8 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.cbioportal.web.config.PublicApiTags; -import org.cbioportal.web.config.annotation.PublicApi; +import org.cbioportal.web.config.InternalApiTags; +import org.cbioportal.web.config.annotation.InternalApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -49,10 +49,10 @@ import javax.validation.Valid; import java.util.*; -@PublicApi +@InternalApi @RestController @Validated -@Api(tags = PublicApiTags.STRUCTURAL_VARIANTS, description = " ") +@Api(tags = InternalApiTags.STRUCTURAL_VARIANTS, description = " ") public class StructuralVariantController { @Autowired private StructuralVariantService structuralVariantService; diff --git a/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java b/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java index 19aafd8481f..810cbb21939 100644 --- a/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java +++ b/web/src/main/java/org/cbioportal/web/config/InternalApiTags.java @@ -8,4 +8,5 @@ public class InternalApiTags { public static final String REFERENCE_GENOME_GENES = "Reference Genome Genes"; public static final String RESOURCE_DEFINITIONS = "Resource Definitions"; public static final String RESOURCE_DATA = "Resource Data"; + public static final String STRUCTURAL_VARIANTS = "Structural Variants"; } diff --git a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java index a0ec96adbd6..b6f62a3df33 100644 --- a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java +++ b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java @@ -16,5 +16,6 @@ public class PublicApiTags { public static final String GENES = "Genes"; public static final String GENE_PANELS = "Gene Panels"; public static final String GENERIC_ASSAYS = "Generic Assays"; - public static final String STRUCTURAL_VARIANTS = "Structural Variants"; + public static final String GENERIC_ASSAY_DATA = "Generic Assay Data"; + public static final String INFO = "Info"; } \ No newline at end of file diff --git a/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java b/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java index e0cd06ceba8..29fae7fc3b3 100644 --- a/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java +++ b/web/src/main/java/org/cbioportal/web/config/SwaggerConfig.java @@ -47,7 +47,8 @@ public Docket publicApi() { new Tag(PublicApiTags.GENES, "", 12), new Tag(PublicApiTags.GENE_PANELS, "", 13), new Tag(PublicApiTags.GENERIC_ASSAYS, "", 14), - new Tag(PublicApiTags.STRUCTURAL_VARIANTS, "", 15) + new Tag(PublicApiTags.GENERIC_ASSAY_DATA, "", 15), + new Tag(PublicApiTags.INFO, "", 16) ); return d; From f6ca91e8078d61313ef805434f631b7c6fb932a6 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Jagannathan <37613906+jagnathan@users.noreply.github.com> Date: Tue, 12 Apr 2022 17:22:39 -0400 Subject: [PATCH 4/5] fix 9342 API endpoint changes fix #9342 API endpoint changes ; Split Gene Panel into Meta and Data, Added Generic assay Data. Added tests for all. --- .../cbioportal/web/GenePanelController.java | 54 ----- .../web/GenePanelDataController.java | 98 ++++++++ .../web/GenericAssayController.java | 34 ++- .../web/GenericAssayDataController.java | 28 +++ .../cbioportal/web/config/PublicApiTags.java | 1 + .../web/GenePanelControllerTest.java | 98 +------- .../web/GenePanelDataControllerTest.java | 181 +++++++++++++++ .../web/GenericAssayControllerTest.java | 178 +++++---------- .../web/GenericAssayDataControllerTest.java | 214 ++++++++++++++++++ 9 files changed, 608 insertions(+), 278 deletions(-) create mode 100644 web/src/main/java/org/cbioportal/web/GenePanelDataController.java create mode 100644 web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java create mode 100644 web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java diff --git a/web/src/main/java/org/cbioportal/web/GenePanelController.java b/web/src/main/java/org/cbioportal/web/GenePanelController.java index 1a9047996a5..93e3c293f14 100644 --- a/web/src/main/java/org/cbioportal/web/GenePanelController.java +++ b/web/src/main/java/org/cbioportal/web/GenePanelController.java @@ -98,58 +98,4 @@ public ResponseEntity> fetchGenePanels( return new ResponseEntity<>(genePanelService.fetchGenePanels(genePanelIds, projection.name()), HttpStatus.OK); } - - @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/molecular-profiles/{molecularProfileId}/gene-panel-data/fetch", method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Get gene panel data") - public ResponseEntity> getGenePanelData( - @ApiParam(required = true, value = "Molecular Profile ID e.g. nsclc_unito_2016_mutations") - @PathVariable String molecularProfileId, - @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Entrez Gene IDs") - @Valid @RequestBody GenePanelDataFilter genePanelDataFilter) throws MolecularProfileNotFoundException { - - List genePanelDataList; - if (genePanelDataFilter.getSampleListId() != null) { - genePanelDataList = genePanelService.getGenePanelData(molecularProfileId, - genePanelDataFilter.getSampleListId()); - } else { - genePanelDataList = genePanelService.fetchGenePanelData(molecularProfileId, - genePanelDataFilter.getSampleIds()); - } - - return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); - } - - @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") - @RequestMapping(value = "/gene-panel-data/fetch", method = RequestMethod.POST, - consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @ApiOperation("Fetch gene panel data") - public ResponseEntity> fetchGenePanelDataInMultipleMolecularProfiles( - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface - @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, - @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. - @Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter, - @ApiParam(required = true, value = "Gene panel data filter object") - @RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) { - - List genePanelDataList; - if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) { - List molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers() - .stream() - .map(sampleMolecularIdentifier -> { - MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier(); - profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId()); - profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId()); - return profileCaseIdentifier; - }) - .collect(Collectors.toList()); - - genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers); - } else { - genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())); - } - - return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); - } } diff --git a/web/src/main/java/org/cbioportal/web/GenePanelDataController.java b/web/src/main/java/org/cbioportal/web/GenePanelDataController.java new file mode 100644 index 00000000000..03ebec52c4f --- /dev/null +++ b/web/src/main/java/org/cbioportal/web/GenePanelDataController.java @@ -0,0 +1,98 @@ +package org.cbioportal.web; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.cbioportal.model.GenePanel; +import org.cbioportal.model.GenePanelData; +import org.cbioportal.model.MolecularProfileCaseIdentifier; +import org.cbioportal.service.GenePanelService; +import org.cbioportal.service.exception.GenePanelNotFoundException; +import org.cbioportal.service.exception.MolecularProfileNotFoundException; +import org.cbioportal.web.config.PublicApiTags; +import org.cbioportal.web.config.annotation.PublicApi; +import org.cbioportal.web.parameter.*; +import org.cbioportal.web.parameter.sort.GenePanelSortBy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.util.CollectionUtils; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.Size; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; + +@PublicApi +@RestController +@Validated +@Api(tags = PublicApiTags.GENE_PANEL_DATA, description = " ") +public class GenePanelDataController { + + @Autowired + private GenePanelService genePanelService; + + @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/molecular-profiles/{molecularProfileId}/gene-panel-data/fetch", method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Get gene panel data") + public ResponseEntity> getGenePanelData( + @ApiParam(required = true, value = "Molecular Profile ID e.g. nsclc_unito_2016_mutations") + @PathVariable String molecularProfileId, + @ApiParam(required = true, value = "List of Sample IDs/Sample List ID and Entrez Gene IDs") + @Valid @RequestBody GenePanelDataFilter genePanelDataFilter) throws MolecularProfileNotFoundException { + + List genePanelDataList; + if (genePanelDataFilter.getSampleListId() != null) { + genePanelDataList = genePanelService.getGenePanelData(molecularProfileId, + genePanelDataFilter.getSampleListId()); + } else { + genePanelDataList = genePanelService.fetchGenePanelData(molecularProfileId, + genePanelDataFilter.getSampleIds()); + } + + return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); + } + + @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/gene-panel-data/fetch", method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch gene panel data") + public ResponseEntity> fetchGenePanelDataInMultipleMolecularProfiles( + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface + @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, + @ApiIgnore // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. + @Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter, + @ApiParam(required = true, value = "Gene panel data filter object") + @RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) { + + List genePanelDataList; + if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) { + List molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers() + .stream() + .map(sampleMolecularIdentifier -> { + MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier(); + profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId()); + profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId()); + return profileCaseIdentifier; + }) + .collect(Collectors.toList()); + + genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers); + } else { + genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())); + } + + return new ResponseEntity<>(genePanelDataList, HttpStatus.OK); + } +} diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayController.java b/web/src/main/java/org/cbioportal/web/GenericAssayController.java index c8f564ff934..652ffe3e97d 100644 --- a/web/src/main/java/org/cbioportal/web/GenericAssayController.java +++ b/web/src/main/java/org/cbioportal/web/GenericAssayController.java @@ -7,6 +7,7 @@ import springfox.documentation.annotations.ApiIgnore; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -54,7 +55,7 @@ public class GenericAssayController { @RequestMapping(value = "/generic_assay_meta/fetch", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation("Fetch meta data for generic-assay by ID") - public ResponseEntity> fetchGenericAssayMetaData( + public ResponseEntity> fetchGenericAssayMeta( @ApiParam(required = true, value = "List of Molecular Profile ID or List of Stable ID") @Valid @RequestBody GenericAssayMetaFilter genericAssayMetaFilter, @ApiParam("Level of detail of the response") @@ -71,4 +72,35 @@ public ResponseEntity> fetchGenericAssayMetaData( return new ResponseEntity<>(result, HttpStatus.OK); } + // PreAuthorize is removed for performance reason + @RequestMapping(value = "/generic-assay-meta/{molecularProfileId}", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch meta data for generic-assay by ID") + public ResponseEntity> getGenericAssayMeta( + @ApiParam(required = true, value = "Molecular Profile ID") + @PathVariable String molecularProfileId, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws GenericAssayNotFoundException { + List result; + + result = genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(null, Arrays.asList(molecularProfileId), projection.name()); + + return new ResponseEntity<>(result, HttpStatus.OK); + } + + @RequestMapping(value = "/generic-assay-meta/generic-assay/{genericAssayStableId}", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Fetch meta data for generic-assay by ID") + public ResponseEntity> getGenericAssayMeta_ga( + @ApiParam(required = false, value = "Generic Assay stable ID") + @PathVariable String genericAssayStableId, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws GenericAssayNotFoundException { + List result; + result = genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Arrays.asList(genericAssayStableId), null, projection.name()); + + return new ResponseEntity<>(result, HttpStatus.OK); + } + + } diff --git a/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java index e6057a510b7..5b546f63889 100644 --- a/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java +++ b/web/src/main/java/org/cbioportal/web/GenericAssayDataController.java @@ -4,8 +4,10 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; +import org.cbioportal.model.GenePanel; import org.cbioportal.model.GenericAssayData; import org.cbioportal.service.GenericAssayService; +import org.cbioportal.service.exception.GenePanelNotFoundException; import org.cbioportal.service.exception.MolecularProfileNotFoundException; import org.cbioportal.web.config.PublicApiTags; import org.cbioportal.web.config.annotation.PublicApi; @@ -22,6 +24,7 @@ import javax.validation.Valid; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -34,6 +37,31 @@ public class GenericAssayDataController { @Autowired private GenericAssayService genericAssayService; + + @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/generic-assay-data/{molecularProfileId}/generic-assay/{genericAssayStableId}", method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Get generic_assay_data in a molecular profile") + public ResponseEntity> getGenericAssayDataInMolecularProfile( + @ApiParam(required = true, value = "Molecular Profile ID") + @PathVariable String molecularProfileId, + @ApiParam(required = true, value = "Generic Assay stable ID") + @PathVariable String genericAssayStableId, + @ApiParam("Level of detail of the response") + @RequestParam(defaultValue = "SUMMARY") Projection projection) throws MolecularProfileNotFoundException { + + List result; + result = filterEmptyGenericAssayData(genericAssayService.fetchGenericAssayData(molecularProfileId, + null, Arrays.asList(genericAssayStableId) , projection.name())); + + if (projection == Projection.META) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add(HeaderKeyConstants.TOTAL_COUNT, String.valueOf(result.size())); + return new ResponseEntity<>(responseHeaders, HttpStatus.OK); + } else { + return new ResponseEntity<>(result, HttpStatus.OK); + } + } @PreAuthorize("hasPermission(#molecularProfileId, 'MolecularProfileId', T(org.cbioportal.utils.security.AccessLevel).READ)") @RequestMapping(value = "/generic_assay_data/{molecularProfileId}/fetch", diff --git a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java index b6f62a3df33..55952192cfa 100644 --- a/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java +++ b/web/src/main/java/org/cbioportal/web/config/PublicApiTags.java @@ -15,6 +15,7 @@ public class PublicApiTags { public static final String COPY_NUMBER_SEGMENTS = "Copy Number Segments"; public static final String GENES = "Genes"; public static final String GENE_PANELS = "Gene Panels"; + public static final String GENE_PANEL_DATA = "Gene Panel Data"; public static final String GENERIC_ASSAYS = "Generic Assays"; public static final String GENERIC_ASSAY_DATA = "Generic Assay Data"; public static final String INFO = "Info"; diff --git a/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java b/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java index 0c88160c2b6..bc30903590c 100644 --- a/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenePanelControllerTest.java @@ -164,8 +164,7 @@ public void getAllGenePanelsMetaProjection() throws Exception { .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.header().string(HeaderKeyConstants.TOTAL_COUNT, "2")); } - - + @Test public void getGenePanelNotFound() throws Exception { @@ -214,98 +213,5 @@ public void getGenePanel() throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$.genes[1].entrezGeneId").value(TEST_ENTREZ_GENE_ID_2)) .andExpect(MockMvcResultMatchers.jsonPath("$.genes[1].hugoGeneSymbol").value(TEST_HUGO_GENE_SYMBOL_2)); } - - @Test - public void getGenePanelData() throws Exception { - - List genePanelDataList = createExampleGenePanelData(); - - Mockito.when(genePanelService.getGenePanelData(Mockito.anyString(), Mockito.anyString())).thenReturn(genePanelDataList); - - GenePanelDataFilter genePanelDataFilter = new GenePanelDataFilter(); - genePanelDataFilter.setSampleListId(TEST_SAMPLE_LIST_ID); - - mockMvc.perform(MockMvcRequestBuilders.post( - "/molecular-profiles/test_molecular_profile_id/gene-panel-data/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genePanelDataFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); - } - - @Test - public void fetchGenePanelData() throws Exception { - - List genePanelDataList = createExampleGenePanelData(); - - Mockito.when(genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(Mockito.anyList())).thenReturn(genePanelDataList); - - List sampleMolecularIdentifiers = new ArrayList<>(); - SampleMolecularIdentifier sampleMolecularIdentifier1 = new SampleMolecularIdentifier(); - sampleMolecularIdentifier1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); - sampleMolecularIdentifier1.setSampleId(TEST_SAMPLE_ID_1); - sampleMolecularIdentifiers.add(sampleMolecularIdentifier1); - SampleMolecularIdentifier sampleMolecularIdentifier2 = new SampleMolecularIdentifier(); - sampleMolecularIdentifier2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); - sampleMolecularIdentifier2.setSampleId(TEST_SAMPLE_ID_2); - sampleMolecularIdentifiers.add(sampleMolecularIdentifier2); - GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter = new GenePanelDataMultipleStudyFilter(); - genePanelDataMultipleStudyFilter.setSampleMolecularIdentifiers(sampleMolecularIdentifiers); - - mockMvc.perform(MockMvcRequestBuilders.post( - "/gene-panel-data/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genePanelDataMultipleStudyFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); - } - - private List createExampleGenePanelData() { - - List genePanelDataList = new ArrayList<>(); - GenePanelData genePanelData1 = new GenePanelData(); - genePanelData1.setGenePanelId(TEST_GENE_PANEL_ID_1); - genePanelData1.setSampleId(TEST_SAMPLE_ID_1); - genePanelData1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); - genePanelData1.setPatientId(TEST_PATIENT_ID_1); - genePanelData1.setStudyId(TEST_STUDY_ID_1); - genePanelData1.setProfiled(true); - genePanelDataList.add(genePanelData1); - GenePanelData genePanelData2 = new GenePanelData(); - genePanelData2.setSampleId(TEST_SAMPLE_ID_2); - genePanelData2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); - genePanelData2.setPatientId(TEST_PATIENT_ID_2); - genePanelData2.setStudyId(TEST_STUDY_ID_2); - genePanelData2.setProfiled(true); - genePanelDataList.add(genePanelData2); - return genePanelDataList; - } + } diff --git a/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java b/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java new file mode 100644 index 00000000000..b810260b874 --- /dev/null +++ b/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java @@ -0,0 +1,181 @@ +package org.cbioportal.web; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.cbioportal.model.GenePanel; +import org.cbioportal.model.GenePanelData; +import org.cbioportal.model.GenePanelToGene; +import org.cbioportal.model.meta.BaseMeta; +import org.cbioportal.service.GenePanelService; +import org.cbioportal.service.exception.GenePanelNotFoundException; +import org.cbioportal.web.parameter.GenePanelDataFilter; +import org.cbioportal.web.parameter.GenePanelDataMultipleStudyFilter; +import org.cbioportal.web.parameter.HeaderKeyConstants; +import org.cbioportal.web.parameter.SampleMolecularIdentifier; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration("/applicationContext-web-test.xml") +@Configuration +public class GenePanelDataControllerTest { + + private static final String TEST_GENE_PANEL_ID_1 = "test_gene_panel_id_1"; + private static final int TEST_INTERNAL_ID_1 = 1; + private static final String TEST_DESCRIPTION_1 = "test_description_1"; + private static final String TEST_SAMPLE_ID_1 = "test_sample_id_1"; + private static final String TEST_PATIENT_ID_1 = "test_patient_id_1"; + private static final String TEST_STUDY_ID_1 = "test_study_id_1"; + private static final String TEST_MOLECULAR_PROFILE_ID_1 = "test_molecular_profile_id_1"; + private static final int TEST_ENTREZ_GENE_ID_1 = 100; + private static final String TEST_HUGO_GENE_SYMBOL_1 = "test_hugo_gene_symbol_1"; + private static final int TEST_ENTREZ_GENE_ID_2 = 200; + private static final String TEST_HUGO_GENE_SYMBOL_2 = "test_hugo_gene_symbol_2"; + private static final String TEST_GENE_PANEL_ID_2 = "test_gene_panel_id_2"; + private static final int TEST_INTERNAL_ID_2 = 2; + private static final String TEST_DESCRIPTION_2 = "test_description_2"; + private static final String TEST_SAMPLE_ID_2 = "test_sample_id_2"; + private static final String TEST_PATIENT_ID_2 = "test_patient_id_2"; + private static final String TEST_STUDY_ID_2 = "test_study_id_2"; + private static final String TEST_MOLECULAR_PROFILE_ID_2 = "test_molecular_profile_id_2"; + private static final int TEST_ENTREZ_GENE_ID_3 = 300; + private static final String TEST_HUGO_GENE_SYMBOL_3 = "test_hugo_gene_symbol_3"; + private static final int TEST_ENTREZ_GENE_ID_4 = 400; + private static final String TEST_HUGO_GENE_SYMBOL_4 = "test_hugo_gene_symbol_4"; + private static final String TEST_SAMPLE_LIST_ID = "test_sample_list_id"; + + @Autowired + private WebApplicationContext wac; + + @Autowired + private GenePanelService genePanelService; + + private ObjectMapper objectMapper = new ObjectMapper(); + + private MockMvc mockMvc; + + @Bean + public GenePanelService genePanelService() { + return Mockito.mock(GenePanelService.class); + } + + @Before + public void setUp() throws Exception { + + Mockito.reset(genePanelService); + mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); + } + + @Test + public void getGenePanelData() throws Exception { + + List genePanelDataList = createExampleGenePanelData(); + + Mockito.when(genePanelService.getGenePanelData(Mockito.anyString(), Mockito.anyString())).thenReturn(genePanelDataList); + + GenePanelDataFilter genePanelDataFilter = new GenePanelDataFilter(); + genePanelDataFilter.setSampleListId(TEST_SAMPLE_LIST_ID); + + mockMvc.perform(MockMvcRequestBuilders.post( + "/molecular-profiles/test_molecular_profile_id/gene-panel-data/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genePanelDataFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); + } + + @Test + public void fetchGenePanelData() throws Exception { + + List genePanelDataList = createExampleGenePanelData(); + + Mockito.when(genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(Mockito.anyList())).thenReturn(genePanelDataList); + + List sampleMolecularIdentifiers = new ArrayList<>(); + SampleMolecularIdentifier sampleMolecularIdentifier1 = new SampleMolecularIdentifier(); + sampleMolecularIdentifier1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); + sampleMolecularIdentifier1.setSampleId(TEST_SAMPLE_ID_1); + sampleMolecularIdentifiers.add(sampleMolecularIdentifier1); + SampleMolecularIdentifier sampleMolecularIdentifier2 = new SampleMolecularIdentifier(); + sampleMolecularIdentifier2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); + sampleMolecularIdentifier2.setSampleId(TEST_SAMPLE_ID_2); + sampleMolecularIdentifiers.add(sampleMolecularIdentifier2); + GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter = new GenePanelDataMultipleStudyFilter(); + genePanelDataMultipleStudyFilter.setSampleMolecularIdentifiers(sampleMolecularIdentifiers); + + mockMvc.perform(MockMvcRequestBuilders.post( + "/gene-panel-data/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genePanelDataMultipleStudyFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(TEST_SAMPLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genePanelId").value(TEST_GENE_PANEL_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_STUDY_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].profiled").value(true)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(TEST_MOLECULAR_PROFILE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(TEST_SAMPLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genePanelId").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_STUDY_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].profiled").value(true)); + } + + private List createExampleGenePanelData() { + + List genePanelDataList = new ArrayList<>(); + GenePanelData genePanelData1 = new GenePanelData(); + genePanelData1.setGenePanelId(TEST_GENE_PANEL_ID_1); + genePanelData1.setSampleId(TEST_SAMPLE_ID_1); + genePanelData1.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_1); + genePanelData1.setPatientId(TEST_PATIENT_ID_1); + genePanelData1.setStudyId(TEST_STUDY_ID_1); + genePanelData1.setProfiled(true); + genePanelDataList.add(genePanelData1); + GenePanelData genePanelData2 = new GenePanelData(); + genePanelData2.setSampleId(TEST_SAMPLE_ID_2); + genePanelData2.setMolecularProfileId(TEST_MOLECULAR_PROFILE_ID_2); + genePanelData2.setPatientId(TEST_PATIENT_ID_2); + genePanelData2.setStudyId(TEST_STUDY_ID_2); + genePanelData2.setProfiled(true); + genePanelDataList.add(genePanelData2); + return genePanelDataList; + } +} diff --git a/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java b/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java index e46d3da34db..d1f4a5662c9 100644 --- a/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java @@ -78,73 +78,15 @@ public void setUp() throws Exception { Mockito.reset(genericAssayService); mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } - - @Test - public void testGenericAssayDataFetch() throws Exception { - List genericAssayDataItems = createGenericAssayDataItemsList(); - Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyString(), Mockito.anyList(), - Mockito.anyList(), Mockito.anyString())).thenReturn(genericAssayDataItems); - - GenericAssayFilter genericAssayDataFilter = new GenericAssayFilter(); - genericAssayDataFilter.setSampleIds(Arrays.asList(SAMPLE_ID)); - genericAssayDataFilter.setGenericAssayStableIds(Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ASSAY_STABLE_ID_3, GENERIC_ASSAY_STABLE_ID_4)); - - mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/" + PROF_ID + "/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genericAssayDataFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); - } - - @Test - public void testGenericAssayDataFetchInMultipleMolecularProfiles() throws Exception { - List genericAssayDataItems = createGenericAssayDataItemsList(); - GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter = new GenericAssayDataMultipleStudyFilter(); - genericAssayDataMultipleStudyFilter.setSampleMolecularIdentifiers(createSampleMolecularIdentifiers()); - - Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyList(), Mockito.any(), - Mockito.any(), Mockito.any())).thenReturn(genericAssayDataItems); - - mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genericAssayDataMultipleStudyFilter))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) - .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); - } - + @Test - public void testGenericAssayMetaDataFetch() throws Exception { + public void testGenericAssayMetaGetMolecularProfileId() throws Exception { List genericAssayMetaItems = createGenericAssayMetaItemsList(); - List genericAssayStableIds = Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2); - GenericAssayMetaFilter genericAssayMetaFilter = new GenericAssayMetaFilter(); - genericAssayMetaFilter.setGenericAssayStableIds(genericAssayStableIds); Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); - mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_meta/fetch") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(genericAssayMetaFilter))) + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-meta/" + PROF_ID) + .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) @@ -158,81 +100,63 @@ public void testGenericAssayMetaDataFetch() throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); } - private List createGenericAssayMetaItemsList() { - - List genericAssayMetaItems = new ArrayList<>(); - - GenericAssayMeta item1 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_1); - genericAssayMetaItems.add(item1); - GenericAssayMeta item2 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ENTITY_META_PROPERTIES); - genericAssayMetaItems.add(item2); + @Test + public void testGenericAssayMetaGetGenericAssayStableId() throws Exception { + List genericAssayMetaItems = createGenericAssayMetaItemsList(); - return genericAssayMetaItems; - } + Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); - private List createGenericAssayDataItemsList() { - - List genericAssayDataItems = new ArrayList<>(); - - GenericAssayData item1 = new GenericAssayData(); - item1.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_1); - item1.setMolecularProfileId(PROF_ID); - item1.setSampleId(SAMPLE_ID); - item1.setValue(VALUE_1); - genericAssayDataItems.add(item1); - - GenericAssayData item2 = new GenericAssayData(); - item2.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_2); - item2.setMolecularProfileId(PROF_ID); - item2.setSampleId(SAMPLE_ID); - item2.setValue(VALUE_2); - genericAssayDataItems.add(item2); - - // This item should be filtered out in api result - GenericAssayData item3 = new GenericAssayData(); - item3.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_3); - item3.setMolecularProfileId(PROF_ID); - item3.setSampleId(SAMPLE_ID); - item3.setValue(VALUE_3); - genericAssayDataItems.add(item3); - - // This item should be filtered out in api result - GenericAssayData item4 = new GenericAssayData(); - item4.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_4); - item4.setMolecularProfileId(PROF_ID); - item4.setSampleId(SAMPLE_ID); - item4.setValue(VALUE_4); - genericAssayDataItems.add(item4); - - return genericAssayDataItems; + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-meta/" + PROF_ID + "/generic-assay/" + GENERIC_ASSAY_STABLE_ID_2) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].entityType").value(ENTITY_TYPE)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].stableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasKey(TEST_NAME))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasValue(TEST_NAME_VALUE))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasKey(TEST_DESCRIPTION))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); } - private List createSampleMolecularIdentifiers() { + @Test + public void testGenericAssayMetaFetch() throws Exception { + List genericAssayMetaItems = createGenericAssayMetaItemsList(); + List genericAssayStableIds = Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2); + GenericAssayMetaFilter genericAssayMetaFilter = new GenericAssayMetaFilter(); + genericAssayMetaFilter.setGenericAssayStableIds(genericAssayStableIds); - List sampleMolecularIdentifiers = new ArrayList<>(); + Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); - SampleMolecularIdentifier identifier1 = new SampleMolecularIdentifier(); - identifier1.setSampleId(SAMPLE_ID); - identifier1.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_1); - sampleMolecularIdentifiers.add(identifier1); + mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_meta/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genericAssayMetaFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].entityType").value(ENTITY_TYPE)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].stableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].entityType").value(ENTITY_TYPE)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].stableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasKey(TEST_NAME))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_NAME_VALUE))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasKey(TEST_DESCRIPTION))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); + } + + private List createGenericAssayMetaItemsList() { - SampleMolecularIdentifier identifier2 = new SampleMolecularIdentifier(); - identifier2.setSampleId(SAMPLE_ID); - identifier2.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_2); - sampleMolecularIdentifiers.add(identifier2); + List genericAssayMetaItems = new ArrayList<>(); - SampleMolecularIdentifier identifier3 = new SampleMolecularIdentifier(); - identifier3.setSampleId(SAMPLE_ID); - identifier3.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_3); - sampleMolecularIdentifiers.add(identifier3); + GenericAssayMeta item1 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_1); + genericAssayMetaItems.add(item1); - SampleMolecularIdentifier identifier4 = new SampleMolecularIdentifier(); - identifier4.setSampleId(SAMPLE_ID); - identifier4.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_4); - sampleMolecularIdentifiers.add(identifier4); + GenericAssayMeta item2 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ENTITY_META_PROPERTIES); + genericAssayMetaItems.add(item2); - return sampleMolecularIdentifiers; + return genericAssayMetaItems; } - } \ No newline at end of file diff --git a/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java b/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java new file mode 100644 index 00000000000..d017d88e1b5 --- /dev/null +++ b/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java @@ -0,0 +1,214 @@ +package org.cbioportal.web; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.cbioportal.model.GenericAssayData; +import org.cbioportal.model.meta.GenericAssayMeta; +import org.cbioportal.service.GenericAssayService; +import org.cbioportal.web.parameter.GenericAssayDataMultipleStudyFilter; +import org.cbioportal.web.parameter.GenericAssayFilter; +import org.cbioportal.web.parameter.GenericAssayMetaFilter; +import org.cbioportal.web.parameter.SampleMolecularIdentifier; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration("/applicationContext-web.xml") +@Configuration +public class GenericAssayDataControllerTest { + + private static final String PROF_ID = "test_prof_id"; + private static final String ENTITY_TYPE = "test_type"; + public static final String GENERIC_ASSAY_STABLE_ID_1 = "genericAssayStableId1"; + public static final String GENERIC_ASSAY_STABLE_ID_2 = "genericAssayStableId2"; + public static final String GENERIC_ASSAY_STABLE_ID_3 = "genericAssayStableId3"; + public static final String GENERIC_ASSAY_STABLE_ID_4 = "genericAssayStableId4"; + private static final String SAMPLE_ID = "test_sample_stable_id_1"; + private static final String VALUE_1 = "0.25"; + private static final String VALUE_2 = "-0.75"; + private static final String VALUE_3 = ""; + private static final String VALUE_4 = "NA"; + private static final String TEST_NAME = "name"; + private static final String TEST_NAME_VALUE = "test_name"; + private static final String TEST_DESCRIPTION = "description"; + private static final String TEST_DESCRIPTION_VALUE = "test_description"; + private static final HashMap GENERIC_ENTITY_META_PROPERTIES = new HashMap() {{ + put(TEST_NAME,TEST_NAME_VALUE); + put(TEST_DESCRIPTION,TEST_DESCRIPTION_VALUE); + }}; + + @Autowired + private WebApplicationContext wac; + + @Autowired + private GenericAssayService genericAssayService; + private MockMvc mockMvc; + + private ObjectMapper objectMapper = new ObjectMapper(); + + @Bean + public GenericAssayService genericAssayService() { + return Mockito.mock(GenericAssayService.class); + } + + @Before + public void setUp() throws Exception { + + Mockito.reset(genericAssayService); + mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); + } + + @Test + public void testGenericAssayDataFetch() throws Exception { + List genericAssayDataItems = createGenericAssayDataItemsList(); + Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyString(), Mockito.anyList(), + Mockito.anyList(), Mockito.anyString())).thenReturn(genericAssayDataItems); + + GenericAssayFilter genericAssayDataFilter = new GenericAssayFilter(); + genericAssayDataFilter.setSampleIds(Arrays.asList(SAMPLE_ID)); + genericAssayDataFilter.setGenericAssayStableIds(Arrays.asList(GENERIC_ASSAY_STABLE_ID_1, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ASSAY_STABLE_ID_3, GENERIC_ASSAY_STABLE_ID_4)); + + mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/" + PROF_ID + "/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genericAssayDataFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); + } + + @Test + public void testGenericAssayDataFetchInMultipleMolecularProfiles() throws Exception { + List genericAssayDataItems = createGenericAssayDataItemsList(); + GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter = new GenericAssayDataMultipleStudyFilter(); + genericAssayDataMultipleStudyFilter.setSampleMolecularIdentifiers(createSampleMolecularIdentifiers()); + + Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyList(), Mockito.any(), + Mockito.any(), Mockito.any())).thenReturn(genericAssayDataItems); + + mockMvc.perform(MockMvcRequestBuilders.post("/generic_assay_data/fetch") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(genericAssayDataMultipleStudyFilter))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(VALUE_2)); + } + + public void testGenericAssayDataGet() throws Exception { + List genericAssayDataItems = createGenericAssayDataItemsList(); + Mockito.when(genericAssayService.fetchGenericAssayData(Mockito.anyString(), Mockito.anyList(), + Mockito.anyList(), Mockito.anyString())).thenReturn(genericAssayDataItems); + + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-data/" + PROF_ID + "/generic-assay/" + GENERIC_ASSAY_STABLE_ID_1) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].molecularProfileId").value(PROF_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].genericAssayStableId").value(GENERIC_ASSAY_STABLE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].sampleId").value(SAMPLE_ID)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(VALUE_1)); + } + + private List createGenericAssayDataItemsList() { + + List genericAssayDataItems = new ArrayList<>(); + + GenericAssayData item1 = new GenericAssayData(); + item1.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_1); + item1.setMolecularProfileId(PROF_ID); + item1.setSampleId(SAMPLE_ID); + item1.setValue(VALUE_1); + genericAssayDataItems.add(item1); + + GenericAssayData item2 = new GenericAssayData(); + item2.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_2); + item2.setMolecularProfileId(PROF_ID); + item2.setSampleId(SAMPLE_ID); + item2.setValue(VALUE_2); + genericAssayDataItems.add(item2); + + // This item should be filtered out in api result + GenericAssayData item3 = new GenericAssayData(); + item3.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_3); + item3.setMolecularProfileId(PROF_ID); + item3.setSampleId(SAMPLE_ID); + item3.setValue(VALUE_3); + genericAssayDataItems.add(item3); + + // This item should be filtered out in api result + GenericAssayData item4 = new GenericAssayData(); + item4.setGenericAssayStableId(GENERIC_ASSAY_STABLE_ID_4); + item4.setMolecularProfileId(PROF_ID); + item4.setSampleId(SAMPLE_ID); + item4.setValue(VALUE_4); + genericAssayDataItems.add(item4); + + return genericAssayDataItems; + } + + private List createSampleMolecularIdentifiers() { + + List sampleMolecularIdentifiers = new ArrayList<>(); + + SampleMolecularIdentifier identifier1 = new SampleMolecularIdentifier(); + identifier1.setSampleId(SAMPLE_ID); + identifier1.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_1); + sampleMolecularIdentifiers.add(identifier1); + + SampleMolecularIdentifier identifier2 = new SampleMolecularIdentifier(); + identifier2.setSampleId(SAMPLE_ID); + identifier2.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_2); + sampleMolecularIdentifiers.add(identifier2); + + SampleMolecularIdentifier identifier3 = new SampleMolecularIdentifier(); + identifier3.setSampleId(SAMPLE_ID); + identifier3.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_3); + sampleMolecularIdentifiers.add(identifier3); + + SampleMolecularIdentifier identifier4 = new SampleMolecularIdentifier(); + identifier4.setSampleId(SAMPLE_ID); + identifier4.setMolecularProfileId(GENERIC_ASSAY_STABLE_ID_4); + sampleMolecularIdentifiers.add(identifier4); + + return sampleMolecularIdentifiers; + } + +} \ No newline at end of file From 405a349907b5a7fa4ad22ca9e264c8a581eea05a Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Jagannathan <37613906+jagnathan@users.noreply.github.com> Date: Wed, 27 Apr 2022 15:26:33 -0400 Subject: [PATCH 5/5] cleared up the tests for GenericAssay and GenePanelData cleared up the tests for GenericAssay and GenePanelData --- .../web/GenePanelDataControllerTest.java | 7 +------ .../web/GenericAssayControllerTest.java | 16 +++++++++++++--- .../web/GenericAssayDataControllerTest.java | 5 ----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java b/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java index b810260b874..a2ded39c3ae 100644 --- a/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenePanelDataControllerTest.java @@ -72,12 +72,7 @@ public class GenePanelDataControllerTest { private ObjectMapper objectMapper = new ObjectMapper(); private MockMvc mockMvc; - - @Bean - public GenePanelService genePanelService() { - return Mockito.mock(GenePanelService.class); - } - + @Before public void setUp() throws Exception { diff --git a/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java b/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java index d1f4a5662c9..c8bf31069ae 100644 --- a/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenericAssayControllerTest.java @@ -103,11 +103,11 @@ public void testGenericAssayMetaGetMolecularProfileId() throws Exception { @Test public void testGenericAssayMetaGetGenericAssayStableId() throws Exception { - List genericAssayMetaItems = createGenericAssayMetaItemsList(); + List genericAssayMetaSingleItem = createGenericAssayMetaSingleItem(); - Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaItems); + Mockito.when(genericAssayService.getGenericAssayMetaByStableIdsAndMolecularIds(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(genericAssayMetaSingleItem); - mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-meta/" + PROF_ID + "/generic-assay/" + GENERIC_ASSAY_STABLE_ID_2) + mockMvc.perform(MockMvcRequestBuilders.get("/generic-assay-meta/generic-assay/" + GENERIC_ASSAY_STABLE_ID_2) .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk()) @@ -146,6 +146,16 @@ public void testGenericAssayMetaFetch() throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasKey(TEST_DESCRIPTION))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].genericEntityMetaProperties", Matchers.hasValue(TEST_DESCRIPTION_VALUE))); } + + private List createGenericAssayMetaSingleItem() { + + List genericAssayMetaItems = new ArrayList<>(); + + GenericAssayMeta item2 = new GenericAssayMeta(ENTITY_TYPE, GENERIC_ASSAY_STABLE_ID_2, GENERIC_ENTITY_META_PROPERTIES); + genericAssayMetaItems.add(item2); + + return genericAssayMetaItems; + } private List createGenericAssayMetaItemsList() { diff --git a/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java b/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java index d017d88e1b5..20dedf7ebfa 100644 --- a/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java +++ b/web/src/test/java/org/cbioportal/web/GenericAssayDataControllerTest.java @@ -65,11 +65,6 @@ public class GenericAssayDataControllerTest { private MockMvc mockMvc; private ObjectMapper objectMapper = new ObjectMapper(); - - @Bean - public GenericAssayService genericAssayService() { - return Mockito.mock(GenericAssayService.class); - } @Before public void setUp() throws Exception {