Search in sources :

Example 41 with JsonWriter

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

the class UpdateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn().checkIsSystemAdministrator();
    int id = request.mandatoryParamAsInt(PARAM_ID);
    try (DbSession dbSession = dbClient.openSession(false)) {
        MetricDto metricTemplate = newMetricTemplate(request);
        MetricDto metricInDb = dbClient.metricDao().selectById(dbSession, id);
        checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
        updateMetricInDb(dbSession, metricInDb, metricTemplate);
        JsonWriter json = response.newJsonWriter();
        writeMetric(json, metricInDb);
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 42 with JsonWriter

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

the class MigrateDbAction 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, migrationState);
        } else if (!database.getDialect().supportsMigration()) {
            writeNotSupportedResponse(json);
        } else {
            switch(migrationState.getStatus()) {
                case RUNNING:
                case FAILED:
                case SUCCEEDED:
                    write(json, migrationState);
                    break;
                case NONE:
                    databaseMigration.startIt();
                    writeJustStartedResponse(json, migrationState);
                    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 43 with JsonWriter

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

the class StatusAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter();
    writeJson(json);
    json.close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 44 with JsonWriter

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

the class UpdatesAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkIsSystemAdministrator();
    JsonWriter jsonWriter = response.newJsonWriter();
    jsonWriter.beginObject();
    Optional<UpdateCenter> updateCenter = updateCenterMatrixFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH);
    writePlugins(jsonWriter, updateCenter);
    pluginWSCommons.writeUpdateCenterProperties(jsonWriter, updateCenter);
    jsonWriter.endObject();
    jsonWriter.close();
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 45 with JsonWriter

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

the class GhostsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
    Set<String> desiredFields = fieldsToReturn(request.paramAsStrings(Param.FIELDS));
    String query = request.param(Param.TEXT_QUERY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = getOrganization(dbSession, request);
        userSession.checkPermission(ADMINISTER, organization);
        long nbOfProjects = dbClient.componentDao().countGhostProjects(dbSession, organization.getUuid(), query);
        List<ComponentDto> projects = dbClient.componentDao().selectGhostProjects(dbSession, organization.getUuid(), query, searchOptions.getOffset(), searchOptions.getLimit());
        JsonWriter json = response.newJsonWriter().beginObject();
        writeProjects(json, projects, desiredFields);
        searchOptions.writeJson(json, nbOfProjects);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

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