Search in sources :

Example 66 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class UpdateAction method writeUser.

private void writeUser(DbSession dbSession, Response response, String login) {
    JsonWriter json = response.newJsonWriter().beginObject();
    json.name("user");
    Set<String> groups = Sets.newHashSet();
    UserDto user = checkFound(dbClient.userDao().selectByLogin(dbSession, login), "User '%s' doesn't exist", login);
    groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login));
    userWriter.write(json, user, groups, UserJsonWriter.FIELDS);
    json.endObject().close();
}
Also used : UserDto(org.sonar.db.user.UserDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 67 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class LinesAction method handle.

@Override
public void handle(Request request, Response response) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto file = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_UUID), request.param(PARAM_KEY), UUID_AND_KEY);
        userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
        int from = request.mandatoryParamAsInt(PARAM_FROM);
        int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE);
        Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.key());
        JsonWriter json = response.newJsonWriter().beginObject();
        writeSource(lines, json);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 68 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class ListAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    checkState(context != null && !context.controllers().isEmpty(), "Web service controllers must be loaded before calling the action");
    boolean includeInternals = request.mandatoryParamAsBoolean("include_internals");
    JsonWriter writer = response.newJsonWriter();
    writer.beginObject();
    writer.name("webServices").beginArray();
    // sort controllers by path
    Ordering<WebService.Controller> ordering = Ordering.natural().onResultOf(WebService.Controller::path);
    for (WebService.Controller controller : ordering.sortedCopy(context.controllers())) {
        writeController(writer, controller, includeInternals);
    }
    writer.endArray();
    writer.endObject();
    writer.close();
}
Also used : WebService(org.sonar.api.server.ws.WebService) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 69 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class JSONReport method writeJson.

@VisibleForTesting
void writeJson(Writer writer) {
    try (JsonWriter json = JsonWriter.of(writer)) {
        json.beginObject();
        json.prop("version", server.getVersion());
        Set<RuleKey> ruleKeys = new LinkedHashSet<>();
        Set<String> userLogins = new LinkedHashSet<>();
        writeJsonIssues(json, ruleKeys, userLogins);
        writeJsonComponents(json);
        writeJsonRules(json, ruleKeys);
        writeUsers(json, userLogins);
        json.endObject();
    } catch (IOException e) {
        throw new IllegalStateException("Unable to write JSON report", e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RuleKey(org.sonar.api.rule.RuleKey) IOException(java.io.IOException) JsonWriter(org.sonar.api.utils.text.JsonWriter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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