Search in sources :

Example 6 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 {
    String query = request.param(Param.TEXT_QUERY);
    int pageSize = request.mandatoryParamAsInt("ps");
    JsonWriter json = response.newJsonWriter().beginObject().name("languages").beginArray();
    for (Language language : listMatchingLanguages(query, pageSize)) {
        json.beginObject().prop("key", language.getKey()).prop("name", language.getName()).endObject();
    }
    json.endArray().endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 7 with JsonWriter

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

the class CreateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String valueAsString = request.mandatoryParam(PARAM_VALUE);
    String description = request.param(PARAM_DESCRIPTION);
    long now = system.now();
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
        MetricDto metric = searchMetric(dbSession, request);
        checkPermissions(userSession, component);
        checkIsProjectOrModule(component);
        checkMeasureDoesNotExistAlready(dbSession, component, metric);
        UserDto user = dbClient.userDao().selectOrFailByLogin(dbSession, userSession.getLogin());
        CustomMeasureDto measure = new CustomMeasureDto().setComponentUuid(component.uuid()).setMetricId(metric.getId()).setDescription(description).setUserLogin(user.getLogin()).setCreatedAt(now).setUpdatedAt(now);
        validator.setMeasureValue(measure, valueAsString, metric);
        dbClient.customMeasureDao().insert(dbSession, measure);
        dbSession.commit();
        JsonWriter json = response.newJsonWriter();
        customMeasureJsonWriter.write(json, measure, metric, component, user, true, CustomMeasureJsonWriter.OPTIONAL_FIELDS);
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 8 with JsonWriter

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

the class UpgradesAction method handle.

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

Example 9 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 {
    Date timestamp = request.paramAsDateTime(TS_PARAM);
    if (timestamp != null && timestamp.after(server.getStartedAt())) {
        response.stream().setStatus(HTTP_NOT_MODIFIED).output().close();
        return;
    }
    String localeParam = request.mandatoryParam(LOCALE_PARAM);
    Locale locale = Locale.forLanguageTag(localeParam);
    checkArgument(!locale.getISO3Language().isEmpty(), "'%s' cannot be parsed as a BCP47 language tag", localeParam);
    JsonWriter json = response.newJsonWriter().beginObject();
    for (String messageKey : i18n.getPropertyKeys()) {
        json.prop(messageKey, i18n.message(locale, messageKey, messageKey));
    }
    json.endObject().close();
}
Also used : Locale(java.util.Locale) JsonWriter(org.sonar.api.utils.text.JsonWriter) Date(java.util.Date)

Example 10 with JsonWriter

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

the class InfoAction method handle.

@Override
public void handle(Request request, Response response) {
    userSession.checkIsSystemAdministrator();
    JsonWriter json = response.newJsonWriter();
    writeJson(json);
    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