use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class ValidateAction method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
boolean isAuthenticated = authenticate(request, response);
response.setContentType(MediaTypes.JSON);
try (JsonWriter jsonWriter = JsonWriter.of(response.getWriter())) {
jsonWriter.beginObject();
jsonWriter.prop("valid", isAuthenticated);
jsonWriter.endObject();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class AuthorsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String query = request.param(Param.TEXT_QUERY);
int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject().name("authors").beginArray();
for (String login : service.listAuthors(query, pageSize)) {
json.value(login);
}
json.endArray().endObject();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class SearchMyOrganizationsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
if (!userSession.isLoggedIn()) {
response.noContent();
return;
}
try (DbSession dbSession = dbClient.openSession(false);
JsonWriter jsonWriter = response.newJsonWriter()) {
jsonWriter.beginObject();
jsonWriter.name("organizations").beginArray();
dbClient.organizationDao().selectByPermission(dbSession, userSession.getUserId(), OrganizationPermission.ADMINISTER.getKey()).forEach(dto -> jsonWriter.value(dto.getKey()));
jsonWriter.endArray();
jsonWriter.endObject();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class ComponentTagsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
Builder<String, Object> paramBuilder = ImmutableMap.<String, Object>builder().put(IssuesWsParameters.PARAM_COMPONENT_UUIDS, request.mandatoryParam(PARAM_COMPONENT_UUID)).put(IssuesWsParameters.PARAM_RESOLVED, false);
if (request.hasParam(PARAM_CREATED_AFTER)) {
paramBuilder.put(PARAM_CREATED_AFTER, request.param(PARAM_CREATED_AFTER));
}
IssueQuery query = queryService.createFromMap(paramBuilder.build());
int pageSize = request.mandatoryParamAsInt(PAGE_SIZE);
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject().name("tags").beginArray();
for (Map.Entry<String, Long> tag : service.listTagsForComponent(query, pageSize).entrySet()) {
json.beginObject().prop("key", tag.getKey()).prop("value", tag.getValue()).endObject();
}
json.endArray().endObject();
}
}
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) throws Exception {
String query = request.param(Param.TEXT_QUERY);
int pageSize = request.mandatoryParamAsInt("ps");
JsonWriter json = response.newJsonWriter().beginObject().name("tags").beginArray();
for (String tag : service.listTags(query, pageSize)) {
json.value(tag);
}
json.endArray().endObject().close();
}
Aggregations