Search in sources :

Example 6 with SnomedRelationshipIndexEntry

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

the class TaxonomyPreCommitHookTest method updateStatedRelationshipDestination.

@Test
public void updateStatedRelationshipDestination() throws Exception {
    final SnomedConceptDocument sourceConcept = concept().build();
    final SnomedConceptDocument newDestinationConcept = concept(Concepts.NAMESPACE_ROOT).build();
    final long concept1Id = Long.parseLong(sourceConcept.getId());
    final long concept2Id = Long.parseLong(newDestinationConcept.getId());
    // register IDs for stated changes
    statedChangedConceptIds.add(ROOT_CONCEPTL);
    statedChangedConceptIds.add(concept1Id);
    statedChangedConceptIds.add(concept2Id);
    // prepare index repository state
    final SnomedRelationshipIndexEntry statedRelationship = createStatedRelationship(sourceConcept.getId(), Concepts.IS_A, Concepts.ROOT_CONCEPT);
    initRevisions(statedRelationship, docWithDefaults(sourceConcept).statedParents(ROOT_CONCEPTL).build(), docWithDefaults(newDestinationConcept).build());
    // change destination from ROOT to NEWDST
    stageChange(statedRelationship, SnomedRelationshipIndexEntry.builder(statedRelationship).destinationId(newDestinationConcept.getId()).build());
    final ConceptChangeProcessor processor = process();
    final SnomedConceptDocument expected = docWithDefaults(sourceConcept).iconId(Concepts.NAMESPACE_ROOT).statedParents(PrimitiveSets.newLongSortedSet(concept2Id)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build();
    assertEquals(1, processor.getChangedMappings().size());
    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) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

Example 7 with SnomedRelationshipIndexEntry

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

the class TaxonomyPreCommitHookTest method addIsaRelationshipToExistingConcepts.

@Test
public void addIsaRelationshipToExistingConcepts() throws Exception {
    // given a parent concept and child concept
    final SnomedConceptDocument parent = concept().build();
    final SnomedConceptDocument child = concept().build();
    final long parentIdLong = Long.parseLong(parent.getId());
    final long childIdLong = Long.parseLong(child.getId());
    statedChangedConceptIds.add(parentIdLong);
    statedChangedConceptIds.add(childIdLong);
    // index the child and parent concept documents as current state
    initRevisions(docWithDefaults(parent).build(), docWithDefaults(child).build());
    // add a new stated relationship between the two
    final SnomedRelationshipIndexEntry childToParentIsa = createStatedRelationship(child.getId(), Concepts.IS_A, parent.getId());
    stageNew(childToParentIsa);
    final ConceptChangeProcessor processor = process();
    // the child document should be reindexed with new parent information
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expectedDoc = docWithDefaults(child).statedParents(PrimitiveSets.newLongSortedSet(parentIdLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build();
    final Revision changedDoc = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
    assertDocEquals(expectedDoc, changedDoc);
    assertEquals(0, processor.getNewMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

Example 8 with SnomedRelationshipIndexEntry

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

the class TaxonomyPreCommitHookTest method indexStatedChild.

@Test
public void indexStatedChild() throws Exception {
    // add the ROOT concept as existing concept in the stated tree
    statedChangedConceptIds.add(ROOT_CONCEPTL);
    final SnomedConceptDocument concept = concept().build();
    stageNew(concept);
    final SnomedRelationshipIndexEntry relationship = createStatedRelationship(concept.getId(), Concepts.IS_A, Concepts.ROOT_CONCEPT);
    stageNew(relationship);
    final ConceptChangeProcessor processor = process();
    final SnomedConceptDocument expected = docWithDefaults(concept).statedParents(PrimitiveSets.newLongSortedSet(ROOT_CONCEPTL)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build();
    final Revision actual = Iterables.getOnlyElement(processor.getNewMappings().values());
    assertDocEquals(expected, actual);
    assertEquals(0, processor.getChangedMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

Example 9 with SnomedRelationshipIndexEntry

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

the class TaxonomyPreCommitHookTest method newInferredIsaRelationshipDoesNotChangeStatedTaxonomy.

@Test
public void newInferredIsaRelationshipDoesNotChangeStatedTaxonomy() throws Exception {
    // given a parent concept and child concept
    final SnomedConceptDocument parent = concept().build();
    final SnomedConceptDocument child = concept().build();
    final SnomedRelationshipIndexEntry statedIsa = createStatedRelationship(child.getId(), Concepts.IS_A, parent.getId());
    final long parentIdLong = Long.parseLong(parent.getId());
    final long childIdLong = Long.parseLong(child.getId());
    // index the child and parent concept documents as current state
    initRevisions(docWithDefaults(parent).build(), docWithDefaults(child).statedParents(PrimitiveSets.newLongSortedSet(parentIdLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build(), statedIsa);
    // add a new stated relationship between the two
    inferredChangedConceptIds.add(parentIdLong);
    inferredChangedConceptIds.add(childIdLong);
    final SnomedRelationshipIndexEntry childToParentIsa = createInferredRelationship(child.getId(), Concepts.IS_A, parent.getId());
    stageNew(childToParentIsa);
    final ConceptChangeProcessor processor = process();
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expected = docWithDefaults(child).statedParents(PrimitiveSets.newLongSortedSet(parentIdLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).parents(PrimitiveSets.newLongSortedSet(parentIdLong)).ancestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).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) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

Example 10 with SnomedRelationshipIndexEntry

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

the class TaxonomyPreCommitHookTest method deleteConceptWithOneStatedChild.

@Test
public void deleteConceptWithOneStatedChild() throws Exception {
    final long namespaceRootLong = Long.parseLong(Concepts.NAMESPACE_ROOT);
    // given a parent concept and child concept
    final SnomedConceptDocument parent = concept().build();
    final SnomedConceptDocument child = concept().build();
    availableImages.add(parent.getId());
    // and a stated relationship between the two
    final SnomedRelationshipIndexEntry childToParentIsa = createStatedRelationship(child.getId(), Concepts.IS_A, parent.getId());
    final SnomedRelationshipIndexEntry childToAnotherConceptIsa = createStatedRelationship(child.getId(), Concepts.IS_A, Concepts.NAMESPACE_ROOT);
    final long parentIdLong = Long.parseLong(parent.getId());
    final long childIdLong = Long.parseLong(child.getId());
    // index the child and parent concept documents as current state
    initRevisions(docWithDefaults(parent).build(), // child concept has stated parent and ROOT ancestor
    docWithDefaults(child).statedParents(PrimitiveSets.newLongSortedSet(parentIdLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build(), // index existing stated relationships
    childToParentIsa, childToAnotherConceptIsa);
    // delete parent concept and its single relationship
    stageRemove(parent);
    stageRemove(childToParentIsa);
    statedChangedConceptIds.add(parentIdLong);
    statedChangedConceptIds.add(childIdLong);
    statedChangedConceptIds.add(namespaceRootLong);
    final ConceptChangeProcessor processor = process();
    // the parent concept should be deleted, but handled by stageRemove
    assertEquals(0, processor.getDeletions().size());
    // and the child concept needs to be reindexed as child of the invisible ROOT ID
    assertEquals(1, processor.getChangedMappings().size());
    final Revision newChildRevision = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
    final SnomedConceptDocument expectedChildRevision = docWithDefaults(child).iconId(Concepts.NAMESPACE_ROOT).statedParents(PrimitiveSets.newLongSortedSet(namespaceRootLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build();
    assertDocEquals(expectedChildRevision, newChildRevision);
    // no new mappings were registered
    assertEquals(0, processor.getNewMappings().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Revision(com.b2international.index.revision.Revision) 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