Search in sources :

Example 1 with QueryParseException

use of com.b2international.index.query.QueryParseException in project snow-owl by b2ihealthcare.

the class RepositoryRequest method execute.

@Override
public B execute(final ServiceProvider context) {
    Repository repository = context.service(RepositoryManager.class).get(repositoryId);
    if (repository == null) {
        throw new IllegalArgumentException(String.format("Unknown repositoryId '%s'", repositoryId));
    }
    DefaultRepositoryContext repositoryContext = new DefaultRepositoryContext(context, repository.status());
    // by default add a NullProgressMonitor binding to the context
    // if the previous context is a delegate context, injecting all services can override this safely
    repositoryContext.bind(IProgressMonitor.class, new NullProgressMonitor());
    repositoryContext.bindAll(repository);
    // always "open" an index read context when executing requests inside a repository
    return repository.service(Index.class).read(index -> {
        try {
            repositoryContext.bind(Searcher.class, index);
            return next(repositoryContext);
        } catch (QueryParseException e) {
            throw new IllegalQueryParameterException(e.getMessage());
        }
    });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Repository(com.b2international.snowowl.core.Repository) DefaultRepositoryContext(com.b2international.snowowl.core.repository.DefaultRepositoryContext) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) Index(com.b2international.index.Index) QueryParseException(com.b2international.index.query.QueryParseException)

Example 2 with QueryParseException

use of com.b2international.index.query.QueryParseException in project snow-owl by b2ihealthcare.

the class RevisionIndexReadRequest method execute.

@Override
public B execute(final BranchContext context) {
    final String branchPath = context.path();
    RevisionIndex index = context.service(RevisionIndex.class);
    if (snapshot) {
        return index.read(branchPath, searcher -> {
            try {
                return next(context.inject().bind(RevisionSearcher.class, searcher).build());
            } catch (QueryParseException e) {
                throw new IllegalQueryParameterException(e.getMessage());
            }
        });
    } else {
        return next(context.inject().bind(RevisionSearcher.class, new RevisionSearcher() {

            @Override
            public <T> Aggregation<T> aggregate(AggregationBuilder<T> aggregation) throws IOException {
                return index.read(branchPath, searcher -> searcher.aggregate(aggregation));
            }

            @Override
            public Searcher searcher() {
                return index.read(branchPath, searcher -> searcher.searcher());
            }

            @Override
            public <T> Hits<T> search(Query<T> query) throws IOException {
                return index.read(branchPath, searcher -> searcher.search(query));
            }

            @Override
            public <T> Iterable<T> get(Class<T> type, Iterable<String> keys) throws IOException {
                return index.read(branchPath, searcher -> searcher.get(type, keys));
            }

            @Override
            public <T> T get(Class<T> type, String key) throws IOException {
                return index.read(branchPath, searcher -> searcher.get(type, key));
            }

            @Override
            public String branch() {
                return branchPath;
            }
        }).build());
    }
}
Also used : Searcher(com.b2international.index.Searcher) Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) QueryParseException(com.b2international.index.query.QueryParseException) Request(com.b2international.snowowl.core.events.Request) IOException(java.io.IOException) Aggregation(com.b2international.index.aggregations.Aggregation) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) AggregationBuilder(com.b2international.index.aggregations.AggregationBuilder) RevisionIndex(com.b2international.index.revision.RevisionIndex) DelegatingRequest(com.b2international.snowowl.core.events.DelegatingRequest) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Hits(com.b2international.index.Hits) RevisionIndex(com.b2international.index.revision.RevisionIndex) Searcher(com.b2international.index.Searcher) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) IOException(java.io.IOException) QueryParseException(com.b2international.index.query.QueryParseException) Aggregation(com.b2international.index.aggregations.Aggregation) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Aggregations

IllegalQueryParameterException (com.b2international.commons.exceptions.IllegalQueryParameterException)2 QueryParseException (com.b2international.index.query.QueryParseException)2 Hits (com.b2international.index.Hits)1 Index (com.b2international.index.Index)1 Searcher (com.b2international.index.Searcher)1 Aggregation (com.b2international.index.aggregations.Aggregation)1 AggregationBuilder (com.b2international.index.aggregations.AggregationBuilder)1 Query (com.b2international.index.query.Query)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 Repository (com.b2international.snowowl.core.Repository)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 DelegatingRequest (com.b2international.snowowl.core.events.DelegatingRequest)1 Request (com.b2international.snowowl.core.events.Request)1 DefaultRepositoryContext (com.b2international.snowowl.core.repository.DefaultRepositoryContext)1 IOException (java.io.IOException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1