Search in sources :

Example 31 with Revision

use of com.b2international.index.revision.Revision 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)

Example 32 with Revision

use of com.b2international.index.revision.Revision in project snow-owl by b2ihealthcare.

the class ConceptChangeProcessorAxiomTest method deleteEmpty.

@Test
public void deleteEmpty() throws Exception {
    final SnomedConceptDocument concept = concept().activeMemberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).memberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).build();
    final SnomedRefSetMemberIndexEntry member = createOwlAxiom(concept.getId(), "").build();
    indexRevision(MAIN, concept, member);
    stageRemove(member);
    final ConceptChangeProcessor processor = process();
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expected = docWithDefaults(concept).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) Test(org.junit.Test)

Example 33 with Revision

use of com.b2international.index.revision.Revision in project snow-owl by b2ihealthcare.

the class ConceptChangeProcessorAxiomTest method newSubClassOfAxiom_TwoTargets.

@Test
public void newSubClassOfAxiom_TwoTargets() throws Exception {
    SnomedConceptDocument concept = concept().build();
    SnomedConceptDocument parentConcept = concept().build();
    SnomedConceptDocument parentConcept2 = concept().build();
    indexRevision(MAIN, concept, parentConcept, parentConcept2);
    statedChangedConceptIds.add(Long.parseLong(concept.getId()));
    statedChangedConceptIds.add(Long.parseLong(parentConcept.getId()));
    statedChangedConceptIds.add(Long.parseLong(parentConcept2.getId()));
    SnomedRefSetMemberIndexEntry member = createOwlAxiom(concept.getId(), String.format("SubClassOf(:%s ObjectIntersectionOf(:%s :%s))", concept.getId(), parentConcept.getId(), parentConcept2.getId())).build();
    stageNew(member);
    final ConceptChangeProcessor processor = process();
    assertEquals(1, processor.getChangedMappings().size());
    final SnomedConceptDocument expected = docWithDefaults(concept).statedParents(Long.parseLong(parentConcept.getId()), Long.parseLong(parentConcept2.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) Test(org.junit.Test)

Example 34 with Revision

use of com.b2international.index.revision.Revision in project snow-owl by b2ihealthcare.

the class ConceptChangeProcessorAxiomTest method updateEmptyAxiom.

@Test
public void updateEmptyAxiom() throws Exception {
    SnomedConceptDocument concept = concept().activeMemberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).memberOf(Collections.singleton(Concepts.REFSET_OWL_AXIOM)).build();
    SnomedConceptDocument parentConcept = concept().build();
    SnomedRefSetMemberIndexEntry member = createOwlAxiom(concept.getId(), "").build();
    indexRevision(MAIN, concept, parentConcept, member);
    statedChangedConceptIds.add(Long.parseLong(concept.getId()));
    statedChangedConceptIds.add(Long.parseLong(parentConcept.getId()));
    // update axiom
    stageChange(member, SnomedRefSetMemberIndexEntry.builder(member).owlExpression(String.format("SubClassOf(:%s :%s)", concept.getId(), parentConcept.getId())).build());
    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) Test(org.junit.Test)

Example 35 with Revision

use of com.b2international.index.revision.Revision 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)

Aggregations

Revision (com.b2international.index.revision.Revision)55 Test (org.junit.Test)51 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)38 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)32 SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)30 SnomedDescriptionFragment (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment)20 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)13 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)4 StagingArea (com.b2international.index.revision.StagingArea)4 ChangeSetProcessorBase (com.b2international.snowowl.core.repository.ChangeSetProcessorBase)4 RefSetMemberChange (com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange)4 ReferenceSetMembershipUpdater (com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater)4 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)4 IOException (java.io.IOException)4 Collectors (java.util.stream.Collectors)4 Acceptability (com.b2international.snowowl.snomed.core.domain.Acceptability)3 com.google.common.collect (com.google.common.collect)3 LongSets (com.b2international.commons.collect.LongSets)2 ObjectId (com.b2international.index.revision.ObjectId)2 RevisionDiff (com.b2international.index.revision.StagingArea.RevisionDiff)2