use of org.sonar.db.user.GroupMembershipDto in project sonarqube by SonarSource.
the class GroupsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn().checkIsSystemAdministrator();
String login = request.mandatoryParam(PARAM_LOGIN);
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);
GroupMembershipQuery query = GroupMembershipQuery.builder().login(login).groupSearch(queryString).membership(getMembership(selected)).pageIndex(page).pageSize(pageSize).build();
try (DbSession dbSession = dbClient.openSession(false)) {
UserDto user = dbClient.userDao().selectByLogin(dbSession, login);
if (user == null) {
throw new NotFoundException(String.format("User with login '%s' has not been found", login));
}
int total = dbClient.groupMembershipDao().countGroups(dbSession, query, user.getId());
Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
List<GroupMembershipDto> groups = dbClient.groupMembershipDao().selectGroups(dbSession, query, user.getId(), paging.offset(), pageSize);
JsonWriter json = response.newJsonWriter().beginObject();
writeGroups(json, groups);
writePaging(json, paging);
json.endObject().close();
}
}
use of org.sonar.db.user.GroupMembershipDto in project sonarqube by SonarSource.
the class GroupsAction method writeGroups.
private static void writeGroups(JsonWriter json, List<GroupMembershipDto> groups) {
json.name("groups").beginArray();
for (GroupMembershipDto group : groups) {
json.beginObject().prop(FIELD_ID, group.getId().toString()).prop(FIELD_NAME, group.getName()).prop(FIELD_DESCRIPTION, group.getDescription()).prop(FIELD_SELECTED, group.getUserId() != null).endObject();
}
json.endArray();
}
Aggregations