use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchWsRequest request, Request wsRequest) {
// prepare the Elasticsearch request
SearchOptions options = createSearchOptionsFromRequest(request);
EnumSet<SearchAdditionalField> additionalFields = SearchAdditionalField.getFromRequest(request);
IssueQuery query = issueQueryService.createFromRequest(request);
// execute request
SearchResult<IssueDoc> result = issueIndex.search(query, options);
List<String> issueKeys = from(result.getDocs()).transform(IssueDocToKey.INSTANCE).toList();
// load the additional information to be returned in response
SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(additionalFields, issueKeys);
collectLoggedInUser(collector);
collectRequestParams(collector, request);
Facets facets = null;
if (!options.getFacets().isEmpty()) {
facets = result.getFacets();
// add missing values to facets. For example if assignee "john" and facet on "assignees" are requested, then
// "john" should always be listed in the facet. If it is not present, then it is added with value zero.
// This is a constraint from webapp UX.
completeFacets(facets, request, wsRequest);
collectFacets(collector, facets);
}
SearchResponseData data = searchResponseLoader.load(collector, facets);
// format response
// Filter and reorder facets according to the requested ordered names.
// Must be done after loading of data as the "hidden" facet "debt"
// can be used to get total debt.
facets = reorderFacets(facets, options.getFacets());
// FIXME allow long in Paging
Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) result.getTotal());
return searchResponseFormat.formatSearch(additionalFields, data, paging, facets);
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_reliability_rating.
@Test
public void facet_reliability_rating() {
index(// 3 docs with rating A
newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), // 2 docs with rating B
newDoc(RELIABILITY_RATING, 2d), newDoc(RELIABILITY_RATING, 2d), // 4 docs with rating C
newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), // 2 docs with rating D
newDoc(RELIABILITY_RATING, 4d), newDoc(RELIABILITY_RATING, 4d), // 5 docs with rating E
newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(RELIABILITY_RATING)).getFacets();
assertThat(facets.get(RELIABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_security_rating.
@Test
public void facet_security_rating() {
index(// 3 docs with rating A
newDoc(SECURITY_RATING, 1.0d), newDoc(SECURITY_RATING, 1.0d), newDoc(SECURITY_RATING, 1.0d), // 2 docs with rating B
newDoc(SECURITY_RATING, 2.0d), newDoc(SECURITY_RATING, 2.0d), // 4 docs with rating C
newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), // 2 docs with rating D
newDoc(SECURITY_RATING, 4.0d), newDoc(SECURITY_RATING, 4.0d), // 5 docs with rating E
newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_RATING)).getFacets();
assertThat(facets.get(SECURITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_maintainability_rating_contains_only_projects_authorized_for_user.
@Test
public void facet_maintainability_rating_contains_only_projects_authorized_for_user() throws Exception {
// User can see these projects
indexForUser(USER1, // 3 docs with rating A
newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), // 2 docs with rating B
newDoc(MAINTAINABILITY_RATING, 2d), newDoc(MAINTAINABILITY_RATING, 2d));
// User cannot see these projects
indexForUser(USER2, // docs with rating C
newDoc(MAINTAINABILITY_RATING, 3d), // docs with rating D
newDoc(MAINTAINABILITY_RATING, 4d), // docs with rating E
newDoc(MAINTAINABILITY_RATING, 5d));
userSession.logIn(USER1);
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 0L), entry("4", 0L), entry("5", 0L));
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_maintainability_rating.
@Test
public void facet_maintainability_rating() {
index(// 3 docs with rating A
newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), // 2 docs with rating B
newDoc(MAINTAINABILITY_RATING, 2d), newDoc(MAINTAINABILITY_RATING, 2d), // 4 docs with rating C
newDoc(MAINTAINABILITY_RATING, 3d), newDoc(MAINTAINABILITY_RATING, 3d), newDoc(MAINTAINABILITY_RATING, 3d), newDoc(MAINTAINABILITY_RATING, 3d), // 2 docs with rating D
newDoc(MAINTAINABILITY_RATING, 4d), newDoc(MAINTAINABILITY_RATING, 4d), // 5 docs with rating E
newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
Aggregations