Search in sources :

Example 16 with JsonWriter

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

the class SearchAction method handle.

@Override
public void handle(Request request, Response response) {
    QgateProjectFinder.Association associations = projectFinder.find(ProjectQgateAssociationQuery.builder().gateId(request.mandatoryParam(QualityGatesWsParameters.PARAM_GATE_ID)).membership(request.param(QualityGatesWsParameters.PARAM_QUERY) == null ? request.param(Param.SELECTED) : ProjectQgateAssociationQuery.ANY).projectSearch(request.param(QualityGatesWsParameters.PARAM_QUERY)).pageIndex(request.paramAsInt(QualityGatesWsParameters.PARAM_PAGE)).pageSize(request.paramAsInt(QualityGatesWsParameters.PARAM_PAGE_SIZE)).build());
    JsonWriter writer = response.newJsonWriter();
    writer.beginObject().prop("more", associations.hasMoreResults());
    writer.name("results").beginArray();
    for (ProjectQgateAssociation project : associations.projects()) {
        writer.beginObject().prop("id", project.id()).prop("name", project.name()).prop(Param.SELECTED, project.isMember()).endObject();
    }
    writer.endArray().endObject().close();
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) QgateProjectFinder(org.sonar.server.qualitygate.QgateProjectFinder) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 17 with JsonWriter

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

the class InstalledAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkIsSystemAdministrator();
    Collection<PluginInfo> pluginInfoList = searchPluginInfoList();
    JsonWriter jsonWriter = response.newJsonWriter();
    jsonWriter.setSerializeEmptys(false);
    jsonWriter.beginObject();
    List<String> additionalFields = request.paramAsStrings(WebService.Param.FIELDS);
    writePluginInfoList(jsonWriter, pluginInfoList, additionalFields == null ? Collections.<String>emptyList() : additionalFields);
    jsonWriter.endObject();
    jsonWriter.close();
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 18 with JsonWriter

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

the class CopyAction method handle.

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

Example 19 with JsonWriter

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

the class OldRestoreAction method writeResponse.

private void writeResponse(JsonWriter json, BulkChangeResult result) {
    QualityProfileDto profile = result.profile();
    if (profile != null) {
        String languageKey = profile.getLanguage();
        Language language = languages.get(languageKey);
        JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
        jsonProfile.prop("key", profile.getKey()).prop("name", profile.getName()).prop("language", languageKey).prop("isDefault", false).prop("isInherited", false);
        if (language != null) {
            jsonProfile.prop("languageName", language.getName());
        }
        jsonProfile.endObject();
    }
    json.prop("ruleSuccesses", result.countSucceeded());
    json.prop("ruleFailures", result.countFailed());
    json.endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 20 with JsonWriter

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

the class RestoreAction method writeResponse.

private void writeResponse(JsonWriter json, BulkChangeResult result) {
    QualityProfileDto profile = result.profile();
    if (profile != null) {
        String languageKey = profile.getLanguage();
        Language language = languages.get(languageKey);
        JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
        jsonProfile.prop("key", profile.getKey()).prop("name", profile.getName()).prop("language", languageKey).prop("isDefault", false).prop("isInherited", false);
        if (language != null) {
            jsonProfile.prop("languageName", language.getName());
        }
        jsonProfile.endObject();
    }
    json.prop("ruleSuccesses", result.countSucceeded());
    json.prop("ruleFailures", result.countFailed());
    json.endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

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