use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class OrganizationAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String organizationKey = request.mandatoryParam(PARAM_ORGANIZATION);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = checkFoundWithOptional(dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization with key '%s'", organizationKey);
JsonWriter json = response.newJsonWriter();
json.beginObject();
writeOrganization(json, organization);
json.endObject().close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class ScmAction method handle.
@Override
public void handle(Request request, Response response) {
String fileKey = request.mandatoryParam("key");
int from = Math.max(request.mandatoryParamAsInt("from"), 1);
int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
boolean commitsByLine = request.mandatoryParamAsBoolean("commits_by_line");
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto file = componentFinder.getByKey(dbSession, fileKey);
userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
Iterable<DbFileSources.Line> sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File '%s' has no sources", fileKey);
JsonWriter json = response.newJsonWriter().beginObject();
writeSource(sourceLines, commitsByLine, json);
json.endObject().close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class InstalledPluginsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
JsonWriter json = response.newJsonWriter().beginArray();
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
Version version = pluginInfo.getVersion();
json.beginObject().prop("key", pluginInfo.getKey()).prop("name", pluginInfo.getName());
if (version != null) {
json.prop("version", version.getName());
}
json.endObject();
}
json.endArray().close();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class DeactivateAction method writeResponse.
private void writeResponse(Response response, String login) {
try (DbSession dbSession = dbClient.openSession(false)) {
UserDto user = dbClient.userDao().selectByLogin(dbSession, login);
// safeguard. It exists as the check has already been done earlier
// when deactivating user
checkFound(user, "User '%s' doesn't exist", login);
JsonWriter json = response.newJsonWriter().beginObject();
json.name("user");
Set<String> groups = Sets.newHashSet();
groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login));
userWriter.write(json, user, groups, UserJsonWriter.FIELDS);
json.endObject().close();
}
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class UpdateAction method writeUser.
private void writeUser(DbSession dbSession, Response response, String login) {
JsonWriter json = response.newJsonWriter().beginObject();
json.name("user");
Set<String> groups = Sets.newHashSet();
UserDto user = checkFound(dbClient.userDao().selectByLogin(dbSession, login), "User '%s' doesn't exist", login);
groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login));
userWriter.write(json, user, groups, UserJsonWriter.FIELDS);
json.endObject().close();
}
Aggregations