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