Search in sources :

Example 1 with SearchUserMembershipDto

use of org.sonar.db.user.SearchUserMembershipDto 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 SearchUserMembershipDto

use of org.sonar.db.user.SearchUserMembershipDto in project sonarqube by SonarSource.

the class SearchUsersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    SearchQualityGateUsersRequest wsRequest = buildRequest(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityGateDto gate = wsSupport.getByName(dbSession, wsRequest.getQualityGate());
        wsSupport.checkCanLimitedEdit(dbSession, gate);
        SearchPermissionQuery query = builder().setQualityGate(gate).setQuery(wsRequest.getQuery()).setMembership(MEMBERSHIP.get(fromParam(wsRequest.getSelected()))).build();
        int total = dbClient.qualityGateUserPermissionDao().countByQuery(dbSession, query);
        List<SearchUserMembershipDto> usersMembership = dbClient.qualityGateUserPermissionDao().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 : SearchPermissionQuery(org.sonar.db.user.SearchPermissionQuery) TEXT_QUERY(org.sonar.api.server.ws.WebService.Param.TEXT_QUERY) 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) Request(org.sonar.api.server.ws.Request) WebService(org.sonar.api.server.ws.WebService) SelectionMode.fromParam(org.sonar.api.server.ws.WebService.SelectionMode.fromParam) Map(java.util.Map) Response(org.sonar.api.server.ws.Response) ANY(org.sonar.db.user.SearchPermissionQuery.ANY) ACTION_SEARCH_USERS(org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_SEARCH_USERS) SelectionMode(org.sonar.api.server.ws.WebService.SelectionMode) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) SearchQualityGatePermissionQuery.builder(org.sonar.db.qualitygate.SearchQualityGatePermissionQuery.builder) Pagination.forPage(org.sonar.db.Pagination.forPage) Optional.ofNullable(java.util.Optional.ofNullable) AvatarResolver(org.sonar.server.issue.AvatarResolver) SearchPermissionQuery(org.sonar.db.user.SearchPermissionQuery) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) PARAM_GATE_NAME(org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_NAME) List(java.util.List) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) SearchUsersResponse(org.sonarqube.ws.Qualitygates.SearchUsersResponse) IN(org.sonar.db.user.SearchPermissionQuery.IN) DESELECTED(org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED) OUT(org.sonar.db.user.SearchPermissionQuery.OUT) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) SearchUserMembershipDto(org.sonar.db.user.SearchUserMembershipDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Aggregations

Strings.emptyToNull (com.google.common.base.Strings.emptyToNull)2 List (java.util.List)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)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 SelectionMode (org.sonar.api.server.ws.WebService.SelectionMode)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.uniqueIndex (org.sonar.core.util.stream.MoreCollectors.uniqueIndex)2 DbClient (org.sonar.db.DbClient)2 DbSession (org.sonar.db.DbSession)2 Pagination.forPage (org.sonar.db.Pagination.forPage)2