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();
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations