Search in sources :

Example 61 with DbSession

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

the class BulkApplyTemplateAction method doHandle.

private void doHandle(BulkApplyTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        ComponentQuery componentQuery = ComponentQuery.builder().setNameOrKeyQuery(request.getQuery()).setQualifiers(qualifiers(request.getQualifier())).build();
        List<ComponentDto> projects = dbClient.componentDao().selectByQuery(dbSession, template.getOrganizationUuid(), componentQuery, 0, Integer.MAX_VALUE);
        permissionTemplateService.apply(dbSession, template, projects);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) ComponentQuery(org.sonar.db.component.ComponentQuery) ComponentDto(org.sonar.db.component.ComponentDto)

Example 62 with DbSession

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

the class DeleteTemplateAction method doHandle.

private void doHandle(DeleteTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        PermissionTemplateDto template = finder.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        DefaultTemplates defaultTemplates = retrieveDefaultTemplates(dbSession, template);
        checkTemplateUuidIsNotDefault(template, defaultTemplates);
        dbClient.permissionTemplateDao().deleteById(dbSession, template.getId());
        updateViewDefaultTemplateWhenGovernanceIsNotInstalled(dbSession, template, defaultTemplates);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates)

Example 63 with DbSession

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

the class QProfileComparison method compare.

public QProfileComparisonResult compare(String leftKey, String rightKey) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        QProfileComparisonResult result = new QProfileComparisonResult();
        compare(dbSession, leftKey, rightKey, result);
        return result;
    }
}
Also used : DbSession(org.sonar.db.DbSession)

Example 64 with DbSession

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

the class QProfileExporters method wrap.

private RulesProfile wrap(QualityProfileDto profile) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
        List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
        List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleIds(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getId));
        ListMultimap<Integer, ActiveRuleParamDto> activeRuleParamsByActiveRuleId = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleId);
        for (ActiveRuleDto activeRule : activeRuleDtos) {
            // TODO all rules should be loaded by using one query with all active rule keys as parameter
            Rule rule = ruleFinder.findByKey(activeRule.getKey().ruleKey());
            org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
            List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleId.get(activeRule.getId());
            for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
                wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
            }
        }
        return target;
    }
}
Also used : DbSession(org.sonar.db.DbSession) RulesProfile(org.sonar.api.profiles.RulesProfile) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) Rule(org.sonar.api.rules.Rule) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 65 with DbSession

use of org.sonar.db.DbSession 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)

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