Search in sources :

Example 1 with SearchPermissionQuery

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

the class SearchGroupsAction 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.qualityGateGroupPermissionsDao().countByQuery(dbSession, query);
        List<SearchGroupMembershipDto> groupMemberships = dbClient.qualityGateGroupPermissionsDao().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(Qualitygates.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 : SearchPermissionQuery(org.sonar.db.user.SearchPermissionQuery) TEXT_QUERY(org.sonar.api.server.ws.WebService.Param.TEXT_QUERY) ACTION_SEARCH_GROUPS(org.sonar.server.qualitygate.ws.QualityGatesWsParameters.ACTION_SEARCH_GROUPS) 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) Request(org.sonar.api.server.ws.Request) WebService(org.sonar.api.server.ws.WebService) Qualitygates(org.sonarqube.ws.Qualitygates) 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) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) GroupDto(org.sonar.db.user.GroupDto) SearchQualityGatePermissionQuery.builder(org.sonar.db.qualitygate.SearchQualityGatePermissionQuery.builder) Pagination.forPage(org.sonar.db.Pagination.forPage) Optional.ofNullable(java.util.Optional.ofNullable) 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) SearchGroupMembershipDto(org.sonar.db.user.SearchGroupMembershipDto) IN(org.sonar.db.user.SearchPermissionQuery.IN) DESELECTED(org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED) OUT(org.sonar.db.user.SearchPermissionQuery.OUT) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) DbSession(org.sonar.db.DbSession) SearchGroupMembershipDto(org.sonar.db.user.SearchGroupMembershipDto) GroupDto(org.sonar.db.user.GroupDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 2 with SearchPermissionQuery

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

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 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 DbClient (org.sonar.db.DbClient)2 DbSession (org.sonar.db.DbSession)2 Pagination.forPage (org.sonar.db.Pagination.forPage)2 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)2 SearchQualityGatePermissionQuery.builder (org.sonar.db.qualitygate.SearchQualityGatePermissionQuery.builder)2 SearchPermissionQuery (org.sonar.db.user.SearchPermissionQuery)2