Search in sources :

Example 1 with UserMembershipQuery

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

the class UsersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
    int page = request.mandatoryParamAsInt(Param.PAGE);
    String queryString = request.param(Param.TEXT_QUERY);
    String selected = request.mandatoryParam(Param.SELECTED);
    try (DbSession dbSession = dbClient.openSession(false)) {
        GroupId group = support.findGroup(dbSession, request);
        userSession.checkPermission(OrganizationPermission.ADMINISTER, group.getOrganizationUuid());
        UserMembershipQuery query = UserMembershipQuery.builder().groupId(group.getId()).memberSearch(queryString).membership(getMembership(selected)).pageIndex(page).pageSize(pageSize).build();
        int total = dbClient.groupMembershipDao().countMembers(dbSession, query);
        Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
        List<UserMembershipDto> users = dbClient.groupMembershipDao().selectMembers(dbSession, query, paging.offset(), paging.pageSize());
        JsonWriter json = response.newJsonWriter().beginObject();
        writeMembers(json, users);
        writePaging(json, paging);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) UserMembershipQuery(org.sonar.db.user.UserMembershipQuery) UserMembershipDto(org.sonar.db.user.UserMembershipDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 2 with UserMembershipQuery

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

the class UpdateAction method writeResponse.

private void writeResponse(DbSession dbSession, Request request, Response response, OrganizationDto organization, GroupDto group) {
    UserMembershipQuery query = UserMembershipQuery.builder().groupId(group.getId()).membership(GroupMembershipQuery.IN).build();
    int membersCount = dbClient.groupMembershipDao().countMembers(dbSession, query);
    WsUserGroups.UpdateResponse.Builder respBuilder = WsUserGroups.UpdateResponse.newBuilder();
    respBuilder.setGroup(toProtobuf(organization, group, membersCount));
    writeProtobuf(respBuilder.build(), request, response);
}
Also used : UserMembershipQuery(org.sonar.db.user.UserMembershipQuery)

Aggregations

UserMembershipQuery (org.sonar.db.user.UserMembershipQuery)2 Paging (org.sonar.api.utils.Paging)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 DbSession (org.sonar.db.DbSession)1 UserMembershipDto (org.sonar.db.user.UserMembershipDto)1