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();
}
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());
}
}
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;
}
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));
}
}
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);
}
Aggregations