use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Builder in project snow-owl by b2ihealthcare.
the class RelationshipChangeProcessor method process.
@Override
public void process(StagingArea staging, RevisionSearcher searcher) throws IOException {
final Multimap<String, RefSetMemberChange> referringRefSets = memberChangeProcessor.process(staging, searcher);
final Set<String> referencedRelationshipIds = newHashSet(referringRefSets.keySet());
staging.getNewObjects(SnomedRelationshipIndexEntry.class).map(SnomedRelationshipIndexEntry::getId).forEach(referencedRelationshipIds::remove);
final Map<String, SnomedRelationshipIndexEntry> changedRelationshipsById = staging.getChangedRevisions(SnomedRelationshipIndexEntry.class).map(diff -> (SnomedRelationshipIndexEntry) diff.newRevision).collect(Collectors.toMap(relationship -> relationship.getId(), relationship -> relationship));
final Set<String> changedRelationshipIds = newHashSet(changedRelationshipsById.keySet());
changedRelationshipIds.addAll(referencedRelationshipIds);
final Iterable<SnomedRelationshipIndexEntry> changedRelationshipHits = searcher.get(SnomedRelationshipIndexEntry.class, changedRelationshipIds);
final Map<String, SnomedRelationshipIndexEntry> changedRelationshipRevisionsById = Maps.uniqueIndex(changedRelationshipHits, Revision::getId);
for (final String id : changedRelationshipIds) {
final SnomedRelationshipIndexEntry currentDoc = changedRelationshipRevisionsById.get(id);
if (currentDoc == null) {
throw new IllegalStateException(String.format("Current relationship revision should not be null for %s", id));
}
final SnomedRelationshipIndexEntry relationship = changedRelationshipsById.get(id);
final Builder doc;
if (relationship != null) {
doc = SnomedRelationshipIndexEntry.builder(relationship);
} else {
doc = SnomedRelationshipIndexEntry.builder(currentDoc);
}
final Collection<String> currentMemberOf = currentDoc.getMemberOf();
final Collection<String> currentActiveMemberOf = currentDoc.getActiveMemberOf();
new ReferenceSetMembershipUpdater(referringRefSets.removeAll(id), currentMemberOf, currentActiveMemberOf).update(doc);
stageChange(currentDoc, doc.build());
}
}
Aggregations