Search in sources :

Example 66 with ComponentDto

use of org.sonar.db.component.ComponentDto 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 67 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class IssueUpdater method saveIssue.

public void saveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, @Nullable String comment) {
    issueStorage.save(session, issue);
    Optional<RuleDto> rule = getRuleByKey(session, issue.getRuleKey());
    ComponentDto project = dbClient.componentDao().selectOrFailByUuid(session, issue.projectUuid());
    notificationService.scheduleForSending(new IssueChangeNotification().setIssue(issue).setChangeAuthorLogin(context.login()).setRuleName(rule.isPresent() ? rule.get().getName() : null).setProject(project.getKey(), project.name()).setComponent(dbClient.componentDao().selectOrFailByUuid(session, issue.componentUuid())).setComment(comment));
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueChangeNotification(org.sonar.server.issue.notification.IssueChangeNotification)

Example 68 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ServerIssueStorage method doInsert.

@Override
protected String doInsert(DbSession session, long now, DefaultIssue issue) {
    ComponentDto component = component(session, issue);
    ComponentDto project = project(session, issue);
    int ruleId = rule(issue).getId();
    IssueDto dto = IssueDto.toDtoForServerInsert(issue, component, project, ruleId, now);
    getDbClient().issueDao().insert(session, dto);
    return dto.getKey();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto)

Example 69 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class DuplicationsJsonWriter method getParentProject.

private ComponentDto getParentProject(String rootUuid, Map<String, ComponentDto> subProjectsByUuid, DbSession session) {
    ComponentDto project = subProjectsByUuid.get(rootUuid);
    if (project == null) {
        Optional<ComponentDto> projectOptional = componentDao.selectByUuid(session, rootUuid);
        if (projectOptional.isPresent()) {
            project = projectOptional.get();
            subProjectsByUuid.put(project.uuid(), project);
        }
    }
    return project;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 70 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class DuplicationsJsonWriter method writeFiles.

private void writeFiles(Map<String, String> refByComponentKey, JsonWriter json, DbSession session) {
    Map<String, ComponentDto> projectsByUuid = newHashMap();
    Map<String, ComponentDto> parentProjectsByUuid = newHashMap();
    for (Map.Entry<String, String> entry : refByComponentKey.entrySet()) {
        String componentKey = entry.getKey();
        String ref = entry.getValue();
        Optional<ComponentDto> fileOptional = componentDao.selectByKey(session, componentKey);
        if (fileOptional.isPresent()) {
            ComponentDto file = fileOptional.get();
            json.name(ref).beginObject();
            addFile(json, file);
            ComponentDto project = getProject(file.projectUuid(), projectsByUuid, session);
            ComponentDto parentProject = getParentProject(file.getRootUuid(), parentProjectsByUuid, session);
            addProject(json, project, parentProject);
            json.endObject();
        }
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13