Search in sources :

Example 1 with RepositoryRequest

use of com.b2international.snowowl.core.request.RepositoryRequest in project snow-owl by b2ihealthcare.

the class SnomedDescriptionApiTest method testDuplicateMemberCleanupEmptiesAcceptabilityMap.

@Test
public void testDuplicateMemberCleanupEmptiesAcceptabilityMap() throws Exception {
    String descriptionId = createNewDescription(branchPath);
    // Inject inactive language member with different acceptability (API won't allow it)
    String memberIdToUpdate = UUID.randomUUID().toString();
    SnomedRefSetMemberIndexEntry member = SnomedRefSetMemberIndexEntry.builder().id(memberIdToUpdate).active(false).released(false).moduleId(Concepts.MODULE_SCT_CORE).refsetId(Concepts.REFSET_LANGUAGE_TYPE_UK).referencedComponentId(descriptionId).referenceSetType(SnomedRefSetType.LANGUAGE).field(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED).build();
    new RepositoryRequest<>(SnomedTerminologyComponentConstants.TOOLING_ID, context -> {
        ApplicationContext.getServiceForClass(RepositoryManager.class).get(SnomedTerminologyComponentConstants.TOOLING_ID).service(RevisionIndex.class).prepareCommit(branchPath.getPath()).stageNew(member).withContext(context.inject().bind(ModuleIdProvider.class, c -> c.getModuleId()).build()).commit(ApplicationContext.getServiceForClass(TimestampProvider.class).getTimestamp(), "test", "Added duplicate language reference set member to " + descriptionId);
        return null;
    }).execute(ApplicationContext.getServiceForClass(Environment.class));
    // Check the acceptability map; the description should be acceptable in the UK reference set
    SnomedDescription description = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class);
    assertEquals(Acceptability.ACCEPTABLE, description.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(2, description.getMembers().getTotal());
    String memberIdToDelete = null;
    for (SnomedReferenceSetMember descriptionMember : description.getMembers()) {
        if (Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_ACCEPTABLE.equals(descriptionMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID))) {
            memberIdToDelete = descriptionMember.getId();
            break;
        }
    }
    assertNotNull(memberIdToDelete);
    // Using bulk update, remove the currently active member and activate the inactive one, also changing its acceptability
    Json bulkRequest = Json.object("requests", Json.array(Json.object("action", "delete", "memberId", memberIdToDelete), Json.object("action", "update", "memberId", memberIdToUpdate, "active", true, "acceptabilityId", Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_ACCEPTABLE)), "commitComment", "Consolidated language reference set members");
    bulkUpdateMembers(branchPath, Concepts.REFSET_LANGUAGE_TYPE_UK, bulkRequest).statusCode(204);
    // Verify that description acceptability is still acceptable, but only one member remains
    SnomedDescription newDescription = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class);
    assertEquals(Acceptability.ACCEPTABLE, newDescription.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(1, newDescription.getMembers().getTotal());
    SnomedReferenceSetMember languageMember = Iterables.getOnlyElement(newDescription.getMembers());
    assertEquals(memberIdToUpdate, languageMember.getId());
    assertEquals(true, languageMember.isActive());
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) CoreMatchers(org.hamcrest.CoreMatchers) RestExtensions.assertCreated(com.b2international.snowowl.test.commons.rest.RestExtensions.assertCreated) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Json(com.b2international.commons.json.Json) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SnomedRestFixtures(com.b2international.snowowl.snomed.core.rest.SnomedRestFixtures) SnomedComponentType(com.b2international.snowowl.snomed.core.rest.SnomedComponentType) IdentifierStatus(com.b2international.snowowl.snomed.cis.domain.IdentifierStatus) ApplicationContext.getServiceForClass(com.b2international.snowowl.core.ApplicationContext.getServiceForClass) Map(java.util.Map) RevisionIndex(com.b2international.index.revision.RevisionIndex) RepositoryRequest(com.b2international.snowowl.core.request.RepositoryRequest) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) ConflictException(com.b2international.commons.exceptions.ConflictException) BulkRequestBuilder(com.b2international.snowowl.core.events.bulk.BulkRequestBuilder) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ContentType(io.restassured.http.ContentType) TimestampProvider(com.b2international.index.revision.TimestampProvider) InactivationProperties(com.b2international.snowowl.snomed.core.domain.InactivationProperties) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) LocalDate(java.time.LocalDate) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) SnomedComponentRestRequests(com.b2international.snowowl.snomed.core.rest.SnomedComponentRestRequests) CodeSystemVersionRestRequests.getNextAvailableEffectiveDate(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getNextAvailableEffectiveDate) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) Iterables(com.google.common.collect.Iterables) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) SnomedRefSetRestRequests.updateRefSetComponent(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.updateRefSetComponent) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ModuleIdProvider(com.b2international.snowowl.snomed.datastore.request.ModuleRequest.ModuleIdProvider) AssociationTarget(com.b2international.snowowl.snomed.core.domain.AssociationTarget) TermFilter(com.b2international.snowowl.core.request.TermFilter) Environment(com.b2international.snowowl.core.setup.Environment) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) CodeSystemVersionRestRequests.createCodeSystemAndVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createCodeSystemAndVersion) BulkRequest(com.b2international.snowowl.core.events.bulk.BulkRequest) RestExtensions.givenAuthenticatedRequest(com.b2international.snowowl.test.commons.rest.RestExtensions.givenAuthenticatedRequest) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) SnomedRefSetRestRequests.bulkUpdateMembers(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.bulkUpdateMembers) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) TextConstants(com.b2international.index.compat.TextConstants) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) DateTimeFormatter(java.time.format.DateTimeFormatter) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Collections(java.util.Collections) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) TimestampProvider(com.b2international.index.revision.TimestampProvider) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) RevisionIndex(com.b2international.index.revision.RevisionIndex) Environment(com.b2international.snowowl.core.setup.Environment) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) Json(com.b2international.commons.json.Json) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Aggregations

ConflictException (com.b2international.commons.exceptions.ConflictException)1 Json (com.b2international.commons.json.Json)1 TextConstants (com.b2international.index.compat.TextConstants)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 TimestampProvider (com.b2international.index.revision.TimestampProvider)1 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)1 ApplicationContext.getServiceForClass (com.b2international.snowowl.core.ApplicationContext.getServiceForClass)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)1 BranchPathUtils (com.b2international.snowowl.core.branch.BranchPathUtils)1 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)1 BulkRequest (com.b2international.snowowl.core.events.bulk.BulkRequest)1 BulkRequestBuilder (com.b2international.snowowl.core.events.bulk.BulkRequestBuilder)1 RepositoryRequest (com.b2international.snowowl.core.request.RepositoryRequest)1 TermFilter (com.b2international.snowowl.core.request.TermFilter)1 Environment (com.b2international.snowowl.core.setup.Environment)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)1 IdentifierStatus (com.b2international.snowowl.snomed.cis.domain.IdentifierStatus)1 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)1