Search in sources :

Example 1 with Builder

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());
    }
}
Also used : RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) ChangeSetProcessorBase(com.b2international.snowowl.core.repository.ChangeSetProcessorBase) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Map(java.util.Map) StagingArea(com.b2international.index.revision.StagingArea) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Builder) RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Builder) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)

Aggregations

Revision (com.b2international.index.revision.Revision)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 StagingArea (com.b2international.index.revision.StagingArea)1 ChangeSetProcessorBase (com.b2international.snowowl.core.repository.ChangeSetProcessorBase)1 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)1 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)1 Builder (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Builder)1 RefSetMemberChange (com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange)1 ReferenceSetMembershipUpdater (com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1