Search in sources :

Example 86 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class RemoveProjectAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    RemoveProjectRequest removeProjectRequest = toWsRequest(request);
    try (DbSession dbSession = dbClient.openSession(false)) {
        String profileKey = projectAssociationFinder.getProfileKey(removeProjectRequest.getLanguage(), removeProjectRequest.getProfileName(), removeProjectRequest.getProfileKey());
        ComponentDto project = projectAssociationFinder.getProject(dbSession, removeProjectRequest.getProjectKey(), removeProjectRequest.getProjectUuid());
        profileProjectOperations.removeProject(dbSession, profileKey, project);
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) RemoveProjectRequest(org.sonarqube.ws.client.qualityprofile.RemoveProjectRequest) ComponentDto(org.sonar.db.component.ComponentDto)

Example 87 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class RegisterQualityProfiles method start.

public void start() {
    Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Register quality profiles");
    DbSession session = dbClient.openSession(false);
    try {
        List<ActiveRuleChange> changes = new ArrayList<>();
        ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage();
        for (String language : profilesByLanguage.keySet()) {
            List<RulesProfile> defs = profilesByLanguage.get(language);
            if (verifyLanguage(language, defs)) {
                changes.addAll(registerProfilesForLanguage(session, language, defs));
            }
        }
        activeRuleIndexer.index(changes);
        profiler.stopDebug();
    } finally {
        session.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Profiler(org.sonar.api.utils.log.Profiler) RulesProfile(org.sonar.api.profiles.RulesProfile) ArrayList(java.util.ArrayList)

Example 88 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class RuleActivator method bulkDeactivate.

BulkChangeResult bulkDeactivate(RuleQuery ruleQuery, String profile) {
    DbSession dbSession = db.openSession(false);
    BulkChangeResult result = new BulkChangeResult();
    try {
        Iterator<RuleKey> rules = ruleIndex.searchAll(ruleQuery);
        while (rules.hasNext()) {
            try {
                RuleKey ruleKey = rules.next();
                ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey);
                List<ActiveRuleChange> changes = deactivate(dbSession, key);
                result.addChanges(changes);
                if (!changes.isEmpty()) {
                    result.incrementSucceeded();
                }
            } catch (BadRequestException e) {
                // other exceptions stop the bulk activation
                result.incrementFailed();
                result.getErrors().addAll(e.errors());
            }
        }
        dbSession.commit();
        activeRuleIndexer.index(result.getChanges());
        return result;
    } finally {
        dbSession.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey) BadRequestException(org.sonar.server.exceptions.BadRequestException) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey)

Example 89 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class DeleteAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    qProfileWsSupport.checkQProfileAdminPermission();
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityProfileDto profile = profileFactory.find(dbSession, QProfileRef.from(request));
        profileFactory.delete(dbSession, profile.getKey(), false);
        dbSession.commit();
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 90 with DbSession

use of org.sonar.db.DbSession in project sonarqube by SonarSource.

the class ServerUserSession method componentUuidToProjectUuid.

@Override
protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
    String projectUuid = projectUuidByComponentUuid.get(componentUuid);
    if (projectUuid != null) {
        return Optional.of(projectUuid);
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
        if (!component.isPresent()) {
            return Optional.empty();
        }
        projectUuid = component.get().projectUuid();
        projectUuidByComponentUuid.put(componentUuid, projectUuid);
        return Optional.of(projectUuid);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto)

Aggregations

DbSession (org.sonar.db.DbSession)254 ComponentDto (org.sonar.db.component.ComponentDto)63 OrganizationDto (org.sonar.db.organization.OrganizationDto)30 JsonWriter (org.sonar.api.utils.text.JsonWriter)24 UserDto (org.sonar.db.user.UserDto)20 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)16 Test (org.junit.Test)13 MetricDto (org.sonar.db.metric.MetricDto)13 Paging (org.sonar.api.utils.Paging)12 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)10 CeQueueDto (org.sonar.db.ce.CeQueueDto)8 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)8 SearchOptions (org.sonar.server.es.SearchOptions)8 NotFoundException (org.sonar.server.exceptions.NotFoundException)8 List (java.util.List)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 GroupDto (org.sonar.db.user.GroupDto)7 DbClient (org.sonar.db.DbClient)6 ProjectId (org.sonar.server.permission.ProjectId)6 RuleKey (org.sonar.api.rule.RuleKey)5