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