Search in sources :

Example 1 with ProjectQueryProcessor

use of com.google.gerrit.server.query.project.ProjectQueryProcessor in project gerrit by GerritCodeReview.

the class QueryProjects method apply.

public List<ProjectInfo> apply() throws BadRequestException, MethodNotAllowedException {
    if (Strings.isNullOrEmpty(query)) {
        throw new BadRequestException("missing query field");
    }
    ProjectIndex searchIndex = indexes.getSearchIndex();
    if (searchIndex == null) {
        throw new MethodNotAllowedException("no project index");
    }
    ProjectQueryProcessor queryProcessor = queryProcessorProvider.get();
    if (start != 0) {
        queryProcessor.setStart(start);
    }
    if (limit != 0) {
        queryProcessor.setUserProvidedLimit(limit);
    }
    try {
        QueryResult<ProjectData> result = queryProcessor.query(queryBuilder.parse(query));
        List<ProjectData> pds = result.entities();
        ArrayList<ProjectInfo> projectInfos = Lists.newArrayListWithCapacity(pds.size());
        for (ProjectData pd : pds) {
            projectInfos.add(json.format(pd.getProject()));
        }
        return projectInfos;
    } catch (QueryParseException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) ProjectQueryProcessor(com.google.gerrit.server.query.project.ProjectQueryProcessor) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ProjectIndex(com.google.gerrit.index.project.ProjectIndex) ProjectData(com.google.gerrit.index.project.ProjectData) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Aggregations

ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 ProjectData (com.google.gerrit.index.project.ProjectData)1 ProjectIndex (com.google.gerrit.index.project.ProjectIndex)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 ProjectQueryProcessor (com.google.gerrit.server.query.project.ProjectQueryProcessor)1