use of org.sonarqube.ws.AlmIntegrations.ListAzureProjectsWsResponse in project sonarqube by SonarSource.
the class ListAzureProjectsAction method doHandle.
private ListAzureProjectsWsResponse 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");
GsonAzureProjectList projectList = azureDevOpsHttpClient.getProjects(url, pat);
List<AzureProject> values = projectList.getValues().stream().map(ListAzureProjectsAction::toAzureProject).sorted(comparing(AzureProject::getName, String::compareToIgnoreCase)).collect(Collectors.toList());
ListAzureProjectsWsResponse.Builder builder = ListAzureProjectsWsResponse.newBuilder().addAllProjects(values);
return builder.build();
}
}
use of org.sonarqube.ws.AlmIntegrations.ListAzureProjectsWsResponse in project sonarqube by SonarSource.
the class ListAzureProjectsAction method handle.
@Override
public void handle(Request request, Response response) {
ListAzureProjectsWsResponse wsResponse = doHandle(request);
writeProtobuf(wsResponse, request, response);
}
use of org.sonarqube.ws.AlmIntegrations.ListAzureProjectsWsResponse in project sonarqube by SonarSource.
the class ListAzureProjectsActionTest method list_projects.
@Test
public void list_projects() {
AlmSettingDto almSetting = insertAlmSetting();
ListAzureProjectsWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(ListAzureProjectsWsResponse.class);
assertThat(response.getProjectsCount()).isEqualTo(2);
assertThat(response.getProjectsList()).extracting(AzureProject::getName, AzureProject::getDescription).containsExactly(tuple("name", "description"), tuple("name", ""));
}
use of org.sonarqube.ws.AlmIntegrations.ListAzureProjectsWsResponse in project sonarqube by SonarSource.
the class ListAzureProjectsActionTest method list_projects_alphabetically_sorted.
@Test
public void list_projects_alphabetically_sorted() {
mockClient(ImmutableList.of(new GsonAzureProject("BBB project", "BBB project description"), new GsonAzureProject("AAA project 1", "AAA project description"), new GsonAzureProject("zzz project", "zzz project description"), new GsonAzureProject("aaa project", "aaa project description")));
AlmSettingDto almSetting = insertAlmSetting();
ListAzureProjectsWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(ListAzureProjectsWsResponse.class);
assertThat(response.getProjectsCount()).isEqualTo(4);
assertThat(response.getProjectsList()).extracting(AzureProject::getName, AzureProject::getDescription).containsExactly(tuple("aaa project", "aaa project description"), tuple("AAA project 1", "AAA project description"), tuple("BBB project", "BBB project description"), tuple("zzz project", "zzz project description"));
}
Aggregations