Search in sources :

Example 6 with ItemIdGenerationStrategy

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

Example 7 with ItemIdGenerationStrategy

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

the class DefaultSnomedIdentifierServiceRegressionTest method issue_SO_2138_testSkipReservedRangeWithWraparound.

@Test
public void issue_SO_2138_testSkipReservedRangeWithWraparound() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    reservationService.create("nothingAboveTwoHundred", Reservations.range(200L, 8999_9999_9999_999L, null, ImmutableSet.of(ComponentCategory.CONCEPT)));
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    // The next item ID would be 200, if it weren't for the reserved range, which goes to the maximum allowed value
    identifiers.register(ImmutableSet.of("199004"));
    assertEquals("100005", 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)

Example 8 with ItemIdGenerationStrategy

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

the class DefaultSnomedIdentifierServiceRegressionTest method testQuadraticProbing_skipReservedRange.

@Test
public void testQuadraticProbing_skipReservedRange() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    reservationService.create("noTwoHundreds", Reservations.range(200L, 299L, "1000004", ImmutableSet.of(ComponentCategory.CONCEPT)));
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    // generate all IDs until 200
    identifiers.generate("1000004", ComponentCategory.CONCEPT, 199);
    // 300 becomes registered
    identifiers.register(ImmutableSet.of("3001000004102"));
    List<String> actualIds = ImmutableList.copyOf(identifiers.generate("1000004", ComponentCategory.CONCEPT, 2));
    List<String> expectedIds = ImmutableList.of("3011000004104", "3021000004108");
    assertEquals(expectedIds, actualIds);
}
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 9 with ItemIdGenerationStrategy

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

the class DefaultSnomedIdentifierServiceRegressionTest method issue_SO_2138_testCoveringReservedRanges.

@Test(expected = IllegalArgumentException.class)
public void issue_SO_2138_testCoveringReservedRanges() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    reservationService.create("nothingAboveOneHundredNinetyNine", Reservations.range(200L, 8999_9999_9999_999L, null, ImmutableSet.of(ComponentCategory.CONCEPT)));
    reservationService.create("nothingBelowOneHundredNinetyNine", Reservations.range(100L, 198L, null, ImmutableSet.of(ComponentCategory.CONCEPT)));
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    identifiers.register(ImmutableSet.of("198007"));
    assertEquals("199004", Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1)));
    // This attempt should not be able to generate any other value
    System.err.println(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

ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)9 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)9 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)8 SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)8 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)7 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)7 Test (org.junit.Test)7 ISnomedIdentifierReservationService (com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService)6 Index (com.b2international.index.Index)3 Mappings (com.b2international.index.mapping.Mappings)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 SnomedIdentifier (com.b2international.snowowl.snomed.cis.SnomedIdentifier)1 CisSnomedIdentifierService (com.b2international.snowowl.snomed.cis.client.CisSnomedIdentifierService)1 Reservation (com.b2international.snowowl.snomed.cis.reservations.Reservation)1 Set (java.util.Set)1 Before (org.junit.Before)1