Source:
public GASearchVariantsResponse getVariantsByRegion(@RequestParam("referenceName") String chromosome, @RequestParam("start") int start, @RequestParam("end") int end, @RequestParam(name = "variantSetIds", required = false) List<String> files, @RequestParam(name = "pageToken", required = false) String pageToken, @RequestParam(name = "pageSize", defaultValue = "10") int limit) throws IllegalOpenCGACredentialsException, UnknownHostException, IOException { initializeQueryOptions(); MultiMongoDbFactory.setDatabaseNameForCurrentThread(DBAdaptorConnector.getDBName("hsapiens_grch37")); if (files != null && !files.isEmpty()) { queryOptions.put("files", files); } List<VariantEntityRepositoryFilter> filters = Helpers.getVariantEntityRepositoryFilters(null, null, null, null, null, files, null, null); int idxCurrentPage = 0; if (pageToken != null && !pageToken.isEmpty() && StringUtils.isNumeric(pageToken)) { idxCurrentPage = Integer.parseInt(pageToken); queryOptions.put("skip", idxCurrentPage * limit); } queryOptions.put("limit", limit); Region region = new Region(chromosome, start, end); List<Region> regions = new ArrayList<>(); regions.add(region); PageRequest pageRequest = Utils.getPageRequest(queryOptions); List<VariantEntity> variantEntities = variantEntityRepository.findByRegionsAndComplexFilters(regions, filters, null, pageRequest); List<Variant> variants = Collections.unmodifiableList(variantEntities); Long numTotalResults = variantEntityRepository.countByRegionsAndComplexFilters(regions, filters); List<GAVariant> gaVariants = GAVariantFactory.create(variants); int idxLastElement = idxCurrentPage * limit + limit; String nextPageToken = (idxLastElement < numTotalResults) ? String.valueOf(idxCurrentPage + 1) : null; return new GASearchVariantsResponse(gaVariants, nextPageToken); }

Target:
public GASearchVariantsResponse getVariantsByRegion(@RequestParam("referenceName") String chromosome, @RequestParam("start") int start, @RequestParam("end") int end, @RequestParam(name = "variantSetIds", required = false) List<String> files, @RequestParam(name = "pageToken", required = false) String pageToken, @RequestParam(name = "pageSize", defaultValue = "10") int limit) throws IllegalOpenCGACredentialsException, UnknownHostException, IOException { initializeQuery(); MultiMongoDbFactory.setDatabaseNameForCurrentThread(DBAdaptorConnector.getDBName("hsapiens_grch37")); if (files != null && !files.isEmpty()) { queryOptions.put("files", files); } List<VariantEntityRepositoryFilter> filters = new FilterBuilder().withFiles(files).build(); PageRequest pageRequest = Utils.getPageRequest(limit, pageToken); Region region = new Region(chromosome, start, end); List<Region> regions = new ArrayList<>(); regions.add(region); List<VariantEntity> variantEntities = variantEntityRepository.findByRegionsAndComplexFilters(regions, filters, null, pageRequest); List<Variant> variants = Collections.unmodifiableList(variantEntities); Long numTotalResults = variantEntityRepository.countByRegionsAndComplexFilters(regions, filters); List<GAVariant> gaVariants = GAVariantFactory.create(variants); String nextPageToken = Utils.getNextPageToken(pageRequest, limit, numTotalResults); return new GASearchVariantsResponse(gaVariants, nextPageToken); }