Search in sources :

Example 6 with ISnomedIdentifierService

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

the class SnomedRelationshipApiTest method createRelationshipWithReservedId.

@Test
public void createRelationshipWithReservedId() {
    ISnomedIdentifierService identifierService = getServiceForClass(ISnomedIdentifierService.class);
    String relationshipId = Iterables.getOnlyElement(identifierService.reserve(null, ComponentCategory.RELATIONSHIP, 1));
    Json requestBody = createRelationshipRequestBody(Concepts.ROOT_CONCEPT, Concepts.PART_OF, Concepts.NAMESPACE_ROOT).with("id", relationshipId).with("commitComment", "Created new relationship with reserved identifier");
    createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody).statusCode(201).header("Location", endsWith("/" + relationshipId));
    SctId relationshipSctId = SnomedRequests.identifiers().prepareGet().setComponentId(relationshipId).buildAsync().execute(getBus()).getSync().first().get();
    assertEquals(IdentifierStatus.ASSIGNED.getSerializedName(), relationshipSctId.getStatus());
}
Also used : ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) Json(com.b2international.commons.json.Json) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 7 with ISnomedIdentifierService

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

the class Rf2TransactionContext method commit.

@Override
public Optional<Commit> commit(String commitComment) {
    final Set<String> idsToRegister = ImmutableSet.copyOf(newComponents.keySet().stream().filter(SnomedIdentifiers::isValid).iterator());
    // clear local cache before executing commit
    newComponents = newHashMap();
    LOG.info("Pushing changes: {}", commitComment);
    Optional<Commit> commit = getDelegate().commit(commitComment);
    // after successful commit register all commited IDs to CIS
    final ISnomedIdentifierService cis = service(ISnomedIdentifierService.class);
    if (cis.importSupported()) {
        cis.register(idsToRegister);
    }
    return commit;
}
Also used : Commit(com.b2international.index.revision.Commit) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifiers(com.b2international.snowowl.snomed.cis.SnomedIdentifiers)

Example 8 with ISnomedIdentifierService

use of com.b2international.snowowl.snomed.cis.ISnomedIdentifierService 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 9 with ISnomedIdentifierService

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

the class DefaultSnomedIdentifierServiceRegressionTest method testQuadraticProbing_skipReservedRangeWithWraparound.

@Test
public void testQuadraticProbing_skipReservedRangeWithWraparound() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    reservationService.create("nothingAboveTwoHundred", Reservations.range(200L, 9999_9999L, "1000133", ImmutableSet.of(ComponentCategory.CONCEPT)));
    final SequentialItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    idGenerationStrategy.getOrCreateCounter("1000133", ComponentCategory.CONCEPT).setCounter(199L);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    // itemId counter is initialized with 199, next free itemId is 199
    assertEquals("1991000133107", Iterables.getOnlyElement(identifiers.generate("1000133", ComponentCategory.CONCEPT, 1)));
    // 1 becomes registered
    identifiers.register(ImmutableSet.of("11000133105"));
    List<String> actualIds = ImmutableList.copyOf(identifiers.generate("1000133", ComponentCategory.CONCEPT, 2));
    List<String> expectedIds = ImmutableList.of("21000133103", "31000133100");
    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 10 with ISnomedIdentifierService

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

Aggregations

ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)15 Test (org.junit.Test)14 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)10 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)10 SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)9 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)9 ISnomedIdentifierReservationService (com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService)8 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)7 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)5 Json (com.b2international.commons.json.Json)3 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)3 Index (com.b2international.index.Index)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Mappings (com.b2international.index.mapping.Mappings)1 Commit (com.b2international.index.revision.Commit)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 SnomedIdentifier (com.b2international.snowowl.snomed.cis.SnomedIdentifier)1 SnomedIdentifiers (com.b2international.snowowl.snomed.cis.SnomedIdentifiers)1 Reservation (com.b2international.snowowl.snomed.cis.reservations.Reservation)1 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)1