Search in sources :

Example 1 with RevisionIndex

use of com.b2international.index.revision.RevisionIndex in project snow-owl by b2ihealthcare.

the class TerminologyRepository method activate.

public void activate(ServiceProvider context) {
    bind(Logger.class, log);
    RevisionIndex index = initIndex(context, mappings);
    bind(Repository.class, this);
    bind(Mappings.class, mappings);
    bind(ClassLoader.class, context.service(Plugins.class).getCompositeClassLoader());
    // initialize the index
    index.admin().create();
}
Also used : RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex)

Example 2 with RevisionIndex

use of com.b2international.index.revision.RevisionIndex 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)

Example 3 with RevisionIndex

use of com.b2international.index.revision.RevisionIndex in project snow-owl by b2ihealthcare.

the class TerminologyRepository method initIndex.

private RevisionIndex initIndex(final ServiceProvider context, Mappings mappings) {
    final ObjectMapper mapper = context.service(ObjectMapper.class);
    IndexConfiguration indexConfiguration = context.service(RepositoryConfiguration.class).getIndexConfiguration();
    final IndexClient indexClient = Indexes.createIndexClient(repositoryId, mapper, mappings, context.service(IndexSettings.class).forIndex(indexConfiguration, repositoryId));
    final Index index = new DefaultIndex(indexClient);
    final RevisionIndex revisionIndex = new DefaultRevisionIndex(index, context.service(TimestampProvider.class), mapper);
    revisionIndex.branching().addBranchChangeListener(path -> {
        new BranchChangedEvent(repositoryId, path).publish(context.service(IEventBus.class));
    });
    // register IndexClient per terminology
    bind(IndexClient.class, indexClient);
    // register index and revision index access, the underlying index is the same
    bind(Index.class, index);
    bind(RevisionIndex.class, revisionIndex);
    // register branching services
    bind(BaseRevisionBranching.class, revisionIndex.branching());
    return revisionIndex;
}
Also used : DefaultIndex(com.b2international.index.DefaultIndex) TimestampProvider(com.b2international.index.revision.TimestampProvider) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) IndexClient(com.b2international.index.IndexClient) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) Index(com.b2international.index.Index) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) DefaultIndex(com.b2international.index.DefaultIndex) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BranchChangedEvent(com.b2international.snowowl.core.branch.BranchChangedEvent) IEventBus(com.b2international.snowowl.eventbus.IEventBus) IndexConfiguration(com.b2international.snowowl.core.config.IndexConfiguration)

Example 4 with RevisionIndex

use of com.b2international.index.revision.RevisionIndex in project snow-owl by b2ihealthcare.

the class SnowOwlPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) throws Exception {
    if (env.isServer()) {
        final ObjectMapper mapper = env.service(ObjectMapper.class);
        final Index resourceIndex = Indexes.createIndex(RESOURCES_INDEX, mapper, new Mappings(ResourceDocument.class, VersionDocument.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), RESOURCES_INDEX));
        final RevisionIndex revisionIndex = new DefaultRevisionIndex(resourceIndex, env.service(TimestampProvider.class), mapper);
        env.services().registerService(ResourceRepository.class, new ResourceRepository(revisionIndex));
    }
}
Also used : VersionDocument(com.b2international.snowowl.core.version.VersionDocument) TimestampProvider(com.b2international.index.revision.TimestampProvider) Mappings(com.b2international.index.mapping.Mappings) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) Index(com.b2international.index.Index) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultRevisionIndex(com.b2international.index.revision.DefaultRevisionIndex) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with RevisionIndex

use of com.b2international.index.revision.RevisionIndex in project snow-owl by b2ihealthcare.

the class BranchCompareRequest method execute.

@Override
public BranchCompareResult execute(RepositoryContext context) {
    final RevisionIndex index = context.service(RevisionIndex.class);
    final Branch branchToCompare = RepositoryRequests.branching().prepareGet(compare).build().execute(context);
    final long compareHeadTimestamp = branchToCompare.headTimestamp();
    final RevisionCompare compareResult;
    final String baseBranchPath;
    if (base != null) {
        compareResult = index.compare(base, compare, limit, excludeComponentChanges);
        baseBranchPath = base;
    } else {
        compareResult = index.compare(compare, limit, excludeComponentChanges);
        baseBranchPath = branchToCompare.parentPath();
    }
    final BranchCompareResult.Builder result = BranchCompareResult.builder(baseBranchPath, compare, compareHeadTimestamp);
    final Set<ComponentIdentifier> changedContainers = Sets.newHashSet();
    for (RevisionCompareDetail detail : compareResult.getDetails()) {
        final ObjectId affectedId;
        if (detail.isComponentChange()) {
            affectedId = detail.getComponent();
            if (!detail.getObject().isRoot() && !excludeComponentChanges) {
                changedContainers.add(ComponentIdentifier.of(detail.getObject().type(), detail.getObject().id()));
            }
        } else {
            affectedId = detail.getObject();
        }
        final ComponentIdentifier identifier = ComponentIdentifier.of(affectedId.type(), affectedId.id());
        switch(detail.getOp()) {
            case ADD:
                result.putNewComponent(identifier);
                break;
            case CHANGE:
                result.putChangedComponent(identifier);
                break;
            case REMOVE:
                result.putDeletedComponent(identifier);
                break;
        }
    }
    return result.totalNew(compareResult.getTotalAdded()).totalChanged(compareResult.getTotalChanged()).totalDeleted(compareResult.getTotalRemoved()).build(changedContainers);
}
Also used : RevisionIndex(com.b2international.index.revision.RevisionIndex) ObjectId(com.b2international.index.revision.ObjectId) Branch(com.b2international.snowowl.core.branch.Branch) RevisionCompare(com.b2international.index.revision.RevisionCompare) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) RevisionCompareDetail(com.b2international.index.revision.RevisionCompareDetail)

Aggregations

RevisionIndex (com.b2international.index.revision.RevisionIndex)5 DefaultRevisionIndex (com.b2international.index.revision.DefaultRevisionIndex)3 Index (com.b2international.index.Index)2 TimestampProvider (com.b2international.index.revision.TimestampProvider)2 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IllegalQueryParameterException (com.b2international.commons.exceptions.IllegalQueryParameterException)1 DefaultIndex (com.b2international.index.DefaultIndex)1 Hits (com.b2international.index.Hits)1 IndexClient (com.b2international.index.IndexClient)1 Searcher (com.b2international.index.Searcher)1 Aggregation (com.b2international.index.aggregations.Aggregation)1 AggregationBuilder (com.b2international.index.aggregations.AggregationBuilder)1 Mappings (com.b2international.index.mapping.Mappings)1 Query (com.b2international.index.query.Query)1 QueryParseException (com.b2international.index.query.QueryParseException)1 ObjectId (com.b2international.index.revision.ObjectId)1 RevisionCompare (com.b2international.index.revision.RevisionCompare)1 RevisionCompareDetail (com.b2international.index.revision.RevisionCompareDetail)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1