Search in sources :

Example 71 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class GhostsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
    Set<String> desiredFields = fieldsToReturn(request.paramAsStrings(Param.FIELDS));
    String query = request.param(Param.TEXT_QUERY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = getOrganization(dbSession, request);
        userSession.checkPermission(ADMINISTER, organization);
        long nbOfProjects = dbClient.componentDao().countGhostProjects(dbSession, organization.getUuid(), query);
        List<ComponentDto> projects = dbClient.componentDao().selectGhostProjects(dbSession, organization.getUuid(), query, searchOptions.getOffset(), searchOptions.getLimit());
        JsonWriter json = response.newJsonWriter().beginObject();
        writeProjects(json, projects, desiredFields);
        searchOptions.writeJson(json, nbOfProjects);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 72 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class SearchAction method buildSearchOptions.

protected SearchOptions buildSearchOptions(SearchWsRequest request) {
    SearchOptions context = loadCommonContext(request);
    SearchOptions searchOptions = new SearchOptions().setLimit(context.getLimit()).setOffset(context.getOffset());
    if (context.getFacets().contains(RuleIndex.FACET_OLD_DEFAULT)) {
        searchOptions.addFacets(DEFAULT_FACETS);
    } else {
        searchOptions.addFacets(context.getFacets());
    }
    return searchOptions;
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions)

Example 73 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class SearchAction method loadCommonContext.

private static SearchOptions loadCommonContext(SearchWsRequest request) {
    int pageSize = request.getPageSize();
    SearchOptions context = new SearchOptions().addFields(request.getFields());
    if (request.getFacets() != null) {
        context.addFacets(request.getFacets());
    }
    if (pageSize < 1) {
        context.setPage(request.getPage(), 0).setLimit(MAX_LIMIT);
    } else {
        context.setPage(request.getPage(), pageSize);
    }
    return context;
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions)

Example 74 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class ListAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String testUuid = request.param(TEST_ID);
    String testFileUuid = request.param(TEST_FILE_ID);
    String testFileKey = request.param(TEST_FILE_KEY);
    String sourceFileUuid = request.param(SOURCE_FILE_ID);
    String sourceFileKey = request.param(SOURCE_FILE_KEY);
    Integer sourceFileLineNumber = request.paramAsInt(SOURCE_FILE_LINE_NUMBER);
    SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(WebService.Param.PAGE), request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
    SearchResult<TestDoc> tests;
    Map<String, ComponentDto> componentsByTestFileUuid;
    try (DbSession dbSession = dbClient.openSession(false)) {
        tests = searchTests(dbSession, testUuid, testFileUuid, testFileKey, sourceFileUuid, sourceFileKey, sourceFileLineNumber, searchOptions);
        componentsByTestFileUuid = buildComponentsByTestFileUuid(dbSession, tests.getDocs());
    }
    WsTests.ListResponse.Builder responseBuilder = WsTests.ListResponse.newBuilder();
    responseBuilder.setPaging(Common.Paging.newBuilder().setPageIndex(searchOptions.getPage()).setPageSize(searchOptions.getLimit()).setTotal((int) tests.getTotal()).build());
    for (TestDoc testDoc : tests.getDocs()) {
        WsTests.Test.Builder testBuilder = WsTests.Test.newBuilder();
        testBuilder.setId(testDoc.testUuid());
        testBuilder.setName(StringUtils.defaultString(testDoc.name()));
        testBuilder.setFileId(testDoc.fileUuid());
        ComponentDto component = componentsByTestFileUuid.get(testDoc.fileUuid());
        if (component != null) {
            testBuilder.setFileKey(component.getKey());
            testBuilder.setFileName(component.longName());
        }
        testBuilder.setStatus(WsTests.TestStatus.valueOf(testDoc.status()));
        if (testDoc.durationInMs() != null) {
            testBuilder.setDurationInMs(testDoc.durationInMs());
        }
        testBuilder.setCoveredLines(coveredLines(testDoc.coveredFiles()));
        if (testDoc.message() != null) {
            testBuilder.setMessage(testDoc.message());
        }
        if (testDoc.stackTrace() != null) {
            testBuilder.setStacktrace(testDoc.stackTrace());
        }
        responseBuilder.addTests(testBuilder.build());
    }
    WsUtils.writeProtobuf(responseBuilder.build(), request, response);
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) TestDoc(org.sonar.server.test.index.TestDoc) SearchOptions(org.sonar.server.es.SearchOptions)

Example 75 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class IssueIndexDebtTest method fixtureForCreatedAtFacet.

protected SearchOptions fixtureForCreatedAtFacet() {
    ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto());
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setFuncCreationDate(DateUtils.parseDateTime("2011-04-25T01:05:13+0100"));
    IssueDoc issue1 = IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(DateUtils.parseDateTime("2014-09-01T12:34:56+0100"));
    IssueDoc issue2 = IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(DateUtils.parseDateTime("2014-09-01T23:46:00+0100"));
    IssueDoc issue3 = IssueDocTesting.newDoc("ISSUE3", file).setFuncCreationDate(DateUtils.parseDateTime("2014-09-02T12:34:56+0100"));
    IssueDoc issue4 = IssueDocTesting.newDoc("ISSUE4", file).setFuncCreationDate(DateUtils.parseDateTime("2014-09-05T12:34:56+0100"));
    IssueDoc issue5 = IssueDocTesting.newDoc("ISSUE5", file).setFuncCreationDate(DateUtils.parseDateTime("2014-09-20T12:34:56+0100"));
    IssueDoc issue6 = IssueDocTesting.newDoc("ISSUE6", file).setFuncCreationDate(DateUtils.parseDateTime("2015-01-18T12:34:56+0100"));
    indexIssues(issue0, issue1, issue2, issue3, issue4, issue5, issue6);
    return new SearchOptions().addFacets("createdAt");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions)

Aggregations

SearchOptions (org.sonar.server.es.SearchOptions)143 Test (org.junit.Test)127 ComponentDto (org.sonar.db.component.ComponentDto)62 Facets (org.sonar.server.es.Facets)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 RuleDto (org.sonar.db.rule.RuleDto)16 RuleKey (org.sonar.api.rule.RuleKey)14 OrganizationDto (org.sonar.db.organization.OrganizationDto)11 IssueQuery (org.sonar.server.issue.IssueQuery)11 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)10 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)9 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)9 SearchIdResult (org.sonar.server.es.SearchIdResult)9 DbSession (org.sonar.db.DbSession)8 OrganizationTesting.newOrganizationDto (org.sonar.db.organization.OrganizationTesting.newOrganizationDto)7 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)5 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 UserDto (org.sonar.db.user.UserDto)3