Search in sources :

Example 11 with SnomedRelationshipIndexEntry

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

the class SnomedRelationshipUpdateRequest method execute.

@Override
public Boolean execute(final TransactionContext context) {
    if (!Strings.isNullOrEmpty(destinationId) && value != null) {
        throw new BadRequestException("'destinationId' and 'value' can not be updated at same time");
    }
    final SnomedRelationshipIndexEntry relationship = context.lookup(componentId(), SnomedRelationshipIndexEntry.class);
    final SnomedRelationshipIndexEntry.Builder updatedRelationship = SnomedRelationshipIndexEntry.builder(relationship);
    boolean changed = false;
    changed |= updateStatus(context, relationship, updatedRelationship);
    changed |= updateModuleId(context, relationship, updatedRelationship);
    changed |= updateTypeId(context, relationship, updatedRelationship);
    changed |= updateDestinationId(context, relationship, updatedRelationship);
    changed |= updateValue(context, relationship, updatedRelationship);
    changed |= updateGroup(context, relationship, updatedRelationship);
    changed |= updateUnionGroup(context, relationship, updatedRelationship);
    changed |= updateCharacteristicTypeId(context, relationship, updatedRelationship);
    changed |= updateModifierId(context, relationship, updatedRelationship);
    changed |= updateEffectiveTime(relationship, updatedRelationship);
    if (changed) {
        if (!isEffectiveTimeUpdate() && relationship.getEffectiveTime() != EffectiveTimes.UNSET_EFFECTIVE_TIME) {
            updatedRelationship.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME);
        }
        context.update(relationship, updatedRelationship.build());
    }
    return changed;
}
Also used : SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 12 with SnomedRelationshipIndexEntry

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

the class Taxonomies method updateTaxonomy.

private static TaxonomyGraphStatus updateTaxonomy(RevisionSearcher searcher, SnomedOWLExpressionConverter expressionConverter, StagingArea staging, TaxonomyGraph graphToUpdate, String characteristicTypeId) throws IOException {
    LOGGER.trace("Processing changes taxonomic information.");
    staging.getNewObjects(SnomedRelationshipIndexEntry.class).filter(relationship -> characteristicTypeId.equals(relationship.getCharacteristicTypeId())).forEach(newRelationship -> updateEdge(newRelationship, graphToUpdate));
    final Set<String> relationshipsToExcludeFromReactivatedConcepts = newHashSet();
    staging.getChangedRevisions(SnomedRelationshipIndexEntry.class).map(diff -> (SnomedRelationshipIndexEntry) diff.newRevision).filter(relationship -> characteristicTypeId.equals(relationship.getCharacteristicTypeId())).forEach(dirtyRelationship -> {
        relationshipsToExcludeFromReactivatedConcepts.add(dirtyRelationship.getId());
        updateEdge(dirtyRelationship, graphToUpdate);
    });
    staging.getRemovedObjects(SnomedRelationshipIndexEntry.class).filter(relationship -> characteristicTypeId.equals(relationship.getCharacteristicTypeId())).forEach(relationship -> {
        relationshipsToExcludeFromReactivatedConcepts.add(relationship.getId());
        graphToUpdate.removeEdge(relationship.getId());
    });
    if (Concepts.STATED_RELATIONSHIP.equals(characteristicTypeId)) {
        staging.getNewObjects(SnomedRefSetMemberIndexEntry.class).filter(member -> SnomedRefSetType.OWL_AXIOM == member.getReferenceSetType()).forEach(member -> updateEdge(member, graphToUpdate, expressionConverter));
        staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).map(diff -> (SnomedRefSetMemberIndexEntry) diff.newRevision).filter(member -> SnomedRefSetType.OWL_AXIOM == member.getReferenceSetType()).forEach(member -> updateEdge(member, graphToUpdate, expressionConverter));
        staging.getRemovedObjects(SnomedRefSetMemberIndexEntry.class).filter(member -> SnomedRefSetType.OWL_AXIOM == member.getReferenceSetType()).map(SnomedRefSetMemberIndexEntry::getId).forEach(graphToUpdate::removeEdge);
    }
    staging.getNewObjects(SnomedConceptDocument.class).forEach(newConcept -> updateConcept(newConcept, graphToUpdate));
    staging.getRemovedObjects(SnomedConceptDocument.class).forEach(concept -> graphToUpdate.removeNode(concept.getId()));
    final Set<String> conceptWithPossibleMissingRelationships = newHashSet();
    staging.getChangedRevisions(SnomedConceptDocument.class, Collections.singleton(SnomedConceptDocument.Fields.ACTIVE)).forEach(diff -> {
        final RevisionPropertyDiff propDiff = diff.getRevisionPropertyDiff(SnomedConceptDocument.Fields.ACTIVE);
        final boolean oldValue = Boolean.parseBoolean(propDiff.getOldValue());
        final boolean newValue = Boolean.parseBoolean(propDiff.getNewValue());
        final String conceptId = diff.newRevision.getId();
        if (!oldValue && newValue) {
            // make sure the node is part of the new tree
            graphToUpdate.addNode(conceptId);
            conceptWithPossibleMissingRelationships.add(conceptId);
        }
    });
    if (!conceptWithPossibleMissingRelationships.isEmpty()) {
        Hits<String[]> possibleMissingRelationships = searcher.search(Query.select(String[].class).from(SnomedRelationshipIndexEntry.class).fields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.DESTINATION_ID).where(Expressions.builder().filter(SnomedRelationshipIndexEntry.Expressions.active()).filter(SnomedRelationshipIndexEntry.Expressions.characteristicTypeId(characteristicTypeId)).filter(SnomedRelationshipIndexEntry.Expressions.typeId(Concepts.IS_A)).filter(SnomedRelationshipIndexEntry.Expressions.sourceIds(conceptWithPossibleMissingRelationships)).mustNot(SnomedRelationshipIndexEntry.Expressions.ids(relationshipsToExcludeFromReactivatedConcepts)).build()).limit(Integer.MAX_VALUE).build());
        for (String[] relationship : possibleMissingRelationships) {
            graphToUpdate.addNode(relationship[2]);
            graphToUpdate.addEdge(relationship[0], Long.parseLong(relationship[1]), new long[] { Long.parseLong(relationship[2]) });
        }
    }
    LOGGER.trace("Rebuilding taxonomic information based on the changes.");
    return graphToUpdate.update();
}
Also used : Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) LoggerFactory(org.slf4j.LoggerFactory) LongCollections(com.b2international.collections.longs.LongCollections) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Expressions.typeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.typeId) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ImmutableList(com.google.common.collect.ImmutableList) LongSets(com.b2international.commons.collect.LongSets) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) CompareUtils(com.b2international.commons.CompareUtils) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedOWLRelationshipDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument) Logger(org.slf4j.Logger) LongIterator(com.b2international.collections.longs.LongIterator) LongCollection(com.b2international.collections.longs.LongCollection) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) Expressions.characteristicTypeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.characteristicTypeId) Expressions.sourceIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.sourceIds) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Expressions.destinationIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.destinationIds) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) StagingArea(com.b2international.index.revision.StagingArea) IComponent(com.b2international.snowowl.core.domain.IComponent) Collections(java.util.Collections) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff)

