Search in sources :

Example 1 with AlmSetting

use of org.sonarqube.ws.AlmSettings.AlmSetting in project sonarqube by SonarSource.

the class ListAction method doHandle.

private ListWsResponse doHandle(Request request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Request.StringParam projectKey = request.getParam(PARAM_PROJECT);
        if (projectKey.isPresent()) {
            ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey.getValue());
            userSession.checkProjectPermission(ADMIN, project);
        } else {
            userSession.checkPermission(PROVISION_PROJECTS);
        }
        List<AlmSettingDto> settings = dbClient.almSettingDao().selectAll(dbSession);
        List<AlmSetting> wsAlmSettings = settings.stream().sorted(Comparator.comparing(AlmSettingDto::getKey)).map(almSetting -> {
            AlmSetting.Builder almSettingBuilder = AlmSetting.newBuilder().setKey(almSetting.getKey()).setAlm(AlmSettingsSupport.toAlmWs(almSetting.getAlm()));
            if (almSetting.getAlm() == ALM.BITBUCKET_CLOUD) {
                almSettingBuilder.setUrl(BITBUCKETCLOUD_ROOT_URL + almSetting.getAppId() + "/");
            } else {
                ofNullable(almSetting.getUrl()).ifPresent(almSettingBuilder::setUrl);
            }
            return almSettingBuilder.build();
        }).collect(Collectors.toList());
        return ListWsResponse.newBuilder().addAllAlmSettings(wsAlmSettings).build();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ComponentFinder(org.sonar.server.component.ComponentFinder) AlmSetting(org.sonarqube.ws.AlmSettings.AlmSetting) Optional.ofNullable(java.util.Optional.ofNullable) PROVISION_PROJECTS(org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS) ALM(org.sonar.db.alm.setting.ALM) ListWsResponse(org.sonarqube.ws.AlmSettings.ListWsResponse) Collectors(java.util.stream.Collectors) DbSession(org.sonar.db.DbSession) ADMIN(org.sonar.api.web.UserRole.ADMIN) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) List(java.util.List) WebService(org.sonar.api.server.ws.WebService) Response(org.sonar.api.server.ws.Response) ProjectDto(org.sonar.db.project.ProjectDto) Change(org.sonar.api.server.ws.Change) UserSession(org.sonar.server.user.UserSession) Comparator(java.util.Comparator) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) AlmSetting(org.sonarqube.ws.AlmSettings.AlmSetting) Request(org.sonar.api.server.ws.Request) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto)

Aggregations

Comparator (java.util.Comparator)1 List (java.util.List)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors (java.util.stream.Collectors)1 Change (org.sonar.api.server.ws.Change)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 ADMIN (org.sonar.api.web.UserRole.ADMIN)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 ALM (org.sonar.db.alm.setting.ALM)1 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)1 PROVISION_PROJECTS (org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS)1 ProjectDto (org.sonar.db.project.ProjectDto)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 UserSession (org.sonar.server.user.UserSession)1 WsUtils.writeProtobuf (org.sonar.server.ws.WsUtils.writeProtobuf)1 AlmSetting (org.sonarqube.ws.AlmSettings.AlmSetting)1 ListWsResponse (org.sonarqube.ws.AlmSettings.ListWsResponse)1