use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class SearchProjectsAction method searchData.
private SearchResults searchData(DbSession dbSession, SearchProjectsRequest request, @Nullable OrganizationDto organization) {
Set<String> favoriteProjectUuids = loadFavoriteProjectUuids(dbSession);
List<Criterion> criteria = FilterParser.parse(firstNonNull(request.getFilter(), ""));
ProjectMeasuresQuery query = newProjectMeasuresQuery(criteria, hasFavoriteFilter(criteria) ? favoriteProjectUuids : null).setSort(request.getSort()).setAsc(request.getAsc());
Optional.ofNullable(organization).map(OrganizationDto::getUuid).ifPresent(query::setOrganizationUuid);
queryValidator.validate(dbSession, query);
SearchIdResult<String> esResults = index.search(query, new SearchOptions().addFacets(request.getFacets()).setPage(request.getPage(), request.getPageSize()));
List<String> projectUuids = esResults.getIds();
Ordering<ComponentDto> ordering = Ordering.explicit(projectUuids).onResultOf(ComponentDto::uuid);
List<ComponentDto> projects = ordering.immutableSortedCopy(dbClient.componentDao().selectByUuids(dbSession, projectUuids));
Map<String, SnapshotDto> analysisByProjectUuid = getSnapshots(dbSession, request, projectUuids);
return new SearchResults(projects, favoriteProjectUuids, esResults, analysisByProjectUuid, query);
}
use of org.sonar.server.es.SearchOptions 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.SearchOptions in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectUuid = request.param(PARAM_PROJECT_ID);
String projectKey = request.param(PARAM_PROJECT_KEY);
List<String> fieldsToReturn = request.paramAsStrings(WebService.Param.FIELDS);
SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(WebService.Param.PAGE), request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_ID_AND_KEY);
checkPermissions(userSession, component);
Long lastAnalysisDateMs = searchLastSnapshotDate(dbSession, component);
List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, component, searchOptions);
int nbCustomMeasures = countTotalOfCustomMeasures(dbSession, component);
Map<String, UserDto> usersByLogin = usersByLogin(dbSession, customMeasures);
Map<Integer, MetricDto> metricsById = metricsById(dbSession, customMeasures);
writeResponse(response, customMeasures, nbCustomMeasures, component, metricsById, usersByLogin, lastAnalysisDateMs, searchOptions, fieldsToReturn);
}
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class ProvisionedAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
SearchOptions options = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
Set<String> desiredFields = desiredFields(request);
String query = request.param(Param.TEXT_QUERY);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = support.getOrganization(dbSession, request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
userSession.checkPermission(PROVISION_PROJECTS, organization);
RowBounds rowBounds = new RowBounds(options.getOffset(), options.getLimit());
List<ComponentDto> projects = dbClient.componentDao().selectProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER, rowBounds);
int nbOfProjects = dbClient.componentDao().countProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER);
JsonWriter json = response.newJsonWriter().beginObject();
writeProjects(projects, json, desiredFields);
options.writeJson(json, nbOfProjects);
json.endObject().close();
}
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class SearchAction method doContextResponse.
protected void doContextResponse(DbSession dbSession, SearchWsRequest request, SearchResult result, SearchResponse.Builder response, RuleQuery query) {
SearchOptions contextForResponse = loadCommonContext(request);
writeRules(response, result, contextForResponse);
if (contextForResponse.getFields().contains("actives")) {
activeRuleCompleter.completeSearch(dbSession, query, result.rules, response);
}
}
Aggregations