Example 13 with SnomedRelationshipIndexEntry

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

the class ConceptChangeProcessorAxiomTest method inactivateIsa_AddSubClassOf.

@Test
public void inactivateIsa_AddSubClassOf() throws Exception {
    final SnomedConceptDocument parentConcept = concept().build();
    final SnomedConceptDocument concept = concept().statedParents(Long.parseLong(parentConcept.getId())).statedAncestors(IComponent.ROOT_IDL).build();
    SnomedRelationshipIndexEntry isaRelationship = createStatedRelationship(concept.getId(), Concepts.IS_A, parentConcept.getId());
    indexRevision(MAIN, concept, parentConcept, isaRelationship);
    statedChangedConceptIds.add(Long.parseLong(concept.getId()));
    statedChangedConceptIds.add(Long.parseLong(parentConcept.getId()));
    stageChange(isaRelationship, SnomedRelationshipIndexEntry.builder(isaRelationship).active(false).build());
    SnomedRefSetMemberIndexEntry member = createOwlAxiom(concept.getId(), String.format("SubClassOf(:%s :%s)", concept.getId(), parentConcept.getId())).build();
    stageNew(member);
    final ConceptChangeProcessor processor = process();
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expected = docWithDefaults(concept).statedParents(Long.parseLong(parentConcept.getId())).statedAncestors(IComponent.ROOT_IDL).activeMemberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).memberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).build();
    final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
    assertDocEquals(expected, actual);
    assertEquals(0, processor.getNewMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) 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 14 with SnomedRelationshipIndexEntry

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

the class RelationshipChangeProcessorTest method deleteMemberOfExistingRelationship.

@Test
public void deleteMemberOfExistingRelationship() {
    final SnomedRelationshipIndexEntry relationship = createRandomRelationship();
    final String referringRefSetId = generateConceptId();
    final SnomedRefSetMemberIndexEntry member = simpleMember(relationship.getId(), referringRefSetId);
    initRevisions(SnomedRelationshipIndexEntry.builder(relationship).memberOf(ImmutableList.of(referringRefSetId)).activeMemberOf(ImmutableList.of(referringRefSetId)).build(), member);
    stageRemove(member);
    process(processor);
    final SnomedRelationshipIndexEntry expectedDoc = SnomedRelationshipIndexEntry.builder(relationship).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 15 with SnomedRelationshipIndexEntry

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

the class RelationshipChangeProcessorTest method detachedRelationship.

@Test
public void detachedRelationship() throws Exception {
    final SnomedRelationshipIndexEntry relationship = createRandomRelationship();
    indexRevision(MAIN, SnomedRelationshipIndexEntry.builder(relationship).build());
    stageRemove(relationship);
    process(processor);
    assertEquals(0, processor.getNewMappings().size());
    assertEquals(0, processor.getChangedMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

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