Search in sources :

Example 51 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) {
    Long qGateId = request.paramAsLong(QualityGatesWsParameters.PARAM_ID);
    String qGateName = request.param(QualityGatesWsParameters.PARAM_NAME);
    checkOneOfIdOrNamePresent(qGateId, qGateName);
    QualityGateDto qGate = qGateId == null ? qualityGates.get(qGateName) : qualityGates.get(qGateId);
    qGateId = qGate.getId();
    JsonWriter writer = response.newJsonWriter().beginObject().prop(QualityGatesWsParameters.PARAM_ID, qGate.getId()).prop(QualityGatesWsParameters.PARAM_NAME, qGate.getName());
    Collection<QualityGateConditionDto> conditions = qualityGates.listConditions(qGateId);
    if (!conditions.isEmpty()) {
        writer.name("conditions").beginArray();
        for (QualityGateConditionDto condition : conditions) {
            QualityGatesWs.writeQualityGateCondition(condition, writer);
        }
        writer.endArray();
    }
    writer.endObject().close();
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 52 with JsonWriter

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

the class ExportersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter().beginObject().name("exporters").beginArray();
    for (ProfileExporter exporter : exporters) {
        json.beginObject().prop("key", exporter.getKey()).prop("name", exporter.getName());
        json.name("languages").beginArray();
        for (String language : exporter.getSupportedLanguages()) {
            json.value(language);
        }
        json.endArray().endObject();
    }
    json.endArray().endObject().close();
}
Also used : ProfileExporter(org.sonar.api.profiles.ProfileExporter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 53 with JsonWriter

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

the class ImportersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter().beginObject().name("importers").beginArray();
    for (ProfileImporter importer : importers) {
        json.beginObject().prop("key", importer.getKey()).prop("name", importer.getName()).name("languages").beginArray();
        for (String languageKey : importer.getSupportedLanguages()) {
            json.value(languageKey);
        }
        json.endArray().endObject();
    }
    json.endArray().endObject().close();
}
Also used : ProfileImporter(org.sonar.api.profiles.ProfileImporter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 54 with JsonWriter

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

the class ComponentAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String componentKey = request.mandatoryParam(PARAM_COMPONENT_KEY);
    try (DbSession session = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByKey(session, componentKey);
        if (!userSession.hasComponentPermission(USER, component) && !userSession.hasComponentPermission(ADMIN, component) && !userSession.isSystemAdministrator()) {
            throw insufficientPrivilegesException();
        }
        OrganizationDto org = componentFinder.getOrganization(session, component);
        Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.projectUuid());
        JsonWriter json = response.newJsonWriter();
        json.beginObject();
        writeComponent(json, session, component, org, analysis.orElse(null));
        writeProfiles(json, session, component);
        writeQualityGate(json, session, component);
        if (userSession.hasComponentPermission(ADMIN, component) || userSession.hasPermission(ADMINISTER_QUALITY_PROFILES, org) || userSession.hasPermission(ADMINISTER_QUALITY_GATES, org)) {
            writeConfiguration(json, component);
        }
        writeBreadCrumbs(json, session, component);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 55 with JsonWriter

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

the class GlobalAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter().beginObject();
    writePages(json);
    writeSettings(json);
    writeDeprecatedLogoProperties(json);
    writeQualifiers(json);
    writeVersion(json);
    writeDatabaseProduction(json);
    writeOrganizationSupport(json);
    json.endObject().close();
}
Also used : 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