Search in sources :

Example 1 with ReferenceSetMembershipUpdater

use of com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater in project snow-owl by b2ihealthcare.

the class DescriptionChangeProcessor method processChanges.

private void processChanges(final String id, final Builder doc, final SnomedDescriptionIndexEntry currentRevision, Multimap<Acceptability, RefSetMemberChange> acceptabilityChanges, Multimap<String, RefSetMemberChange> referringRefSets) {
    final Multimap<Acceptability, String> acceptabilityMap = currentRevision == null ? ImmutableMultimap.<Acceptability, String>of() : ImmutableMap.copyOf(currentRevision.getAcceptabilityMap()).asMultimap().inverse();
    final Collection<String> preferredLanguageRefSets = newHashSet(acceptabilityMap.get(Acceptability.PREFERRED));
    final Collection<String> acceptableLanguageRefSets = newHashSet(acceptabilityMap.get(Acceptability.ACCEPTABLE));
    if (acceptabilityChanges != null) {
        collectChanges(acceptabilityChanges.get(Acceptability.PREFERRED), preferredLanguageRefSets);
        collectChanges(acceptabilityChanges.get(Acceptability.ACCEPTABLE), acceptableLanguageRefSets);
    }
    // clear acceptability map first then apply new acceptability settings
    doc.acceptabilityMap(Collections.emptyMap());
    for (String preferredLanguageRefSet : preferredLanguageRefSets) {
        doc.acceptability(preferredLanguageRefSet, Acceptability.PREFERRED);
    }
    for (String acceptableLanguageRefSet : acceptableLanguageRefSets) {
        doc.acceptability(acceptableLanguageRefSet, Acceptability.ACCEPTABLE);
    }
    final Collection<String> currentMemberOf = currentRevision == null ? Collections.emptySet() : currentRevision.getMemberOf();
    final Collection<String> currentActiveMemberOf = currentRevision == null ? Collections.emptySet() : currentRevision.getActiveMemberOf();
    new ReferenceSetMembershipUpdater(referringRefSets.removeAll(id), currentMemberOf, currentActiveMemberOf).update(doc);
}
Also used : ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability)

Example 2 with ReferenceSetMembershipUpdater

use of com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater in project snow-owl by b2ihealthcare.

the class ConceptChangeProcessor method update.

/*
	 * Updates already existing concept document with changes from concept and the current revision.
	 * New concepts does not have currentRevision and dirty concepts may not have a loaded Concept CDOObject, 
	 * therefore both can be null, but not at the same time.
	 * In case of new objects the Concept object should not be null, in case of dirty, the currentVersion should not be null, 
	 * but there can be a dirty concept if a property changed on it.
	 * We will use whatever we actually have locally to compute the new revision.
	 */
