use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class SearchOptionsTest method writeJson.
@Test
public void writeJson() {
SearchOptions options = new SearchOptions().setPage(3, 10);
StringWriter json = new StringWriter();
JsonWriter jsonWriter = JsonWriter.of(json).beginObject();
options.writeJson(jsonWriter, 42L);
jsonWriter.endObject().close();
JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}");
}
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 {
userSession.checkLoggedIn().checkIsSystemAdministrator();
String key = request.mandatoryParam(PARAM_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
MetricDto metricTemplate = newMetricTemplate(request);
MetricDto metricInDb = dbClient.metricDao().selectByKey(dbSession, key);
checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
if (metricIsNotInDb(metricInDb)) {
metricInDb = insertNewMetric(dbSession, metricTemplate);
} else {
updateMetric(dbSession, metricInDb, metricTemplate);
}
JsonWriter json = response.newJsonWriter();
writeMetric(json, metricInDb);
json.close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class DomainsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
List<String> domains = dbClient.metricDao().selectEnabledDomains(dbSession);
JsonWriter json = response.newJsonWriter();
json.beginObject();
writeDomains(json, domains);
json.endObject();
json.close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM);
try (DbSession dbSession = dbClient.openSession(false)) {
List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions.getOffset(), searchOptions.getLimit());
int nbMetrics = dbClient.metricDao().countEnabled(dbSession, isCustom);
JsonWriter json = response.newJsonWriter();
json.beginObject();
Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
writeMetrics(json, metrics, desiredFields);
searchOptions.writeJson(json, nbMetrics);
json.endObject();
json.close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class TypesAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
JsonWriter json = response.newJsonWriter();
json.beginObject();
json.name("types");
json.beginArray();
for (Metric.ValueType metricType : Metric.ValueType.values()) {
json.value(metricType.name());
}
json.endArray();
json.endObject();
json.close();
}
Aggregations