use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedSimpleMemberCreateDelegate method execute.
@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
checkRefSetType(refSet, SnomedRefSetType.SIMPLE);
checkReferencedComponent(refSet);
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
SnomedRefSetMemberIndexEntry member = SnomedComponents.newSimpleMember().withId(getId()).withActive(isActive()).withReferencedComponent(getReferencedComponentId()).withModuleId(getModuleId()).withRefSet(getReferenceSetId()).addTo(context);
return member.getId();
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry 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());
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class ReferringMemberChangeProcessor method process.
public Multimap<String, RefSetMemberChange> process(StagingArea staging, RevisionSearcher searcher) throws IOException {
final Multimap<String, RefSetMemberChange> memberChanges = HashMultimap.create();
// process new members
staging.getNewObjects(SnomedRefSetMemberIndexEntry.class).filter(this::byReferencedComponentType).forEach((newMember) -> {
addChange(memberChanges, newMember, MemberChangeKind.ADDED);
});
// process dirty members
staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).filter(diff -> byReferencedComponentType((SnomedRefSetMemberIndexEntry) diff.newRevision)).forEach((diff) -> {
RevisionPropertyDiff propChange = diff.getRevisionPropertyDiff(SnomedRefSetMemberIndexEntry.Fields.ACTIVE);
if (propChange != null) {
addChange(memberChanges, (SnomedRefSetMemberIndexEntry) diff.newRevision, MemberChangeKind.CHANGED);
}
});
// process detached members
staging.getRemovedObjects(SnomedRefSetMemberIndexEntry.class).filter(this::byReferencedComponentType).forEach(doc -> {
final String uuid = doc.getId();
final String referencedComponentId = doc.getReferencedComponentId();
final String refSetId = doc.getRefsetId();
memberChanges.put(referencedComponentId, new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, doc.isActive()));
});
return memberChanges;
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.
the class DescriptionAcceptabilityChangeProcessor method process.
public Map<String, Multimap<Acceptability, RefSetMemberChange>> process(StagingArea staging, RevisionSearcher searcher) throws IOException {
final Multimap<String, RefSetMemberChange> preferredMemberChanges = HashMultimap.create();
final Multimap<String, RefSetMemberChange> acceptableMemberChanges = HashMultimap.create();
// add active new and active dirty members
final Stream<SnomedRefSetMemberIndexEntry> newAndDirtyMembers = Streams.concat(staging.getNewObjects(SnomedRefSetMemberIndexEntry.class).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE), staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).map(diff -> (SnomedRefSetMemberIndexEntry) diff.newRevision).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE));
newAndDirtyMembers.forEach(member -> {
if (member.isActive()) {
final String uuid = member.getId();
final String refSetId = member.getRefsetId();
final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.ADDED, member.isActive());
registerChange(preferredMemberChanges, acceptableMemberChanges, member.getAcceptabilityId(), member.getReferencedComponentId(), change);
}
});
// remove dirty inactive (and/or changed in acceptability) members
final List<SnomedRefSetMemberIndexEntry> dirtyMembers = staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).map(diff -> (SnomedRefSetMemberIndexEntry) diff.newRevision).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE).collect(Collectors.toList());
final Set<String> dirtyMemberIds = dirtyMembers.stream().map(SnomedRefSetMemberIndexEntry::getId).collect(Collectors.toSet());
final List<SnomedRefSetMemberIndexEntry> detachedLanguageMembers = staging.getRemovedObjects(SnomedRefSetMemberIndexEntry.class).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE).collect(Collectors.toList());
final Map<String, SnomedRefSetMemberIndexEntry> currentRevisionsByMemberId = newHashMap();
detachedLanguageMembers.forEach(member -> currentRevisionsByMemberId.put(member.getId(), member));
searcher.get(SnomedRefSetMemberIndexEntry.class, dirtyMemberIds).forEach(member -> currentRevisionsByMemberId.put(member.getId(), member));
for (SnomedRefSetMemberIndexEntry member : dirtyMembers) {
final String uuid = member.getId();
final String refSetId = member.getRefsetId();
final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, member.isActive());
final SnomedRefSetMemberIndexEntry before = currentRevisionsByMemberId.get(member.getId());
if (before != null) {
final String beforeAcceptabilityId = before.getAcceptabilityId();
final boolean beforeActive = before.isActive();
final boolean acceptabilityChanged = !member.getAcceptabilityId().equals(beforeAcceptabilityId);
if (beforeActive && acceptabilityChanged) {
registerChange(preferredMemberChanges, acceptableMemberChanges, beforeAcceptabilityId, member.getReferencedComponentId(), change);
}
}
if (!member.isActive()) {
registerChange(preferredMemberChanges, acceptableMemberChanges, member.getAcceptabilityId(), member.getReferencedComponentId(), change);
}
}
for (final SnomedRefSetMemberIndexEntry before : detachedLanguageMembers) {
if (before.isActive()) {
final String uuid = before.getId();
final String refSetId = before.getRefsetId();
final String referencedComponentId = before.getReferencedComponentId();
final String beforeAcceptabilityId = before.getAcceptabilityId();
final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, before.isActive());
registerChange(preferredMemberChanges, acceptableMemberChanges, beforeAcceptabilityId, referencedComponentId, change);
}
}
final Map<String, Multimap<Acceptability, RefSetMemberChange>> changes = newHashMap();
for (String descriptionId : Iterables.concat(preferredMemberChanges.keySet(), acceptableMemberChanges.keySet())) {
if (!changes.containsKey(descriptionId)) {
changes.put(descriptionId, HashMultimap.<Acceptability, RefSetMemberChange>create());
}
final Multimap<Acceptability, RefSetMemberChange> memberChanges = changes.get(descriptionId);
memberChanges.putAll(Acceptability.PREFERRED, preferredMemberChanges.get(descriptionId));
memberChanges.putAll(Acceptability.ACCEPTABLE, acceptableMemberChanges.get(descriptionId));
}
return changes;
}
Aggregations