Search in sources :

Example 16 with SnomedRelationshipIndexEntry

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());
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

Example 17 with SnomedRelationshipIndexEntry

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();
    }
}
Also used : ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) ConstantIdStrategy(com.b2international.snowowl.snomed.core.domain.ConstantIdStrategy) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 18 with SnomedRelationshipIndexEntry

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

SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)18 Test (org.junit.Test)14 Revision (com.b2international.index.revision.Revision)13 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)9 SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)6 BadRequestException (com.b2international.commons.exceptions.BadRequestException)2 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)2 StagingArea (com.b2international.index.revision.StagingArea)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Set (java.util.Set)2 LongCollection (com.b2international.collections.longs.LongCollection)1 LongCollections (com.b2international.collections.longs.LongCollections)1 LongIterator (com.b2international.collections.longs.LongIterator)1 CompareUtils (com.b2international.commons.CompareUtils)1 LongSets (com.b2international.commons.collect.LongSets)1 Hits (com.b2international.index.Hits)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1