Search in sources :

Example 1 with DefaultRepositoryContext

use of com.b2international.snowowl.core.repository.DefaultRepositoryContext 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 DefaultRepositoryContext

use of com.b2international.snowowl.core.repository.DefaultRepositoryContext in project snow-owl by b2ihealthcare.

the class ResourceRepositoryRequest method execute.

@Override
public R execute(ServiceProvider context) {
    ResourceRepository resourceRepository = context.service(ResourceRepository.class);
    return resourceRepository.read(searcher -> {
        // TODO check health
        DefaultRepositoryContext repository = new DefaultRepositoryContext(context, RepositoryInfo.of(RESOURCE_REPOSITORY_ID, Health.GREEN, null, List.of()));
        repository.bind(RevisionIndex.class, resourceRepository);
        repository.bind(Searcher.class, searcher.searcher());
        repository.bind(RevisionSearcher.class, searcher);
        repository.bind(ContextConfigurer.class, ContextConfigurer.NOOP);
        repository.bind(BaseRevisionBranching.class, resourceRepository.branching());
        return next(repository);
    });
}
Also used : DefaultRepositoryContext(com.b2international.snowowl.core.repository.DefaultRepositoryContext) ResourceRepository(com.b2international.snowowl.core.internal.ResourceRepository)

Aggregations

DefaultRepositoryContext (com.b2international.snowowl.core.repository.DefaultRepositoryContext)2 IllegalQueryParameterException (com.b2international.commons.exceptions.IllegalQueryParameterException)1 Index (com.b2international.index.Index)1 QueryParseException (com.b2international.index.query.QueryParseException)1 Repository (com.b2international.snowowl.core.Repository)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 ResourceRepository (com.b2international.snowowl.core.internal.ResourceRepository)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1