Search in sources :

Example 1 with JsonWriter

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 2 with JsonWriter

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();
    }
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 3 with JsonWriter

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();
    }
}
Also used : DbSession(org.sonar.db.DbSession) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 4 with JsonWriter

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();
    }
}
Also used : IssueQuery(org.sonar.server.issue.IssueQuery) JsonWriter(org.sonar.api.utils.text.JsonWriter) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 5 with JsonWriter

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();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter)

Aggregations

JsonWriter (org.sonar.api.utils.text.JsonWriter)69 DbSession (org.sonar.db.DbSession)24 ComponentDto (org.sonar.db.component.ComponentDto)12 UserDto (org.sonar.db.user.UserDto)6 MetricDto (org.sonar.db.metric.MetricDto)5 OrganizationDto (org.sonar.db.organization.OrganizationDto)5 SearchOptions (org.sonar.server.es.SearchOptions)5 StringWriter (java.io.StringWriter)4 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Language (org.sonar.api.resources.Language)3 Paging (org.sonar.api.utils.Paging)2 PluginInfo (org.sonar.core.platform.PluginInfo)2 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)2 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)2 BadRequestException (org.sonar.server.exceptions.BadRequestException)2 NotFoundException (org.sonar.server.exceptions.NotFoundException)2 DatabaseVersion (org.sonar.server.platform.db.migration.version.DatabaseVersion)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1