use of org.sonarqube.ws.AlmIntegrations.AlmProject in project sonarqube by SonarSource.
the class ListBitbucketServerProjectsAction method doHandle.
private ListBitbucketserverProjectsWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
userSession.checkLoggedIn().checkPermission(PROVISION_PROJECTS);
String almSettingKey = request.mandatoryParam(PARAM_ALM_SETTING);
String userUuid = requireNonNull(userSession.getUuid(), "User UUID is not null");
AlmSettingDto almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, almSettingKey).orElseThrow(() -> new NotFoundException(String.format("ALM Setting '%s' not found", almSettingKey)));
Optional<AlmPatDto> almPatDto = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
String url = requireNonNull(almSettingDto.getUrl(), "URL cannot be null");
ProjectList projectList = bitbucketServerRestClient.getProjects(url, pat);
List<AlmProject> values = projectList.getValues().stream().map(ListBitbucketServerProjectsAction::toAlmProject).collect(Collectors.toList());
ListBitbucketserverProjectsWsResponse.Builder builder = ListBitbucketserverProjectsWsResponse.newBuilder().addAllProjects(values);
return builder.build();
}
}
Aggregations