use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry in project snow-owl by b2ihealthcare.
the class RelationshipChangeProcessorTest method deleteOneMemberFromMultipleMembersOfRelationship.
@Test
public void deleteOneMemberFromMultipleMembersOfRelationship() {
final SnomedRelationshipIndexEntry relationship = createRandomRelationship();
final String referringRefSetId = generateConceptId();
final SnomedRefSetMemberIndexEntry member1 = simpleMember(relationship.getId(), referringRefSetId);
final SnomedRefSetMemberIndexEntry member2 = simpleMember(relationship.getId(), referringRefSetId);
initRevisions(SnomedRelationshipIndexEntry.builder(relationship).memberOf(ImmutableList.of(referringRefSetId, referringRefSetId)).activeMemberOf(ImmutableList.of(referringRefSetId, referringRefSetId)).build(), member1, member2);
stageRemove(member1);
process(processor);
final SnomedRelationshipIndexEntry expectedDoc = SnomedRelationshipIndexEntry.builder(relationship).memberOf(Collections.singleton(referringRefSetId)).activeMemberOf(Collections.singleton(referringRefSetId)).build();
final Revision currentDoc = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
assertDocEquals(expectedDoc, currentDoc);
assertEquals(0, processor.getNewMappings().size());
assertEquals(0, processor.getDeletions().size());
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry in project snow-owl by b2ihealthcare.
the class SnomedRelationshipCreateRequest method execute.
@Override
public String execute(final TransactionContext context) {
if (Strings.isNullOrEmpty(getSourceId())) {
throw new BadRequestException("'sourceId' may not be empty");
}
if (Strings.isNullOrEmpty(getDestinationId()) && getValue() == null) {
throw new BadRequestException("'destinationId' or 'value' should be specified");
}
if (!Strings.isNullOrEmpty(getDestinationId()) && getValue() != null) {
throw new BadRequestException("'destinationId' and 'value' can not be set for the same relationship");
}
try {
final String relationshipId = ((ConstantIdStrategy) getIdGenerationStrategy()).getId();
final SnomedRelationshipIndexEntry relationship = SnomedComponents.newRelationship().withId(relationshipId).withActive(isActive()).withModuleId(getModuleId()).withSourceId(getSourceId()).withTypeId(getTypeId()).withDestinationId(getDestinationId()).withDestinationNegated(isDestinationNegated()).withValue(getValue()).withRelationshipGroup(getRelationshipGroup()).withUnionGroup(getUnionGroup()).withCharacteristicTypeId(getCharacteristicTypeId()).withModifierId(getModifierId()).build(context);
convertMembers(context, relationshipId);
context.add(relationship);
return relationship.getId();
} catch (final ComponentNotFoundException e) {
throw e.toBadRequestException();
}
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry 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