Search in sources :

Example 1 with Index

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

the class SnomedIdentifierPlugin method registerSnomedIdentifierService.

private void registerSnomedIdentifierService(final SnomedIdentifierConfiguration conf, final Environment env, final ISnomedIdentifierReservationService reservationService) {
    ISnomedIdentifierService identifierService = null;
    switch(conf.getStrategy()) {
        case EMBEDDED:
            final Index index = Indexes.createIndex(SNOMED_IDS_INDEX, env.service(ObjectMapper.class), new Mappings(SctId.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), SNOMED_IDS_INDEX));
            index.admin().create();
            final ItemIdGenerationStrategy generationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
            identifierService = new DefaultSnomedIdentifierService(index, generationStrategy, reservationService, conf);
            break;
        case CIS:
            final ObjectMapper mapper = new ObjectMapper();
            identifierService = new CisSnomedIdentifierService(conf, reservationService, mapper);
            break;
        default:
            throw new IllegalStateException(String.format("Unknown ID generation source configured: %s. ", conf.getStrategy()));
    }
    env.services().registerService(ISnomedIdentifierService.class, identifierService);
    LOGGER.info("Snow Owl is configured to use {} based identifier service.", conf.getStrategy());
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) Mappings(com.b2international.index.mapping.Mappings) CisSnomedIdentifierService(com.b2international.snowowl.snomed.cis.client.CisSnomedIdentifierService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) Index(com.b2international.index.Index) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SctId(com.b2international.snowowl.snomed.cis.domain.SctId)

Example 2 with Index

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

the class ReservationImplTest method whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries.

@Test
public void whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries() throws Exception {
    final Index store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
    store.admin().create();
    final ISnomedIdentifierService identifierService = new DefaultSnomedIdentifierService(store, new ItemIdGenerationStrategy() {

        int counter = 200;

        @Override
        public Set<String> generateItemIds(String namespace, ComponentCategory category, int quantity, int attempt) {
            return IntStream.range(counter, counter + quantity).mapToObj(String::valueOf).collect(Collectors.toSet());
        }
    }, new SnomedIdentifierReservationServiceImpl(), new SnomedIdentifierConfiguration());
    final Set<ComponentCategory> components = Collections.singleton(ComponentCategory.CONCEPT);
    final Reservation range = Reservations.range(200, 300, "", components);
    final Set<String> componentIds = identifierService.generate(null, ComponentCategory.CONCEPT, 300 - 200 + 1);
    for (String id : componentIds) {
        final SnomedIdentifier identifier = SnomedIdentifiers.create(id);
        assertTrue(range.includes(identifier));
    }
    store.admin().delete();
}
Also used : ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) Set(java.util.Set) Index(com.b2international.index.Index) SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) Mappings(com.b2international.index.mapping.Mappings) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) Test(org.junit.Test)

Example 3 with Index

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

the class DefaultSnomedIdentifierServiceRegressionTest method issue_SO_1945_testItemIdPoolExhausted.

@Test
public void issue_SO_1945_testItemIdPoolExhausted() throws Exception {
    final Provider<Index> storeProvider = Providers.of(store);
    final ItemIdGenerationStrategy idGenerationStrategy = new CyclingItemIdGenerationStrategy("1000", "1001");
    final SnomedIdentifierConfiguration config = new SnomedIdentifierConfiguration();
    config.setMaxIdGenerationAttempts(10);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(storeProvider, idGenerationStrategy, config);
    final String first = Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1));
    assertThat(first).startsWith("1000");
    final String second = Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1));
    assertThat(second).startsWith("1001");
    /*
		 * The third attempt should generate itemId 1000 again,
		 * but that is already generated and no more itemIds are available
		 * therefore it will try to generate 1001, and that fails too, 
		 * rinse and repeat until maxIdGenerationAttempts are made
		 */
    try {
        identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1);
    } catch (final BadRequestException e) {
        assertThat(e.getMessage()).isEqualTo(String.format("Couldn't generate 1 identifiers [CONCEPT, INT] in maximum (%s) number of attempts", config.getMaxIdGenerationAttempts()));
    }
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Index(com.b2international.index.Index) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Example 4 with Index

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

the class RepositoryTransactionContext method clearContents.

@Override
public void clearContents() {
    final Index index = service(Index.class);
    final RevisionSearcher revisionSearcher = service(RevisionSearcher.class);
    final IndexAdmin indexAdmin = index.admin();
    final Mappings mappings = indexAdmin.mappings();
    final Stream<Class<?>> revisionTypes = mappings.getTypes().stream().filter(t -> Revision.class.isAssignableFrom(t));
    revisionTypes.forEach(type -> {
        Query.select(String.class).from(type).fields(Revision.Fields.ID).where(Expressions.matchAll()).build().stream(revisionSearcher).forEachOrdered(ids -> {
            final Iterable<?> revisions = fetchComponents(ids.getHits(), type);
            revisions.forEach(rev -> {
                final String revisionId = ((Revision) rev).getId();
                staging.stageRemove(revisionId, rev);
            });
        });
    });
}
Also used : IndexAdmin(com.b2international.index.admin.IndexAdmin) Mappings(com.b2international.index.mapping.Mappings) Index(com.b2international.index.Index)

Example 5 with Index

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

Aggregations

Index (com.b2international.index.Index)17 Mappings (com.b2international.index.mapping.Mappings)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)6 Before (org.junit.Before)6 ValidationRepository (com.b2international.snowowl.core.internal.validation.ValidationRepository)4 ValidationRule (com.b2international.snowowl.core.validation.rule.ValidationRule)4 RevisionIndex (com.b2international.index.revision.RevisionIndex)3 ValidationIssue (com.b2international.snowowl.core.validation.issue.ValidationIssue)3 ValidationWhiteList (com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList)3 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)3 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)3 DefaultRevisionIndex (com.b2international.index.revision.DefaultRevisionIndex)2 TimestampProvider (com.b2international.index.revision.TimestampProvider)2 ClassPathScanner (com.b2international.snowowl.core.plugin.ClassPathScanner)2 ValidationIssueDetailExtensionProvider (com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider)2 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)2 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)2 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)2 SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)2