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