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();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class LinesAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto file = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_UUID), request.param(PARAM_KEY), UUID_AND_KEY);
userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
int from = request.mandatoryParamAsInt(PARAM_FROM);
int to = MoreObjects.firstNonNull(request.paramAsInt(PARAM_TO), Integer.MAX_VALUE);
Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.key());
JsonWriter json = response.newJsonWriter().beginObject();
writeSource(lines, json);
json.endObject().close();
}
}
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 {
checkState(context != null && !context.controllers().isEmpty(), "Web service controllers must be loaded before calling the action");
boolean includeInternals = request.mandatoryParamAsBoolean("include_internals");
JsonWriter writer = response.newJsonWriter();
writer.beginObject();
writer.name("webServices").beginArray();
// sort controllers by path
Ordering<WebService.Controller> ordering = Ordering.natural().onResultOf(WebService.Controller::path);
for (WebService.Controller controller : ordering.sortedCopy(context.controllers())) {
writeController(writer, controller, includeInternals);
}
writer.endArray();
writer.endObject();
writer.close();
}
use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.
the class JSONReport method writeJson.
@VisibleForTesting
void writeJson(Writer writer) {
try (JsonWriter json = JsonWriter.of(writer)) {
json.beginObject();
json.prop("version", server.getVersion());
Set<RuleKey> ruleKeys = new LinkedHashSet<>();
Set<String> userLogins = new LinkedHashSet<>();
writeJsonIssues(json, ruleKeys, userLogins);
writeJsonComponents(json);
writeJsonRules(json, ruleKeys);
writeUsers(json, userLogins);
json.endObject();
} catch (IOException e) {
throw new IllegalStateException("Unable to write JSON report", e);
}
}
Aggregations