Search in sources :

Example 1 with SnomedComponentDocument

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

the class DetachedContainerChangeProcessor method process.

@Override
public void process(StagingArea staging, RevisionSearcher searcher) throws IOException {
    final Set<String> deletedCoreComponentIds = newHashSet();
    final Set<String> deletedConceptIds = newHashSet();
    staging.getRemovedObjects().forEach(detachedObject -> {
        if (detachedObject instanceof SnomedComponentDocument) {
            String id = ((SnomedComponentDocument) detachedObject).getId();
            deletedCoreComponentIds.add(id);
            if (detachedObject instanceof SnomedConceptDocument) {
                deletedConceptIds.add(id);
            }
        }
    });
    if (deletedCoreComponentIds.isEmpty() && deletedConceptIds.isEmpty()) {
        return;
    }
    // deleting concepts should delete all of its descriptions, relationships, and inbound relationships
    Query.select(SnomedDescriptionIndexEntry.class).where(SnomedDescriptionIndexEntry.Expressions.concepts(deletedConceptIds)).limit(PAGE_SIZE).build().stream(searcher).flatMap(Hits::stream).forEachOrdered(description -> {
        deletedCoreComponentIds.add(description.getId());
        stageRemove(description);
    });
    Query.select(SnomedRelationshipIndexEntry.class).where(Expressions.builder().should(SnomedRelationshipIndexEntry.Expressions.sourceIds(deletedConceptIds)).should(SnomedRelationshipIndexEntry.Expressions.destinationIds(deletedConceptIds)).build()).limit(PAGE_SIZE).build().stream(searcher).flatMap(Hits::stream).forEachOrdered(relationship -> {
        deletedCoreComponentIds.add(relationship.getId());
        stageRemove(relationship);
    });
    // deleting core components should delete all referring members as well
    ExpressionBuilder referringMembersQuery = Expressions.builder().should(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(deletedCoreComponentIds)).should(SnomedRefSetMemberIndexEntry.Expressions.refsetIds(deletedConceptIds));
    SnomedRf2Headers.MEMBER_FIELDS_WITH_COMPONENT_ID.forEach(memberField -> {
        referringMembersQuery.should(Expressions.matchAny(memberField, deletedCoreComponentIds));
    });
    Query.select(SnomedRefSetMemberIndexEntry.class).where(referringMembersQuery.build()).limit(PAGE_SIZE).build().stream(searcher).flatMap(Hits::stream).forEachOrdered(member -> stageRemove(member));
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedComponentDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedComponentDocument) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Aggregations

ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 SnomedComponentDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedComponentDocument)1 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)1