private void update(SnomedConceptDocument.Builder doc, List<SnomedDescriptionFragment> preferredDescriptions, @Nullable SnomedConceptDocument newOrDirtyRevision, SnomedConceptDocument cleanRevision) {
    checkArgument(newOrDirtyRevision != null || cleanRevision != null, "Either the newOrDirtyRevision is null or the cleanRevision but not both");
    final String id = newOrDirtyRevision != null ? newOrDirtyRevision.getId() : cleanRevision.getId();
    final long idLong = Long.parseLong(id);
    final boolean active = newOrDirtyRevision != null ? newOrDirtyRevision.isActive() : cleanRevision.isActive();
    if (newOrDirtyRevision != null) {
        doc.active(active).released(newOrDirtyRevision.isReleased()).effectiveTime(newOrDirtyRevision.getEffectiveTime()).moduleId(newOrDirtyRevision.getModuleId()).exhaustive(newOrDirtyRevision.isExhaustive()).definitionStatusId(newOrDirtyRevision.getDefinitionStatusId()).refSetType(newOrDirtyRevision.getRefSetType()).referencedComponentType(newOrDirtyRevision.getReferencedComponentType()).mapTargetComponentType(newOrDirtyRevision.getMapTargetComponentType()).doi(doiData.getDoiScore(idLong));
    } else {
        doc.active(active).released(cleanRevision.isReleased()).effectiveTime(cleanRevision.getEffectiveTime()).moduleId(cleanRevision.getModuleId()).exhaustive(cleanRevision.isExhaustive()).definitionStatusId(cleanRevision.getDefinitionStatusId()).refSetType(cleanRevision.getRefSetType()).referencedComponentType(cleanRevision.getReferencedComponentType()).mapTargetComponentType(cleanRevision.getMapTargetComponentType()).doi(doiData.getDoiScore(idLong));
    }
    /*
		 * Extract semantic tags from active FSNs received in preferredDescriptions (these are expected to be preferred in at 
		 * least one language reference set).
		 */
    final SortedSet<String> semanticTags = preferredDescriptions.stream().filter(f -> Concepts.FULLY_SPECIFIED_NAME.equals(f.getTypeId())).map(f -> SnomedDescriptionIndexEntry.extractSemanticTag(f.getTerm())).filter(semanticTag -> !semanticTag.isEmpty()).collect(Collectors.toCollection(TreeSet::new));
    final boolean inStated = statedTaxonomy.getNewTaxonomy().containsNode(idLong);
    final boolean inInferred = inferredTaxonomy.getNewTaxonomy().containsNode(idLong);
    if (inStated || inInferred) {
        iconId.update(id, Iterables.getFirst(semanticTags, ""), active, doc);
    }
    if (inStated) {
        stated.update(id, doc);
    }
    if (inInferred) {
        inferred.update(id, doc);
    }
    final Collection<String> currentMemberOf = cleanRevision == null ? Collections.emptySet() : cleanRevision.getMemberOf();
    final Collection<String> currentActiveMemberOf = cleanRevision == null ? Collections.emptySet() : cleanRevision.getActiveMemberOf();
    new ReferenceSetMembershipUpdater(referringRefSets.removeAll(id), currentMemberOf, currentActiveMemberOf).update(doc);
    doc.semanticTags(semanticTags);
    doc.preferredDescriptions(preferredDescriptions);
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ChangeSetProcessorBase(com.b2international.snowowl.core.repository.ChangeSetProcessorBase) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) java.util(java.util) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) RevisionDiff(com.b2international.index.revision.StagingArea.RevisionDiff) IconIdUpdater(com.b2international.snowowl.snomed.datastore.index.update.IconIdUpdater) TaxonomyGraph(com.b2international.snowowl.snomed.datastore.taxonomy.TaxonomyGraph) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) LongSets(com.b2international.commons.collect.LongSets) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ObjectId(com.b2international.index.revision.ObjectId) SnomedDescriptionFragment(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) com.google.common.collect(com.google.common.collect) Nullable(javax.annotation.Nullable) RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Revision(com.b2international.index.revision.Revision) IOException(java.io.IOException) Taxonomy(com.b2international.snowowl.snomed.datastore.taxonomy.Taxonomy) Collectors(java.util.stream.Collectors) ParentageUpdater(com.b2international.snowowl.snomed.datastore.index.update.ParentageUpdater) StagingArea(com.b2international.index.revision.StagingArea) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Builder) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater)

Example 3 with ReferenceSetMembershipUpdater

use of com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater 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

ReferenceSetMembershipUpdater (com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater)3 Revision (com.b2international.index.revision.Revision)2 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)2 StagingArea (com.b2international.index.revision.StagingArea)2 ChangeSetProcessorBase (com.b2international.snowowl.core.repository.ChangeSetProcessorBase)2 Acceptability (com.b2international.snowowl.snomed.core.domain.Acceptability)2 RefSetMemberChange (com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 LongSets (com.b2international.commons.collect.LongSets)1 ObjectId (com.b2international.index.revision.ObjectId)1 RevisionDiff (com.b2international.index.revision.StagingArea.RevisionDiff)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)1 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)1 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)1 Builder (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Builder)1 SnomedDescriptionFragment (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment)1 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)1