Search in sources :

Example 31 with DbSession

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

the class ValidateProjectStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Component root = treeRootHolder.getRoot();
        List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey());
        Map<String, ComponentDto> baseModulesByKey = from(baseModules).uniqueIndex(ComponentDto::key);
        ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
        new DepthTraversalTypeAwareCrawler(visitor).visit(root);
        if (!visitor.validationMessages.isEmpty()) {
            throw MessageException.of("Validation of project failed:\n  o " + MESSAGES_JOINER.join(visitor.validationMessages));
        }
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) ComponentDto(org.sonar.db.component.ComponentDto) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 32 with DbSession

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

the class IssueQueryService method createFromRequest.

public IssueQuery createFromRequest(SearchWsRequest request) {
    DbSession session = dbClient.openSession(false);
    try {
        IssueQuery.Builder builder = IssueQuery.builder().issueKeys(request.getIssues()).severities(request.getSeverities()).statuses(request.getStatuses()).resolutions(request.getResolutions()).resolved(request.getResolved()).rules(stringsToRules(request.getRules())).assignees(buildAssignees(request.getAssignees())).languages(request.getLanguages()).tags(request.getTags()).types(request.getTypes()).assigned(request.getAssigned()).createdAt(parseDateOrDateTime(request.getCreatedAt())).createdBefore(parseEndingDateOrDateTime(request.getCreatedBefore())).facetMode(request.getFacetMode());
        Set<String> allComponentUuids = Sets.newHashSet();
        boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(session, request.getOnComponentOnly(), request.getComponents(), request.getComponentUuids(), request.getComponentKeys(), request.getComponentRootUuids(), request.getComponentRoots(), allComponentUuids);
        addComponentParameters(builder, session, effectiveOnComponentOnly, allComponentUuids, request.getProjectUuids(), request.getProjectKeys(), request.getModuleUuids(), request.getDirectories(), request.getFileUuids(), request.getAuthors());
        builder.createdAfter(buildCreatedAfterFromRequest(session, request, allComponentUuids));
        String sort = request.getSort();
        if (!Strings.isNullOrEmpty(sort)) {
            builder.sort(sort);
            builder.asc(request.getAsc());
        }
        return builder.build();
    } finally {
        session.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession)

Example 33 with DbSession

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

the class IssueStorage method update.

/**
   * @return the keys of the updated issues
   */
private Collection<String> update(List<DefaultIssue> issuesToUpdate, long now) {
    Collection<String> updated = new ArrayList<>();
    if (!issuesToUpdate.isEmpty()) {
        try (DbSession dbSession = dbClient.openSession(false)) {
            IssueChangeMapper issueChangeMapper = dbSession.getMapper(IssueChangeMapper.class);
            for (DefaultIssue issue : issuesToUpdate) {
                String key = doUpdate(dbSession, now, issue);
                updated.add(key);
                insertChanges(issueChangeMapper, issue);
            }
            dbSession.commit();
        }
    }
    return updated;
}
Also used : DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Example 34 with DbSession

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

the class FavoriteFinder method list.

/**
   * @return the list of favorite components of the authenticated user. Empty list if the user is not authenticated
   */
public List<ComponentDto> list() {
    if (!userSession.isLoggedIn()) {
        return emptyList();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        PropertyQuery dbQuery = PropertyQuery.builder().setKey(PROP_FAVORITE_KEY).setUserId(userSession.getUserId()).build();
        Set<Long> componentIds = dbClient.propertiesDao().selectByQuery(dbQuery, dbSession).stream().map(PropertyDto::getResourceId).collect(Collectors.toSet());
        return dbClient.componentDao().selectByIds(dbSession, componentIds).stream().sorted(Comparator.comparing(ComponentDto::name)).collect(toList());
    }
}
Also used : DbSession(org.sonar.db.DbSession) PropertyQuery(org.sonar.db.property.PropertyQuery) ComponentDto(org.sonar.db.component.ComponentDto)

Example 35 with DbSession

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

the class NewIssuesNotification method setStatistics.

public NewIssuesNotification setStatistics(String projectName, NewIssuesStatistics.Stats stats) {
    setDefaultMessage(stats.countForMetric(SEVERITY) + " new issues on " + projectName + ".\n");
    try (DbSession dbSession = dbClient.openSession(false)) {
        setSeverityStatistics(stats);
        setAssigneesStatistics(stats);
        setTagsStatistics(stats);
        setComponentsStatistics(dbSession, stats);
        setRuleStatistics(dbSession, stats);
    }
    return this;
}
Also used : DbSession(org.sonar.db.DbSession)

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