Search in sources :

Example 1 with SearchGroupMembershipDto

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

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

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 (org.sonar.core.util.stream.MoreCollectors)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 GroupDto (org.sonar.db.user.GroupDto)2 SearchGroupMembershipDto (org.sonar.db.user.SearchGroupMembershipDto)2