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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations