Search in sources :

Example 1 with TumorTypesNotFoundException

use of org.mskcc.oncotree.error.TumorTypesNotFoundException in project oncotree by cBioPortal.

the class TumorTypesApi method tumorTypesSearchTypeQueryQueryGet.

@ApiOperation(value = "Tumor Types", notes = "", response = TumorType.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "An array of tumor types"), @ApiResponse(code = 400, message = "Bad request"), @ApiResponse(code = 404, message = "Could not find tumor types"), @ApiResponse(code = 503, message = "Required data source unavailable") })
@RequestMapping(value = "/search/{type}/{query}", produces = { APPLICATION_JSON_VALUE }, method = RequestMethod.GET)
public Iterable<TumorType> tumorTypesSearchTypeQueryQueryGet(@ApiParam(value = "Query type. It could be 'code', 'name', 'mainType', 'level', 'nci', 'umls' or 'color'.", required = true) @PathVariable("type") String type, @ApiParam(value = "The query content", required = true) @PathVariable("query") String query, @ApiParam(value = "The version of tumor types. For example, " + VersionUtil.DEFAULT_VERSION + ". Please see the versions api documentation for released versions.") @RequestParam(value = "version", required = false) String version, @ApiParam(value = "If it sets to true, it will only return one element array.", defaultValue = "true") @RequestParam(value = "exactMatch", required = false, defaultValue = "true") Boolean exactMatch, @ApiParam(value = "Tumor type levels. 1-5. By default, it doesn't includes tissue which is the primary level.", defaultValue = "2,3,4,5") @RequestParam(value = "levels", required = false, defaultValue = "1,2,3,4,5") String levels) {
    List<TumorType> matchedTumorTypes = new ArrayList<>();
    Version v = (version == null) ? versionUtil.getDefaultVersion() : versionUtil.getVersion(version);
    // Cache in tumor types in case no data present
    cacheUtil.getTumorTypesByVersion(v);
    matchedTumorTypes = v == null ? new ArrayList<TumorType>() : tumorTypesUtil.findTumorTypesByVersion(type, query, exactMatch, v, false);
    // check that user did not do a "level" query, but is doing a "levels" filter
    if (!type.toLowerCase().equals("level") && !StringUtils.isBlank(levels)) {
        List<String> ls = Arrays.asList(levels.split(","));
        List<Integer> levelList = new ArrayList<>();
        for (String l : ls) {
            try {
                Integer level = new Integer(Integer.parseInt(l.trim()));
                levelList.add(level);
            } catch (NumberFormatException e) {
                throw new InvalidQueryException("'" + l + "' is not a valid level.  Level must be an integer.");
            }
        }
        matchedTumorTypes = tumorTypesUtil.filterTumorTypesByLevel(matchedTumorTypes, levelList);
    }
    if (matchedTumorTypes.isEmpty()) {
        throw new TumorTypesNotFoundException("No tumor types found matching supplied query");
    }
    return matchedTumorTypes;
}
Also used : TumorTypesNotFoundException(org.mskcc.oncotree.error.TumorTypesNotFoundException) InvalidQueryException(org.mskcc.oncotree.error.InvalidQueryException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 InvalidQueryException (org.mskcc.oncotree.error.InvalidQueryException)1 TumorTypesNotFoundException (org.mskcc.oncotree.error.TumorTypesNotFoundException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1