Search in sources :

Example 11 with JsonWriter

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

the class AvailableAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkIsSystemAdministrator();
    JsonWriter jsonWriter = response.newJsonWriter();
    jsonWriter.beginObject();
    Optional<UpdateCenter> updateCenter = updateCenterFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH);
    writePlugins(jsonWriter, updateCenter);
    pluginWSCommons.writeUpdateCenterProperties(jsonWriter, updateCenter);
    jsonWriter.endObject();
    jsonWriter.close();
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 12 with JsonWriter

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

the class QPMeasureData method toJson.

public static String toJson(QPMeasureData data) {
    StringWriter json = new StringWriter();
    try (JsonWriter writer = JsonWriter.of(json)) {
        writer.beginArray();
        for (QualityProfile profile : data.getProfiles()) {
            writer.beginObject().prop("key", profile.getQpKey()).prop("language", profile.getLanguageKey()).prop("name", profile.getQpName()).prop("rulesUpdatedAt", UtcDateUtils.formatDateTime(profile.getRulesUpdatedAt())).endObject();
        }
        writer.endArray();
    }
    return json.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 13 with JsonWriter

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

the class IndexAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<ComponentDto> projects = getAuthorizedComponents(dbSession, searchComponents(dbSession, request));
        JsonWriter json = response.newJsonWriter();
        json.beginArray();
        for (ComponentDto project : projects) {
            addProject(json, project);
        }
        json.endArray();
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 14 with JsonWriter

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

the class ProvisionedAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    SearchOptions options = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
    Set<String> desiredFields = desiredFields(request);
    String query = request.param(Param.TEXT_QUERY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = support.getOrganization(dbSession, request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
        userSession.checkPermission(PROVISION_PROJECTS, organization);
        RowBounds rowBounds = new RowBounds(options.getOffset(), options.getLimit());
        List<ComponentDto> projects = dbClient.componentDao().selectProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER, rowBounds);
        int nbOfProjects = dbClient.componentDao().countProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER);
        JsonWriter json = response.newJsonWriter().beginObject();
        writeProjects(projects, json, desiredFields);
        options.writeJson(json, nbOfProjects);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) RowBounds(org.apache.ibatis.session.RowBounds) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 15 with JsonWriter

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

the class RenameAction method handle.

@Override
public void handle(Request request, Response response) {
    long idToRename = QualityGatesWs.parseId(request, QualityGatesWsParameters.PARAM_ID);
    QualityGateDto renamedQualityGate = qualityGates.rename(idToRename, request.mandatoryParam(QualityGatesWsParameters.PARAM_NAME));
    JsonWriter writer = response.newJsonWriter();
    QualityGatesWs.writeQualityGate(renamedQualityGate, writer).close();
}
Also used : JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

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