Search in sources :

Example 1 with SearchQualityProfilePermissionQuery

use of org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery in project sonarqube by SonarSource.

the class SearchUsersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    SearchQualityProfileUsersRequest wsRequest = buildRequest(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, wsRequest.getQualityProfile(), wsRequest.getLanguage());
        wsSupport.checkCanEdit(dbSession, profile);
        SearchQualityProfilePermissionQuery query = builder().setProfile(profile).setQuery(wsRequest.getQuery()).setMembership(MEMBERSHIP.get(fromParam(wsRequest.getSelected()))).build();
        int total = dbClient.qProfileEditUsersDao().countByQuery(dbSession, query);
        List<SearchUserMembershipDto> usersMembership = dbClient.qProfileEditUsersDao().selectByQuery(dbSession, query, forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize()));
        Map<String, UserDto> usersById = dbClient.userDao().selectByUuids(dbSession, usersMembership.stream().map(SearchUserMembershipDto::getUserUuid).collect(toList())).stream().collect(uniqueIndex(UserDto::getUuid));
        writeProtobuf(SearchUsersResponse.newBuilder().addAllUsers(usersMembership.stream().map(userMembershipDto -> toUser(usersById.get(userMembershipDto.getUserUuid()), userMembershipDto.isSelected())).collect(toList())).setPaging(buildPaging(wsRequest, total)).build(), request, response);
    }
}
Also used : TEXT_QUERY(org.sonar.api.server.ws.WebService.Param.TEXT_QUERY) Arrays(java.util.Arrays) ACTION_SEARCH_USERS(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_USERS) UserDto(org.sonar.db.user.UserDto) SELECTED(org.sonar.api.server.ws.WebService.Param.SELECTED) DbSession(org.sonar.db.DbSession) ALL(org.sonar.api.server.ws.WebService.SelectionMode.ALL) SearchUserMembershipDto(org.sonar.db.user.SearchUserMembershipDto) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) ANY(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.ANY) Request(org.sonar.api.server.ws.Request) Languages(org.sonar.api.resources.Languages) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) WebService(org.sonar.api.server.ws.WebService) SelectionMode.fromParam(org.sonar.api.server.ws.WebService.SelectionMode.fromParam) PARAM_LANGUAGE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) SelectionMode(org.sonar.api.server.ws.WebService.SelectionMode) Language(org.sonar.api.resources.Language) PARAM_QUALITY_PROFILE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) Pagination.forPage(org.sonar.db.Pagination.forPage) ImmutableMap(com.google.common.collect.ImmutableMap) Optional.ofNullable(java.util.Optional.ofNullable) AvatarResolver(org.sonar.server.issue.AvatarResolver) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) List(java.util.List) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) OUT(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.OUT) SearchQualityProfilePermissionQuery(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery) IN(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.IN) SearchUsersResponse(org.sonarqube.ws.Qualityprofiles.SearchUsersResponse) DESELECTED(org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) SearchQualityProfilePermissionQuery.builder(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.builder) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) SearchUserMembershipDto(org.sonar.db.user.SearchUserMembershipDto) SearchQualityProfilePermissionQuery(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery)

Example 2 with SearchQualityProfilePermissionQuery

use of org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery in project sonarqube by SonarSource.

the class SearchGroupsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    SearchQualityProfileUsersRequest wsRequest = buildRequest(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, wsRequest.getQualityProfile(), wsRequest.getLanguage());
        wsSupport.checkCanEdit(dbSession, profile);
        SearchQualityProfilePermissionQuery query = builder().setProfile(profile).setQuery(wsRequest.getQuery()).setMembership(MEMBERSHIP.get(fromParam(wsRequest.getSelected()))).build();
        int total = dbClient.qProfileEditGroupsDao().countByQuery(dbSession, query);
        List<SearchGroupMembershipDto> groupMemberships = dbClient.qProfileEditGroupsDao().selectByQuery(dbSession, query, forPage(wsRequest.getPage()).andSize(wsRequest.getPageSize()));
        Map<String, GroupDto> groupsByUuid = dbClient.groupDao().selectByUuids(dbSession, groupMemberships.stream().map(SearchGroupMembershipDto::getGroupUuid).collect(MoreCollectors.toList())).stream().collect(MoreCollectors.uniqueIndex(GroupDto::getUuid));
        writeProtobuf(Qualityprofiles.SearchGroupsResponse.newBuilder().addAllGroups(groupMemberships.stream().map(groupsMembership -> toGroup(groupsByUuid.get(groupsMembership.getGroupUuid()), groupsMembership.isSelected())).collect(toList())).setPaging(buildPaging(wsRequest, total)).build(), request, response);
    }
}
Also used : TEXT_QUERY(org.sonar.api.server.ws.WebService.Param.TEXT_QUERY) Arrays(java.util.Arrays) Qualityprofiles(org.sonarqube.ws.Qualityprofiles) SELECTED(org.sonar.api.server.ws.WebService.Param.SELECTED) DbSession(org.sonar.db.DbSession) ALL(org.sonar.api.server.ws.WebService.SelectionMode.ALL) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) ANY(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.ANY) Request(org.sonar.api.server.ws.Request) Languages(org.sonar.api.resources.Languages) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) WebService(org.sonar.api.server.ws.WebService) SelectionMode.fromParam(org.sonar.api.server.ws.WebService.SelectionMode.fromParam) PARAM_LANGUAGE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Language(org.sonar.api.resources.Language) PARAM_QUALITY_PROFILE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) ACTION_SEARCH_GROUPS(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SEARCH_GROUPS) GroupDto(org.sonar.db.user.GroupDto) Pagination.forPage(org.sonar.db.Pagination.forPage) Optional.ofNullable(java.util.Optional.ofNullable) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) List(java.util.List) OUT(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.OUT) SearchQualityProfilePermissionQuery(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery) SearchGroupMembershipDto(org.sonar.db.user.SearchGroupMembershipDto) IN(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.IN) DESELECTED(org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) SearchQualityProfilePermissionQuery.builder(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery.builder) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) SearchGroupMembershipDto(org.sonar.db.user.SearchGroupMembershipDto) GroupDto(org.sonar.db.user.GroupDto) SearchQualityProfilePermissionQuery(org.sonar.db.qualityprofile.SearchQualityProfilePermissionQuery)

Aggregations

Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)2 Language (org.sonar.api.resources.Language)2 Languages (org.sonar.api.resources.Languages)2 Request (org.sonar.api.server.ws.Request)2 Response (org.sonar.api.server.ws.Response)2 WebService (org.sonar.api.server.ws.WebService)2 PAGE (org.sonar.api.server.ws.WebService.Param.PAGE)2 PAGE_SIZE (org.sonar.api.server.ws.WebService.Param.PAGE_SIZE)2 SELECTED (org.sonar.api.server.ws.WebService.Param.SELECTED)2 TEXT_QUERY (org.sonar.api.server.ws.WebService.Param.TEXT_QUERY)2 ALL (org.sonar.api.server.ws.WebService.SelectionMode.ALL)2 DESELECTED (org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED)2 SelectionMode.fromParam (org.sonar.api.server.ws.WebService.SelectionMode.fromParam)2 MoreCollectors.toList (org.sonar.core.util.stream.MoreCollectors.toList)2 MoreCollectors.toSet (org.sonar.core.util.stream.MoreCollectors.toSet)2 DbClient (org.sonar.db.DbClient)2 DbSession (org.sonar.db.DbSession)2