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