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());
}
Aggregations