Search in sources :

Example 1 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery 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 ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method fail_when_metric_is_disabled.

@Test
public void fail_when_metric_is_disabled() throws Exception {
    insertMetric(createValidMetric("ncloc").setEnabled(false));
    insertMetric(createValidMetric("debt").setEnabled(false));
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d)).setSort("debt");
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Following metrics are disabled : [debt, ncloc]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 3 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method fail_when_metric_are_not_numeric.

@Test
public void fail_when_metric_are_not_numeric() throws Exception {
    insertMetric(createValidMetric("ncloc").setValueType(INT.name()));
    insertMetric(createValidMetric("debt").setValueType(WORK_DUR.name()));
    insertMetric(createValidMetric("data").setValueType(DATA.name()));
    insertMetric(createValidMetric("distrib").setValueType(DISTRIB.name()));
    insertMetric(createValidMetric("string").setValueType(STRING.name()));
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("data", GT, 10d)).addMetricCriterion(new MetricCriterion("distrib", EQ, 11d)).addMetricCriterion(new MetricCriterion("ncloc", LTE, 20d)).addMetricCriterion(new MetricCriterion("debt", LT, 20d)).addMetricCriterion(new MetricCriterion("string", EQ, 40d));
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Following metrics are not numeric : [data, distrib, string]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 4 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method does_not_fail_when_sort_contains_an_existing_metric.

@Test
public void does_not_fail_when_sort_contains_an_existing_metric() throws Exception {
    insertValidMetric("ncloc");
    insertValidMetric("debt");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d)).setSort("debt");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Example 5 with ProjectMeasuresQuery

use of org.sonar.server.measure.index.ProjectMeasuresQuery in project sonarqube by SonarSource.

the class ProjectMeasuresQueryValidatorTest method fail_when_metric_does_not_exists.

@Test
public void fail_when_metric_does_not_exists() throws Exception {
    insertValidMetric("ncloc");
    ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("unknown", GT, 10d)).setSort("debt");
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Unknown metric(s) [debt, unknown]");
    underTest.validate(dbSession, query);
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) ProjectMeasuresQuery(org.sonar.server.measure.index.ProjectMeasuresQuery) Test(org.junit.Test)

Aggregations

ProjectMeasuresQuery (org.sonar.server.measure.index.ProjectMeasuresQuery)29 Test (org.junit.Test)25 ProjectMeasuresQueryFactory.newProjectMeasuresQuery (org.sonar.server.component.ws.ProjectMeasuresQueryFactory.newProjectMeasuresQuery)20 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)12 Criterion (org.sonar.server.component.ws.FilterParser.Criterion)7 SnapshotDto (org.sonar.db.component.SnapshotDto)2 SearchOptions (org.sonar.server.es.SearchOptions)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 HashSet (java.util.HashSet)1 ComponentDto (org.sonar.db.component.ComponentDto)1 ProjectDto (org.sonar.db.project.ProjectDto)1