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