Search in sources :

Example 61 with JsonWriter

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();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 62 with JsonWriter

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();
}
Also used : WebService(org.sonar.api.server.ws.WebService) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 63 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class AppAction method handle.

@Override
public void handle(Request request, Response response) {
    try (DbSession session = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(session, request.param(PARAM_COMPONENT_ID), request.param(PARAM_COMPONENT), ParamNames.COMPONENT_ID_AND_COMPONENT);
        userSession.checkComponentPermission(UserRole.USER, component);
        JsonWriter json = response.newJsonWriter();
        json.beginObject();
        Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session);
        appendComponent(json, component, userSession, session);
        appendPermissions(json, component, userSession);
        appendMeasures(json, measuresByMetricKey);
        json.endObject();
        json.close();
    }
}
Also used : MeasureDto(org.sonar.db.measure.MeasureDto) DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 64 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class WebhookPayloadFactoryImpl method create.

@Override
public WebhookPayload create(PostProjectAnalysisTask.ProjectAnalysis analysis) {
    Writer string = new StringWriter();
    try (JsonWriter writer = JsonWriter.of(string)) {
        writer.beginObject();
        writeServer(writer);
        writeTask(writer, analysis.getCeTask());
        analysis.getAnalysisDate().ifPresent(date -> writer.propDateTime("analysedAt", date));
        writeProject(analysis, writer, analysis.getProject());
        writeQualityGate(writer, analysis.getQualityGate());
        writeAnalysisProperties(writer, analysis.getScannerContext());
        writer.endObject().close();
        return new WebhookPayload(analysis.getProject().getKey(), string.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(org.sonar.api.utils.text.JsonWriter) JsonWriter(org.sonar.api.utils.text.JsonWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 65 with JsonWriter

use of org.sonar.api.utils.text.JsonWriter in project sonarqube by SonarSource.

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) {
    try (DbSession dbSession = dbClient.openSession(false);
        JsonWriter json = response.newJsonWriter()) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param("uuid"), request.param("key"), UUID_AND_KEY);
        userSession.checkComponentPermission(UserRole.CODEVIEWER, component);
        json.beginObject();
        String duplications = findDataFromComponent(dbSession, component);
        List<DuplicationsParser.Block> blocks = parser.parse(component, duplications, dbSession);
        duplicationsJsonWriter.write(blocks, json, dbSession);
        json.endObject();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Aggregations

JsonWriter (org.sonar.api.utils.text.JsonWriter)69 DbSession (org.sonar.db.DbSession)24 ComponentDto (org.sonar.db.component.ComponentDto)12 UserDto (org.sonar.db.user.UserDto)6 MetricDto (org.sonar.db.metric.MetricDto)5 OrganizationDto (org.sonar.db.organization.OrganizationDto)5 SearchOptions (org.sonar.server.es.SearchOptions)5 StringWriter (java.io.StringWriter)4 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Language (org.sonar.api.resources.Language)3 Paging (org.sonar.api.utils.Paging)2 PluginInfo (org.sonar.core.platform.PluginInfo)2 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)2 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)2 BadRequestException (org.sonar.server.exceptions.BadRequestException)2 NotFoundException (org.sonar.server.exceptions.NotFoundException)2 DatabaseVersion (org.sonar.server.platform.db.migration.version.DatabaseVersion)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1