Search in sources :

Example 21 with DbSession

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

the class LoadReportAnalysisMetadataHolderStep method toOrganization.

private Organization toOrganization(String organizationUuid) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
        checkState(organizationDto.isPresent(), "Organization with uuid '{}' can't be found", organizationUuid);
        return Organization.from(organizationDto.get());
    }
}
Also used : DbSession(org.sonar.db.DbSession) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 22 with DbSession

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

the class FileMoveDetectionStep method computeScoreMatrix.

private ScoreMatrix computeScoreMatrix(Map<String, DbComponent> dtosByKey, Set<String> dbFileKeys, Map<String, File> reportFileSourcesByKey) {
    int[][] scoreMatrix = new int[dbFileKeys.size()][reportFileSourcesByKey.size()];
    int maxScore = 0;
    try (DbSession dbSession = dbClient.openSession(false)) {
        int dbFileIndex = 0;
        for (String removedFileKey : dbFileKeys) {
            File fileInDb = getFile(dbSession, dtosByKey.get(removedFileKey));
            if (fileInDb == null) {
                continue;
            }
            int reportFileIndex = 0;
            for (Map.Entry<String, File> reportFileSourceAndKey : reportFileSourcesByKey.entrySet()) {
                File unmatchedFile = reportFileSourceAndKey.getValue();
                int score = fileSimilarity.score(fileInDb, unmatchedFile);
                scoreMatrix[dbFileIndex][reportFileIndex] = score;
                if (score > maxScore) {
                    maxScore = score;
                }
                reportFileIndex++;
            }
            dbFileIndex++;
        }
    }
    return new ScoreMatrix(dbFileKeys, reportFileSourcesByKey, scoreMatrix, maxScore);
}
Also used : DbSession(org.sonar.db.DbSession) File(org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 23 with DbSession

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

the class BuildComponentTreeStep method execute.

@Override
public void execute() {
    String branch = analysisMetadataHolder.getBranch();
    ScannerReport.Component reportProject = reportReader.readComponent(analysisMetadataHolder.getRootComponentRef());
    String projectKey = createKey(reportProject.getKey(), branch);
    UuidFactory uuidFactory = new UuidFactory(dbClient, projectKey);
    try (DbSession dbSession = dbClient.openSession(false)) {
        BaseAnalysisSupplier baseAnalysisSupplier = new BaseAnalysisSupplier(dbClient, dbSession);
        ComponentRootBuilder rootBuilder = new ComponentRootBuilder(branch, uuidFactory::getOrCreateForKey, reportReader::readComponent, () -> dbClient.componentDao().selectByKey(dbSession, projectKey), baseAnalysisSupplier);
        Component project = rootBuilder.build(reportProject, projectKey);
        treeRootHolder.setRoot(project);
        analysisMetadataHolder.setBaseAnalysis(toAnalysis(baseAnalysisSupplier.apply(project.getUuid())));
    }
}
Also used : DbSession(org.sonar.db.DbSession) UuidFactory(org.sonar.server.computation.task.projectanalysis.component.UuidFactory) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) ComponentRootBuilder(org.sonar.server.computation.task.projectanalysis.component.ComponentRootBuilder) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 24 with DbSession

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

the class ComputeMeasureVariationsStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<Metric> metrics = StreamSupport.stream(metricRepository.getAll().spliterator(), false).filter(isNumeric()).collect(Collectors.toList());
        new DepthTraversalTypeAwareCrawler(new VariationMeasuresVisitor(dbSession, metrics)).visit(treeRootHolder.getRoot());
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Example 25 with DbSession

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

the class NewEffortAggregator method beforeComponent.

@Override
public void beforeComponent(Component component) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<IssueChangeDto> changes = dbClient.issueChangeDao().selectChangelogOfNonClosedIssuesByComponent(dbSession, component.getUuid());
        for (IssueChangeDto change : changes) {
            changesByIssueUuid.put(change.getIssueKey(), change);
        }
    }
    counter = new NewEffortCounter(calculator);
    counterByComponentRef.put(component.getReportAttributes().getRef(), counter);
    for (Component child : component.getChildren()) {
        NewEffortCounter childSum = counterByComponentRef.remove(child.getReportAttributes().getRef());
        if (childSum != null) {
            counter.add(childSum);
        }
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) DbSession(org.sonar.db.DbSession) Component(org.sonar.server.computation.task.projectanalysis.component.Component)

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