Search in sources :

Example 56 with ComponentDto

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

the class SearchAction method doHandle.

private SearchWsResponse doHandle(SearchWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentQuery query = buildQuery(request);
        OrganizationDto organization = getOrganization(dbSession, request);
        Paging paging = buildPaging(dbSession, request, organization, query);
        List<ComponentDto> components = searchComponents(dbSession, organization, query, paging);
        return buildResponse(components, organization, paging);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentQuery(org.sonar.db.component.ComponentQuery) Paging(org.sonar.api.utils.Paging) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 57 with ComponentDto

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

the class SearchProjectsAction method searchData.

private SearchResults searchData(DbSession dbSession, SearchProjectsRequest request, @Nullable OrganizationDto organization) {
    Set<String> favoriteProjectUuids = loadFavoriteProjectUuids(dbSession);
    List<Criterion> criteria = FilterParser.parse(firstNonNull(request.getFilter(), ""));
    ProjectMeasuresQuery query = newProjectMeasuresQuery(criteria, hasFavoriteFilter(criteria) ? favoriteProjectUuids : null).setSort(request.getSort()).setAsc(request.getAsc());
    Optional.ofNullable(organization).map(OrganizationDto::getUuid).ifPresent(query::setOrganizationUuid);
    queryValidator.validate(dbSession, query);
    SearchIdResult<String> esResults = index.search(query, new SearchOptions().addFacets(request.getFacets()).setPage(request.getPage(), request.getPageSize()));
    List<String> projectUuids = esResults.getIds();
    Ordering<ComponentDto> ordering = Ordering.explicit(projectUuids).onResultOf(ComponentDto::uuid);
    List<ComponentDto> projects = ordering.immutableSortedCopy(dbClient.componentDao().selectByUuids(dbSession, projectUuids));
    Map<String, SnapshotDto> analysisByProjectUuid = getSnapshots(dbSession, request, projectUuids);
    return new SearchResults(projects, favoriteProjectUuids, esResults, analysisByProjectUuid, query);
}
Also used : ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Criterion(org.sonar.server.component.ws.FilterParser.Criterion)

Example 58 with ComponentDto

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

the class LoadPeriodsStep method buildPeriod.

@CheckForNull
private Period buildPeriod(Component projectOrView, DbSession session) {
    Optional<ComponentDto> projectDto = dbClient.componentDao().selectByKey(session, projectOrView.getKey());
    // No project on first analysis, no period
    if (!projectDto.isPresent()) {
        return null;
    }
    boolean isReportType = projectOrView.getType().isReportType();
    PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(), isReportType ? projectOrView.getReportAttributes().getVersion() : null);
    Settings settings = settingsRepository.getSettings(projectOrView);
    Period period = periodResolver.resolve(settings);
    // SONAR-4700 Add a past snapshot only if it exists
    if (period != null) {
        return period;
    }
    return null;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Settings(org.sonar.api.config.Settings) CheckForNull(javax.annotation.CheckForNull)

Example 59 with ComponentDto

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

the class PersistComponentsStep method createForSubView.

private ComponentDto createForSubView(Component subView, PathAwareVisitor.Path<ComponentDtoHolder> path) {
    ComponentDto res = createBase(subView);
    res.setScope(Scopes.PROJECT);
    res.setQualifier(Qualifiers.SUBVIEW);
    res.setName(subView.getName());
    res.setDescription(subView.getDescription());
    res.setLongName(res.name());
    res.setCopyComponentUuid(subView.getSubViewAttributes().getOriginalViewUuid());
    setRootAndParentModule(res, path);
    return res;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 60 with ComponentDto

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

the class PersistComponentsStep method createBase.

private ComponentDto createBase(Component component) {
    String componentKey = component.getKey();
    String componentUuid = component.getUuid();
    ComponentDto componentDto = new ComponentDto();
    componentDto.setOrganizationUuid(analysisMetadataHolder.getOrganization().getUuid());
    componentDto.setUuid(componentUuid);
    componentDto.setKey(componentKey);
    componentDto.setDeprecatedKey(componentKey);
    componentDto.setEnabled(true);
    componentDto.setCreatedAt(new Date(system2.now()));
    return componentDto;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date)

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