Search in sources :

Example 21 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddGroupAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE));
        wsSupport.checkCanEdit(dbSession, profile);
        GroupDto user = wsSupport.getGroup(dbSession, request.mandatoryParam(PARAM_GROUP));
        addGroup(dbSession, profile, user);
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) GroupDto(org.sonar.db.user.GroupDto)

Example 22 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class AddUserAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, request.mandatoryParam(PARAM_QUALITY_PROFILE), request.mandatoryParam(PARAM_LANGUAGE));
        wsSupport.checkCanEdit(dbSession, profile);
        UserDto user = wsSupport.getUser(dbSession, request.mandatoryParam(PARAM_LOGIN));
        addUser(dbSession, profile, user);
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto)

Example 23 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class RestoreAction method writeResponse.

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

Example 24 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class ChangelogAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    QProfileReference reference = QProfileReference.fromName(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, reference);
        QProfileChangeQuery query = new QProfileChangeQuery(profile.getKee());
        Date since = parseStartingDateOrDateTime(request.param(PARAM_SINCE));
        if (since != null) {
            query.setFromIncluded(since.getTime());
        }
        Date to = parseEndingDateOrDateTime(request.param(PARAM_TO));
        if (to != null) {
            query.setToExcluded(to.getTime());
        }
        int page = request.mandatoryParamAsInt(Param.PAGE);
        int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
        query.setPage(page, pageSize);
        int total = dbClient.qProfileChangeDao().countByQuery(dbSession, query);
        List<Change> changelogs = load(dbSession, query);
        Map<String, UserDto> usersByUuid = getUsersByUserUuid(dbSession, changelogs);
        Map<String, RuleDefinitionDto> rulesByRuleIds = getRulesByRuleUuids(dbSession, changelogs);
        writeResponse(response.newJsonWriter(), total, page, pageSize, changelogs, usersByUuid, rulesByRuleIds);
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) QProfileChangeQuery(org.sonar.db.qualityprofile.QProfileChangeQuery) Date(java.util.Date) DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Example 25 with QProfileDto

use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.

the class DeleteAction method handle.

@Override
public void handle(Request request, Response response) {
    userSession.checkLoggedIn();
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromName(request));
        wsSupport.checkCanEdit(dbSession, profile);
        Collection<QProfileDto> descendants = selectDescendants(dbSession, profile);
        ensureNoneIsMarkedAsDefault(dbSession, profile, descendants);
        profileFactory.delete(dbSession, merge(profile, descendants));
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) QProfileDto(org.sonar.db.qualityprofile.QProfileDto)

Aggregations

QProfileDto (org.sonar.db.qualityprofile.QProfileDto)389 Test (org.junit.Test)329 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)139 UserDto (org.sonar.db.user.UserDto)72 DbSession (org.sonar.db.DbSession)38 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)38 ProjectDto (org.sonar.db.project.ProjectDto)36 RuleParamDto (org.sonar.db.rule.RuleParamDto)36 GroupDto (org.sonar.db.user.GroupDto)35 NotFoundException (org.sonar.server.exceptions.NotFoundException)31 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)23 TestRequest (org.sonar.server.ws.TestRequest)23 System2 (org.sonar.api.utils.System2)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)21 DbTester (org.sonar.db.DbTester)21 BadRequestException (org.sonar.server.exceptions.BadRequestException)20 UserSessionRule (org.sonar.server.tester.UserSessionRule)20 List (java.util.List)19 Rule (org.junit.Rule)19