Search in sources :

Example 1 with IssueDoc

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);
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) Facets(org.sonar.server.es.Facets) Paging(org.sonar.api.utils.Paging) SearchOptions(org.sonar.server.es.SearchOptions) IssueQuery(org.sonar.server.issue.IssueQuery)

Example 2 with IssueDoc

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);
}
Also used : TotalHits(org.apache.lucene.search.TotalHits) IssueDoc(org.sonar.server.issue.index.IssueDoc) SearchHit(org.elasticsearch.search.SearchHit) SearchHits(org.elasticsearch.search.SearchHits) Test(org.junit.Test)

Example 3 with IssueDoc

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;
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) Date(java.util.Date)

Example 4 with IssueDoc

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);
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) RuleDto(org.sonar.db.rule.RuleDto) IssueIndex(org.sonar.server.issue.index.IssueIndex) ComponentDto(org.sonar.db.component.ComponentDto) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) SearchOptions(org.sonar.server.es.SearchOptions) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 5 with IssueDoc

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();
}
Also used : TotalHits(org.apache.lucene.search.TotalHits) IssueDoc(org.sonar.server.issue.index.IssueDoc) SearchHits(org.elasticsearch.search.SearchHits) Test(org.junit.Test)

Aggregations

IssueDoc (org.sonar.server.issue.index.IssueDoc)5 Test (org.junit.Test)3 TotalHits (org.apache.lucene.search.TotalHits)2 SearchHits (org.elasticsearch.search.SearchHits)2 SearchOptions (org.sonar.server.es.SearchOptions)2 Date (java.util.Date)1 SearchHit (org.elasticsearch.search.SearchHit)1 Paging (org.sonar.api.utils.Paging)1 ComponentDto (org.sonar.db.component.ComponentDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 Facets (org.sonar.server.es.Facets)1 IssueQuery (org.sonar.server.issue.IssueQuery)1 IssueIndex (org.sonar.server.issue.index.IssueIndex)1 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)1 IssueIteratorFactory (org.sonar.server.issue.index.IssueIteratorFactory)1 AuthorizationTypeSupport (org.sonar.server.permission.index.AuthorizationTypeSupport)1