Search in sources :

Example 1 with Reservation

use of com.b2international.snowowl.snomed.cis.reservations.Reservation 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 2 with Reservation

use of com.b2international.snowowl.snomed.cis.reservations.Reservation in project snow-owl by b2ihealthcare.

the class ReservationImplTest method whenReservingSingleID_ThenItShouldConflictWithThatIDOnly.

@Test
public void whenReservingSingleID_ThenItShouldConflictWithThatIDOnly() throws Exception {
    final Reservation single = Reservations.single(Concepts.ROOT_CONCEPT);
    assertTrue(single.includes(SnomedIdentifiers.create(Concepts.ROOT_CONCEPT)));
    assertFalse(single.includes(SnomedIdentifiers.create(Concepts.FULLY_DEFINED)));
    assertFalse(single.includes(SnomedIdentifiers.create(Concepts.ADDITIONAL_RELATIONSHIP)));
}
Also used : Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) Test(org.junit.Test)

Example 3 with Reservation

use of com.b2international.snowowl.snomed.cis.reservations.Reservation in project snow-owl by b2ihealthcare.

the class SnomedIdSetReservationTest method testIdSetReservationReservedIds.

@Test
public void testIdSetReservationReservedIds() {
    final Reservation idSetReservation = Reservations.idSetReservation(Sets.newHashSet(Concepts.MODULE_ROOT, Concepts.MODULE_SCT_CORE));
    final SnomedIdentifier rootIdentifier = SnomedIdentifiers.create(Concepts.ROOT_CONCEPT);
    final SnomedIdentifier sctCoreIdentifier = SnomedIdentifiers.create(Concepts.MODULE_SCT_CORE);
    final Set<SnomedIdentifier> reservedIds = idSetReservation.intersection(Sets.newHashSet(rootIdentifier, sctCoreIdentifier));
    assertThat(reservedIds).containsOnly(sctCoreIdentifier);
}
Also used : Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) Test(org.junit.Test)

Example 4 with Reservation

use of com.b2international.snowowl.snomed.cis.reservations.Reservation in project snow-owl by b2ihealthcare.

the class SnomedIdentifierReservationServiceImplTest method whenCreatingMoreThanOneReservation_ThenServiceMustStoreThem.

@Test
public void whenCreatingMoreThanOneReservation_ThenServiceMustStoreThem() throws Exception {
    final Reservation single = Reservations.single(Concepts.ROOT_CONCEPT);
    final Reservation range = Reservations.range(100, 200, null, Collections.singleton(ComponentCategory.CONCEPT));
    this.reservationService.create(SINGLE_RESERVATION, single);
    this.reservationService.create(RANGE_RESERVATION, range);
    assertThat(this.reservationService.getReservations()).contains(single, range);
}
Also used : Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) Test(org.junit.Test)

Example 5 with Reservation

use of com.b2international.snowowl.snomed.cis.reservations.Reservation in project snow-owl by b2ihealthcare.

the class SnomedIdentifierReservationServiceImplTest method whenCreatingSingleIDReservation_ThenReturnIsReservedTrueForThatID.

@Test
public void whenCreatingSingleIDReservation_ThenReturnIsReservedTrueForThatID() throws Exception {
    final Reservation single = Reservations.single(Concepts.ROOT_CONCEPT);
    this.reservationService.create(SINGLE_RESERVATION, single);
    assertThat(this.reservationService.isReserved(Concepts.ROOT_CONCEPT)).isTrue();
}
Also used : Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) Test(org.junit.Test)

Aggregations

Reservation (com.b2international.snowowl.snomed.cis.reservations.Reservation)7 Test (org.junit.Test)6 SnomedIdentifier (com.b2international.snowowl.snomed.cis.SnomedIdentifier)3 Index (com.b2international.index.Index)1 Mappings (com.b2international.index.mapping.Mappings)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)1 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)1 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)1 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)1 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)1 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1