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