Search in sources :

Example 1 with Repository

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

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

the class LocksCommand method parseLockTarget.

private static DatastoreLockTarget parseLockTarget(final String lockTargetOrAll) {
    if (ALL.equalsIgnoreCase(lockTargetOrAll)) {
        return DatastoreLockTarget.ALL;
    }
    final String repositoryId;
    final String path;
    String[] parts = lockTargetOrAll.split(":");
    if (parts.length == 2) {
        repositoryId = parts[0];
        path = parts[1];
    } else if (parts.length == 1) {
        repositoryId = parts[0];
        path = null;
    } else {
        return null;
    }
    final RepositoryManager repositoryManager = ApplicationContext.getInstance().getService(RepositoryManager.class);
    final Repository repository = repositoryManager.get(repositoryId);
    if (null == repository) {
        return null;
    }
    if (Strings.isNullOrEmpty(path)) {
        return new DatastoreLockTarget(repositoryId, null);
    }
    final IBranchPath branchPath = BranchPathUtils.createPath(path);
    // assuming active connection manager service here
    RevisionBranch branch = repository.service(BaseRevisionBranching.class).getBranch(path);
    if (null == branch) {
        return null;
    }
    return new DatastoreLockTarget(repositoryId, branchPath.getPath());
}
Also used : Repository(com.b2international.snowowl.core.Repository) RevisionBranch(com.b2international.index.revision.RevisionBranch) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching)

Example 3 with Repository

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

the class BranchesCommand method isValidRepositoryName.

private boolean isValidRepositoryName(String repositoryId, CommandLineStream out) {
    RepositoryManager repositoryManager = getRepositoryManager();
    Repository repository = repositoryManager.get(repositoryId);
    if (repository == null) {
        out.println("Could not find repository '%s'", repositoryId);
        out.println("Available repositories are:");
        repositoryManager.repositories().forEach(r -> out.println("\t%s", r.id()));
        return false;
    }
    return true;
}
Also used : Repository(com.b2international.snowowl.core.Repository) RepositoryManager(com.b2international.snowowl.core.RepositoryManager)

Example 4 with Repository

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

the class TerminologyRepositoryPlugin method run.

@Override
public final void run(SnowOwlConfiguration configuration, Environment env) throws Exception {
    // register terminology and component definitions
    TerminologyRegistry registry = env.service(TerminologyRegistry.class);
    registry.register(this);
    getAdditionalTerminologyComponents().values().forEach(additionalTerminologyComponent -> registry.register(getToolingId(), additionalTerminologyComponent));
    if (env.isServer()) {
        final DefaultRepositoryManager repositories = (DefaultRepositoryManager) env.service(RepositoryManager.class);
        final RepositoryBuilder builder = repositories.prepareCreate(getToolingId());
        final Repository repo = builder.withPreCommitHook(getTerminologyRepositoryPreCommitHook(builder.log())).addTerminologyComponents(getTerminologyComponents()).addTerminologyComponents(getAdditionalTerminologyComponents()).addMappings(getAdditionalMappings()).bind(ComponentDeletionPolicy.class, getComponentDeletionPolicy()).bind(VersioningRequestBuilder.class, getVersioningRequestBuilder()).bind(ComponentRevisionConflictProcessor.class, getComponentRevisionConflictProcessor()).bind(ConceptSearchRequestEvaluator.class, getConceptSearchRequestEvaluator()).bind(ValueSetMemberSearchRequestEvaluator.class, getMemberSearchRequestEvaluator()).bind(ConceptMapMappingSearchRequestEvaluator.class, getConceptMapMappingSearchRequestEvaluator()).bind(QueryOptimizer.class, getQueryOptimizer()).bind(ContentAvailabilityInfoProvider.class, getContentAvailabilityInfoProvider()).bind(ContextConfigurer.class, getRequestConfigurer()).bind(ResourceURLSchemaSupport.class, getTerminologyURISupport()).build(env);
        RepositoryInfo status = repo.status();
        if (status.health() == Health.GREEN) {
            LOG.info("Started repository '{}' with status '{}'", repo.id(), status.health());
        } else {
            LOG.warn("Started repository '{}' with status '{}'. Diagnosis: {}.", status.id(), status.health(), status.diagnosis());
        }
        // register EsClient from repository globally
        env.services().registerService(EsClient.class, repo.service(IndexClient.class).client());
    }
    afterRun(configuration, env);
}
Also used : Repository(com.b2international.snowowl.core.Repository) VersioningRequestBuilder(com.b2international.snowowl.core.request.version.VersioningRequestBuilder) RepositoryInfo(com.b2international.snowowl.core.RepositoryInfo) ResourceURLSchemaSupport(com.b2international.snowowl.core.uri.ResourceURLSchemaSupport) TerminologyRegistry(com.b2international.snowowl.core.terminology.TerminologyRegistry) RepositoryManager(com.b2international.snowowl.core.RepositoryManager)

Aggregations

Repository (com.b2international.snowowl.core.Repository)4 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)4 IllegalQueryParameterException (com.b2international.commons.exceptions.IllegalQueryParameterException)1 Index (com.b2international.index.Index)1 QueryParseException (com.b2international.index.query.QueryParseException)1 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 RepositoryInfo (com.b2international.snowowl.core.RepositoryInfo)1 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)1 DatastoreLockTarget (com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)1 DefaultRepositoryContext (com.b2international.snowowl.core.repository.DefaultRepositoryContext)1 VersioningRequestBuilder (com.b2international.snowowl.core.request.version.VersioningRequestBuilder)1 TerminologyRegistry (com.b2international.snowowl.core.terminology.TerminologyRegistry)1 ResourceURLSchemaSupport (com.b2international.snowowl.core.uri.ResourceURLSchemaSupport)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1