use of org.sonar.server.issue.index.IssueDoc 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.issue.index.IssueDoc in project sonarqube by SonarSource.
the class EsUtilsTest method convertToDocs.
@Test
public void convertToDocs() {
SearchHits hits = new SearchHits(new SearchHit[] { new SearchHit(16) }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1);
List<BaseDoc> docs = EsUtils.convertToDocs(hits, IssueDoc::new);
assertThat(docs).hasSize(1);
}
use of org.sonar.server.issue.index.IssueDoc in project sonarqube by SonarSource.
the class IssueDocTesting method newDoc.
public static IssueDoc newDoc() {
IssueDoc doc = new IssueDoc(new HashMap<>());
doc.setKey(Uuids.createFast());
doc.setRuleUuid(Uuids.createFast());
doc.setType(RuleType.CODE_SMELL);
doc.setAssigneeUuid("assignee_uuid_" + randomAlphabetic(26));
doc.setAuthorLogin("author_" + randomAlphabetic(5));
doc.setScope(IssueScope.MAIN);
doc.setLanguage("language_" + randomAlphabetic(5));
doc.setComponentUuid(Uuids.createFast());
doc.setFilePath("filePath_" + randomAlphabetic(5));
doc.setDirectoryPath("directory_" + randomAlphabetic(5));
doc.setModuleUuid(Uuids.createFast());
doc.setModuleUuidPath(Uuids.createFast());
doc.setProjectUuid(Uuids.createFast());
doc.setLine(nextInt(1_000) + 1);
doc.setStatus(STATUS_OPEN);
doc.setResolution(null);
doc.setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size())));
doc.setEffort((long) nextInt(10));
doc.setFuncCreationDate(new Date(System.currentTimeMillis() - 2_000));
doc.setFuncUpdateDate(new Date(System.currentTimeMillis() - 1_000));
doc.setFuncCloseDate(null);
return doc;
}
use of org.sonar.server.issue.index.IssueDoc in project sonarqube by SonarSource.
the class ViewIndexerTest method clear_views_lookup_cache_on_index_view_uuid.
@Test
public void clear_views_lookup_cache_on_index_view_uuid() {
IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
String viewUuid = "ABCD";
RuleDto rule = RuleTesting.newXooX1();
dbClient.ruleDao().insert(dbSession, rule);
ComponentDto project1 = addProjectWithIssue(rule, dbTester.organizations().insert());
issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
permissionIndexer.indexProjectsByUuids(dbSession, asList(project1.uuid()));
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto view = ComponentTesting.newView(organizationDto, "ABCD");
ComponentDto techProject1 = ComponentTesting.newProjectCopy("CDEF", project1, view);
dbClient.componentDao().insert(dbSession, view, techProject1);
dbSession.commit();
// First view indexation
underTest.index(viewUuid);
// Execute issue query on view -> 1 issue on view
SearchResult<IssueDoc> docs = issueIndex.search(IssueQuery.builder().viewUuids(newArrayList(viewUuid)).build(), new SearchOptions());
assertThat(docs.getDocs()).hasSize(1);
// Add a project to the view and index it again
ComponentDto project2 = addProjectWithIssue(rule, organizationDto);
issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
permissionIndexer.indexProjectsByUuids(dbSession, asList(project2.uuid()));
ComponentDto techProject2 = ComponentTesting.newProjectCopy("EFGH", project2, view);
dbClient.componentDao().insert(dbSession, techProject2);
dbSession.commit();
underTest.index(viewUuid);
// Execute issue query on view -> issue of project2 are well taken into account : the cache has been cleared
assertThat(issueIndex.search(IssueQuery.builder().viewUuids(newArrayList(viewUuid)).build(), new SearchOptions()).getDocs()).hasSize(2);
}
use of org.sonar.server.issue.index.IssueDoc in project sonarqube by SonarSource.
the class EsUtilsTest method convertToDocs_empty.
@Test
public void convertToDocs_empty() {
SearchHits hits = new SearchHits(new SearchHit[] {}, new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0);
List<BaseDoc> docs = EsUtils.convertToDocs(hits, IssueDoc::new);
assertThat(docs).isEmpty();
}
Aggregations