use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class RepositoriesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String query = request.param(Param.TEXT_QUERY);
String languageKey = request.param(LANGUAGE);
JsonWriter json = response.newJsonWriter().beginObject().name("repositories").beginArray();
for (RuleRepositoryDto repo : listMatchingRepositories(query, languageKey)) {
json.beginObject().prop("key", repo.getKey()).prop("name", repo.getName()).prop(LANGUAGE, repo.getLanguage()).endObject();
}
json.endArray().endObject().close();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class TagsAction method handle.
@Override
public void handle(Request request, Response response) {
String query = request.param(Param.TEXT_QUERY);
int pageSize = request.mandatoryParamAsInt("ps");
Set<String> tags = service.listTags(query, pageSize);
JsonWriter json = response.newJsonWriter().beginObject();
json.name("tags").beginArray();
for (String tag : tags) {
json.value(tag);
}
json.endArray().endObject().close();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class SettingsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
boolean isSysAdmin = userSession.isSystemAdministrator();
JsonWriter json = response.newJsonWriter().beginObject();
json.prop("showUpdateCenter", isSysAdmin && settings.getBoolean(WebConstants.SONAR_UPDATECENTER_ACTIVATE));
json.name("extensions").beginArray();
if (isSysAdmin) {
for (Page page : pageRepository.getGlobalPages(true)) {
json.beginObject().prop("key", page.getKey()).prop("name", page.getName()).endObject();
}
}
json.endArray();
json.endObject().close();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class WebServiceEngine method sendErrors.
private static void sendErrors(Response response, int status, List<String> errors) {
Response.Stream stream = response.stream();
if (stream instanceof ServletResponse.ServletStream) {
((ServletResponse.ServletStream) stream).reset();
}
stream.setStatus(status);
stream.setMediaType(MediaTypes.JSON);
try (JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8))) {
json.beginObject();
writeErrors(json, errors);
json.endObject();
} catch (Exception e) {
// Do not hide the potential exception raised in the try block.
throw Throwables.propagate(e);
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
int page = request.mandatoryParamAsInt(Param.PAGE);
int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
SearchOptions options = new SearchOptions().setPage(page, pageSize);
String query = defaultIfBlank(request.param(Param.TEXT_QUERY), "");
Set<String> fields = neededFields(request);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = groupWsSupport.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY));
userSession.checkLoggedIn().checkPermission(ADMINISTER, organization);
int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query);
List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize);
List<Integer> groupIds = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size()));
Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds);
JsonWriter json = response.newJsonWriter().beginObject();
options.writeJson(json, limit);
writeGroups(json, groups, userCountByGroup, fields);
json.endObject().close();
}
}
Aggregations