Search in sources :

Example 56 with JsonWriter

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

the class OrganizationAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String organizationKey = request.mandatoryParam(PARAM_ORGANIZATION);
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = checkFoundWithOptional(dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization with key '%s'", organizationKey);
        JsonWriter json = response.newJsonWriter();
        json.beginObject();
        writeOrganization(json, organization);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 57 with JsonWriter

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

the class ScmAction method handle.

@Override
public void handle(Request request, Response response) {
    String fileKey = request.mandatoryParam("key");
    int from = Math.max(request.mandatoryParamAsInt("from"), 1);
    int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
    boolean commitsByLine = request.mandatoryParamAsBoolean("commits_by_line");
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto file = componentFinder.getByKey(dbSession, fileKey);
        userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
        Iterable<DbFileSources.Line> sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File '%s' has no sources", fileKey);
        JsonWriter json = response.newJsonWriter().beginObject();
        writeSource(sourceLines, commitsByLine, 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 58 with JsonWriter

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

the class InstalledPluginsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter().beginArray();
    for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
        Version version = pluginInfo.getVersion();
        json.beginObject().prop("key", pluginInfo.getKey()).prop("name", pluginInfo.getName());
        if (version != null) {
            json.prop("version", version.getName());
        }
        json.endObject();
    }
    json.endArray().close();
}
Also used : Version(org.sonar.updatecenter.common.Version) PluginInfo(org.sonar.core.platform.PluginInfo) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 59 with JsonWriter

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

the class DeactivateAction method writeResponse.

private void writeResponse(Response response, String login) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto user = dbClient.userDao().selectByLogin(dbSession, login);
        // safeguard. It exists as the check has already been done earlier
        // when deactivating user
        checkFound(user, "User '%s' doesn't exist", login);
        JsonWriter json = response.newJsonWriter().beginObject();
        json.name("user");
        Set<String> groups = Sets.newHashSet();
        groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login));
        userWriter.write(json, user, groups, UserJsonWriter.FIELDS);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 60 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)

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