Search in sources :

Example 1 with SequentialItemIdGenerationStrategy

use of com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy 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 SequentialItemIdGenerationStrategy

use of com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method testQuadraticProbing_wraparound.

@Test
public void testQuadraticProbing_wraparound() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final SequentialItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    // next free itemId is 99999997
    idGenerationStrategy.getOrCreateCounter("1000154", ComponentCategory.CONCEPT).setCounter(99999997L);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    assertEquals("999999971000154106", Iterables.getOnlyElement(identifiers.generate("1000154", ComponentCategory.CONCEPT, 1)));
    // 99999998 and 2 becomes registered
    identifiers.register(ImmutableSet.of("999999981000154108", "21000154106"));
    // Attempt 1, quantity 2, 99999998 - 0
    // Attempt 2, quantity 1, 2 - 2
    // Attempt 3, quantity 1, 6 - 6
    List<String> actualIds = ImmutableList.copyOf(identifiers.generate("1000154", ComponentCategory.CONCEPT, 2));
    List<String> expectedIds = ImmutableList.of("999999991000154105", "11000154102");
    assertEquals(expectedIds, actualIds);
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Example 3 with SequentialItemIdGenerationStrategy

use of com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceTest method init.

@Before
public void init() {
    store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
    store.admin().create();
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    service = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) Mappings(com.b2international.index.mapping.Mappings) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 4 with SequentialItemIdGenerationStrategy

use of com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method issue_SO_2138_testItemIdsReturnedInSequence.

@Test
public void issue_SO_2138_testItemIdsReturnedInSequence() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    List<String> actualIds = ImmutableList.copyOf(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 3));
    List<String> expectedIds = ImmutableList.of("100005", "101009", "102002");
    assertEquals(expectedIds, actualIds);
    actualIds = ImmutableList.copyOf(identifiers.generate(B2I_NAMESPACE, ComponentCategory.CONCEPT, 3));
    expectedIds = ImmutableList.of("11000129102", "21000129106", "31000129108");
    assertEquals(expectedIds, actualIds);
    // Make a surprise return to the INT namespace here
    assertEquals("103007", Iterables.getFirst(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1), null));
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Example 5 with SequentialItemIdGenerationStrategy

use of com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method testQuadraticProbing.

@Test
public void testQuadraticProbing() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1);
    // Register a few existing SCTIDs that are "in the way"
    identifiers.register(ImmutableSet.of(// 1
    "101009", // 2
    "102002"));
    assertEquals("104001", Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1)));
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Aggregations

SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)10 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)10 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)9 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)9 ISnomedIdentifierReservationService (com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService)9 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)8 Test (org.junit.Test)8 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)7 Mappings (com.b2international.index.mapping.Mappings)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Index (com.b2international.index.Index)1 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)1 CisSnomedIdentifierService (com.b2international.snowowl.snomed.cis.client.CisSnomedIdentifierService)1 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)1 Before (org.junit.Before)1