Search in sources :

Example 46 with JsonWriter

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

the class DbMigrationStatusAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    Optional<Long> currentVersion = databaseVersion.getVersion();
    checkState(currentVersion.isPresent(), NO_CONNECTION_TO_DB);
    JsonWriter json = response.newJsonWriter();
    try {
        DatabaseVersion.Status status = databaseVersion.getStatus();
        if (status == DatabaseVersion.Status.UP_TO_DATE || status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) {
            write(json, databaseMigrationState);
        } else if (!database.getDialect().supportsMigration()) {
            writeNotSupportedResponse(json);
        } else {
            switch(databaseMigrationState.getStatus()) {
                case RUNNING:
                case FAILED:
                case SUCCEEDED:
                    write(json, databaseMigrationState);
                    break;
                case NONE:
                    writeMigrationRequiredResponse(json);
                    break;
                default:
                    throw new IllegalArgumentException(UNSUPPORTED_DATABASE_MIGRATION_STATUS);
            }
        }
    } finally {
        json.close();
    }
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) DatabaseVersion(org.sonar.server.platform.db.migration.version.DatabaseVersion)

Example 47 with JsonWriter

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

the class PendingAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkIsSystemAdministrator();
    ImmutableMap<String, Plugin> compatiblePluginsByKey = compatiblePluginsByKey(updateCenterMatrixFactory);
    JsonWriter jsonWriter = response.newJsonWriter();
    jsonWriter.beginObject();
    writePlugins(jsonWriter, compatiblePluginsByKey);
    jsonWriter.endObject();
    jsonWriter.close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) Plugin(org.sonar.updatecenter.common.Plugin)

Example 48 with JsonWriter

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

the class BulkRuleActivationActions method writeResponse.

private static void writeResponse(BulkChangeResult result, Response response) {
    JsonWriter json = response.newJsonWriter().beginObject();
    json.prop("succeeded", result.countSucceeded());
    json.prop("failed", result.countFailed());
    writeErrors(json, result.getErrors());
    json.endObject().close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 49 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) {
    JsonWriter writer = response.newJsonWriter().beginObject().name("qualitygates").beginArray();
    for (QualityGateDto qgate : qualityGates.list()) {
        QualityGatesWs.writeQualityGate(qgate, writer);
    }
    writer.endArray();
    QualityGateDto defaultQgate = qualityGates.getDefault();
    if (defaultQgate != null) {
        writer.prop("default", defaultQgate.getId());
    }
    writer.endObject().close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 50 with JsonWriter

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

the class IndexAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    request.param(PARAM_FORMAT);
    JsonWriter json = response.newJsonWriter();
    json.beginArray();
    doHandle(json, request);
    json.endArray();
    json.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