Search in sources :

Example 1 with Criterion

use of org.sonar.server.component.ws.FilterParser.Criterion 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 2 with Criterion

use of org.sonar.server.component.ws.FilterParser.Criterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryFactoryTest method create_query.

@Test
public void create_query() throws Exception {
    List<Criterion> criteria = asList(Criterion.builder().setKey("ncloc").setOperator(GT).setValue("10").build(), Criterion.builder().setKey("coverage").setOperator(LTE).setValue("80").build());
    ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet());
    assertThat(underTest.getMetricCriteria()).extracting(MetricCriterion::getMetricKey, MetricCriterion::getOperator, MetricCriterion::getValue).containsOnly(tuple("ncloc", GT, 10d), tuple("coverage", Operator.LTE, 80d));
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Criterion(org.sonar.server.component.ws.FilterParser.Criterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) Test(org.junit.Test)

Example 3 with Criterion

use of org.sonar.server.component.ws.FilterParser.Criterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryFactoryTest method create_query_having_q_ignore_case_sensitive.

@Test
public void create_query_having_q_ignore_case_sensitive() throws Exception {
    List<Criterion> criteria = singletonList(Criterion.builder().setKey("query").setOperator(EQ).setValue("Sonar Qube").build());
    ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet());
    assertThat(underTest.getQueryText().get()).isEqualTo("Sonar Qube");
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Criterion(org.sonar.server.component.ws.FilterParser.Criterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) Test(org.junit.Test)

Example 4 with Criterion

use of org.sonar.server.component.ws.FilterParser.Criterion in project sonarqube by SonarSource.

the class ProjectMeasuresQueryFactoryTest method create_query_having_q.

@Test
public void create_query_having_q() throws Exception {
    List<Criterion> criteria = singletonList(Criterion.builder().setKey("query").setOperator(EQ).setValue("Sonar Qube").build());
    ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet());
    assertThat(underTest.getQueryText().get()).isEqualTo("Sonar Qube");
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Criterion(org.sonar.server.component.ws.FilterParser.Criterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) ProjectMeasuresQueryFactory.newProjectMeasuresQuery(org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery) Test(org.junit.Test)

Aggregations

Criterion (org.sonar.server.component.ws.FilterParser.Criterion)4 ProjectMeasuresQueryFactory.newProjectMeasuresQuery (org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery)4 ProjectMeasuresQuery (org.sonar.server.measure.index.ProjectMeasuresQuery)4 Test (org.junit.Test)3 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)3 ComponentDto (org.sonar.db.component.ComponentDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 SearchOptions (org.sonar.server.es.SearchOptions)1