use of org.sonar.api.server.ws.WebService.Param.PAGE_SIZE in project sonarqube by SonarSource.
the class SearchBitbucketCloudReposAction method doHandle.
private SearchBitbucketcloudReposWsResponse doHandle(Request request) {
userSession.checkLoggedIn().checkPermission(PROVISION_PROJECTS);
String almSettingKey = request.mandatoryParam(PARAM_ALM_SETTING);
String repoName = request.param(PARAM_REPO_NAME);
int page = request.mandatoryParamAsInt(PAGE);
int pageSize = request.mandatoryParamAsInt(PAGE_SIZE);
try (DbSession dbSession = dbClient.openSession(false)) {
AlmSettingDto almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, almSettingKey).orElseThrow(() -> new NotFoundException(String.format("ALM Setting '%s' not found", almSettingKey)));
String workspace = ofNullable(almSettingDto.getAppId()).orElseThrow(() -> new IllegalArgumentException(String.format("workspace for alm setting %s is missing", almSettingDto.getKey())));
String userUuid = requireNonNull(userSession.getUuid(), "User UUID cannot be null");
Optional<AlmPatDto> almPatDto = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
RepositoryList repositoryList = bitbucketCloudRestClient.searchRepos(pat, workspace, repoName, page, pageSize);
Map<String, String> sqProjectKeyByRepoSlug = getSqProjectKeyByRepoSlug(dbSession, almSettingDto, repositoryList.getValues());
List<BBCRepo> bbcRepos = repositoryList.getValues().stream().map(repository -> toBBCRepo(repository, workspace, sqProjectKeyByRepoSlug)).collect(toList());
SearchBitbucketcloudReposWsResponse.Builder builder = SearchBitbucketcloudReposWsResponse.newBuilder().setIsLastPage(repositoryList.getNext() == null).setPaging(Paging.newBuilder().setPageIndex(page).setPageSize(pageSize).build()).addAllRepositories(bbcRepos);
return builder.build();
}
}
Aggregations