Search in sources :

Example 1 with Hits

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

the class RevisionIndexReadRequest method execute.

@Override
public B execute(final BranchContext context) {
    final String branchPath = context.path();
    RevisionIndex index = context.service(RevisionIndex.class);
    if (snapshot) {
        return index.read(branchPath, searcher -> {
            try {
                return next(context.inject().bind(RevisionSearcher.class, searcher).build());
            } catch (QueryParseException e) {
                throw new IllegalQueryParameterException(e.getMessage());
            }
        });
    } else {
        return next(context.inject().bind(RevisionSearcher.class, new RevisionSearcher() {

            @Override
            public <T> Aggregation<T> aggregate(AggregationBuilder<T> aggregation) throws IOException {
                return index.read(branchPath, searcher -> searcher.aggregate(aggregation));
            }

            @Override
            public Searcher searcher() {
                return index.read(branchPath, searcher -> searcher.searcher());
            }

            @Override
            public <T> Hits<T> search(Query<T> query) throws IOException {
                return index.read(branchPath, searcher -> searcher.search(query));
            }

            @Override
            public <T> Iterable<T> get(Class<T> type, Iterable<String> keys) throws IOException {
                return index.read(branchPath, searcher -> searcher.get(type, keys));
            }

            @Override
            public <T> T get(Class<T> type, String key) throws IOException {
                return index.read(branchPath, searcher -> searcher.get(type, key));
            }

            @Override
            public String branch() {
                return branchPath;
            }
        }).build());
    }
}
Also used : Searcher(com.b2international.index.Searcher) Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) QueryParseException(com.b2international.index.query.QueryParseException) Request(com.b2international.snowowl.core.events.Request) IOException(java.io.IOException) Aggregation(com.b2international.index.aggregations.Aggregation) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) AggregationBuilder(com.b2international.index.aggregations.AggregationBuilder) RevisionIndex(com.b2international.index.revision.RevisionIndex) DelegatingRequest(com.b2international.snowowl.core.events.DelegatingRequest) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Hits(com.b2international.index.Hits) RevisionIndex(com.b2international.index.revision.RevisionIndex) Searcher(com.b2international.index.Searcher) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) IOException(java.io.IOException) QueryParseException(com.b2international.index.query.QueryParseException) Aggregation(com.b2international.index.aggregations.Aggregation) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Example 2 with Hits

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

the class SnomedVersioningRequest method doVersionComponents.

@Override
protected void doVersionComponents(TransactionContext context) throws Exception {
    final Logger log = context.service(Logger.class);
    log.info("Publishing SNOMED CT components [effectiveTime: {}]...", EffectiveTimes.format(config().getEffectiveTime()));
    // sourceModuleId to targetModuleId map
    final Multimap<String, String> componentIdsByReferringModule = HashMultimap.create();
    final RevisionSearcher searcher = context.service(RevisionSearcher.class);
    final Stream<Hits<? extends SnomedDocument>> documentsToVersion = Streams.concat(Query.select(SnomedConceptDocument.class).where(SnomedDocument.Expressions.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME)).limit(getCommitLimit(context)).build().stream(searcher), Query.select(SnomedDescriptionIndexEntry.class).where(SnomedDocument.Expressions.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME)).limit(getCommitLimit(context)).build().stream(searcher), Query.select(SnomedRelationshipIndexEntry.class).where(SnomedDocument.Expressions.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME)).limit(getCommitLimit(context)).build().stream(searcher), Query.select(SnomedRefSetMemberIndexEntry.class).where(SnomedDocument.Expressions.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME)).limit(getCommitLimit(context)).build().stream(searcher));
    documentsToVersion.forEachOrdered(componentsToVersion -> versionComponents(context, componentsToVersion, componentIdsByReferringModule));
    // iterate over each module and get modules of all components registered to componentsByReferringModule
    log.info("Collecting module dependencies of changed components...");
    final Multimap<String, String> moduleDependencies = HashMultimap.create();
    final Map<String, Long> moduleToLatestEffectiveTime = newHashMap();
    for (String module : ImmutableSet.copyOf(componentIdsByReferringModule.keySet())) {
        final Collection<String> dependencies = componentIdsByReferringModule.removeAll(module);
        for (Class<? extends SnomedComponentDocument> type : CORE_COMPONENT_TYPES) {
            Query.select(String[].class).from(type).fields(SnomedComponentDocument.Fields.ID, SnomedComponentDocument.Fields.MODULE_ID, SnomedComponentDocument.Fields.EFFECTIVE_TIME).where(SnomedComponentDocument.Expressions.ids(dependencies)).limit(10000).build().stream(searcher).flatMap(Hits::stream).forEachOrdered(dependency -> {
                String targetModule = dependency[1];
                if (!module.equals(targetModule)) {
                    moduleDependencies.put(module, targetModule);
                }
                moduleToLatestEffectiveTime.merge(targetModule, Long.parseLong(dependency[2]), (oldEffectiveTime, newEffectiveTime) -> {
                    if (oldEffectiveTime == EffectiveTimes.UNSET_EFFECTIVE_TIME || newEffectiveTime == EffectiveTimes.UNSET_EFFECTIVE_TIME) {
                        return EffectiveTimes.UNSET_EFFECTIVE_TIME;
                    } else {
                        return Math.max(oldEffectiveTime, newEffectiveTime);
                    }
                });
            });
        }
    }
    log.info("Collecting module dependencies of changed components successfully finished.");
    log.info("Adjusting effective time changes on module dependency...");
    adjustDependencyRefSetMembers(context, moduleDependencies, moduleToLatestEffectiveTime, effectiveTime);
    log.info("Effective time adjustment successfully finished on module dependency.");
}
Also used : Hits(com.b2international.index.Hits) Logger(org.slf4j.Logger) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Example 3 with Hits

use of com.b2international.index.Hits 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();
}
Also used : Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) LoggerFactory(org.slf4j.LoggerFactory) LongCollections(com.b2international.collections.longs.LongCollections) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Expressions.typeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.typeId) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ImmutableList(com.google.common.collect.ImmutableList) LongSets(com.b2international.commons.collect.LongSets) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) CompareUtils(com.b2international.commons.CompareUtils) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedOWLRelationshipDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument) Logger(org.slf4j.Logger) LongIterator(com.b2international.collections.longs.LongIterator) LongCollection(com.b2international.collections.longs.LongCollection) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) Expressions.characteristicTypeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.characteristicTypeId) Expressions.sourceIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.sourceIds) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Expressions.destinationIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.destinationIds) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) StagingArea(com.b2international.index.revision.StagingArea) IComponent(com.b2international.snowowl.core.domain.IComponent) Collections(java.util.Collections) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff)

Example 4 with Hits

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

the class Taxonomies method getStatements.

private static Collection<Object[]> getStatements(RevisionSearcher searcher, LongCollection conceptIds, String characteristicTypeId, boolean filterByConceptIds) throws IOException {
    // merge stated relationships and OWL axiom relationships into a single array
    ImmutableList.Builder<Object[]> isaStatementsBuilder = ImmutableList.builder();
    final Set<String> concepts = LongSets.toStringSet(conceptIds);
    ExpressionBuilder activeIsaRelationshipQuery = Expressions.builder().filter(active()).filter(typeId(Concepts.IS_A)).filter(characteristicTypeId(characteristicTypeId));
    if (filterByConceptIds) {
        activeIsaRelationshipQuery.filter(sourceIds(concepts)).filter(destinationIds(concepts));
    }
    final Query<String[]> activeStatedISARelationshipsQuery = Query.select(String[].class).from(SnomedRelationshipIndexEntry.class).fields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.DESTINATION_ID).where(activeIsaRelationshipQuery.build()).limit(Integer.MAX_VALUE).build();
    Hits<String[]> activeIsaRelationships = searcher.search(activeStatedISARelationshipsQuery);
    activeIsaRelationships.forEach(activeIsaRelationship -> {
        isaStatementsBuilder.add(new Object[] { activeIsaRelationship[0], Long.parseLong(activeIsaRelationship[1]), new long[] { Long.parseLong(activeIsaRelationship[2]) } });
    });
    activeIsaRelationships = null;
    if (Concepts.STATED_RELATIONSHIP.equals(characteristicTypeId)) {
        // search existing axioms defined for the given set of conceptIds
        ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active());
        if (filterByConceptIds) {
            activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(concepts)).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, Expressions.builder().filter(typeId(Concepts.IS_A)).filter(destinationIds(concepts)).build()));
        } else {
            activeOwlAxiomMemberQuery.filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, Expressions.builder().filter(typeId(Concepts.IS_A)).build()));
        }
        final Query<SnomedRefSetMemberIndexEntry> activeAxiomISARelationshipsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(Integer.MAX_VALUE).build();
        Hits<SnomedRefSetMemberIndexEntry> activeAxiomISARelationships = searcher.search(activeAxiomISARelationshipsQuery);
        activeAxiomISARelationships.forEach(owlMember -> {
            if (!CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())) {
                // XXX: breaks with a NumberFormatException if any of the IS A relationships has a value
                long[] destinationIds = owlMember.getClassAxiomRelationships().stream().filter(classAxiom -> Concepts.IS_A.equals(classAxiom.getTypeId())).map(SnomedOWLRelationshipDocument::getDestinationId).mapToLong(Long::parseLong).toArray();
                isaStatementsBuilder.add(new Object[] { owlMember.getId(), Long.parseLong(owlMember.getReferencedComponentId()), destinationIds });
            }
        });
        activeAxiomISARelationships = null;
    }
    return isaStatementsBuilder.build();
}
Also used : Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) LoggerFactory(org.slf4j.LoggerFactory) LongCollections(com.b2international.collections.longs.LongCollections) SnomedOWLExpressionConverterResult(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverterResult) Expressions.typeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.typeId) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ImmutableList(com.google.common.collect.ImmutableList) LongSets(com.b2international.commons.collect.LongSets) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) CompareUtils(com.b2international.commons.CompareUtils) RevisionPropertyDiff(com.b2international.index.revision.StagingArea.RevisionPropertyDiff) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedOWLRelationshipDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument) Logger(org.slf4j.Logger) LongIterator(com.b2international.collections.longs.LongIterator) LongCollection(com.b2international.collections.longs.LongCollection) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) SnomedOWLExpressionConverter(com.b2international.snowowl.snomed.datastore.request.SnomedOWLExpressionConverter) Expressions.characteristicTypeId(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.characteristicTypeId) Expressions.sourceIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.sourceIds) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Expressions.destinationIds(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions.destinationIds) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) StagingArea(com.b2international.index.revision.StagingArea) IComponent(com.b2international.snowowl.core.domain.IComponent) Collections(java.util.Collections) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedOWLRelationshipDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument) ImmutableList(com.google.common.collect.ImmutableList) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)

Example 5 with Hits

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

the class SnomedValidationIssueDetailExtension method extendRelationshipIssueLabels.

private void extendRelationshipIssueLabels(BranchContext context, Collection<ValidationIssue> issues, Map<String, Object> ruleParameters) {
    final RevisionSearcher searcher = context.service(RevisionSearcher.class);
    final List<ValidationIssue> relationshipIssues = issues.stream().filter(issue -> SnomedRelationship.TYPE == issue.getAffectedComponent().getComponentType()).collect(Collectors.toList());
    if (relationshipIssues.isEmpty()) {
        return;
    }
    final Multimap<String, ValidationIssue> issuesByRelationshipId = Multimaps.index(relationshipIssues, issue -> issue.getAffectedComponent().getComponentId());
    final Set<String> conceptsToFetch = newHashSet();
    final Map<String, String> relationshipFragmentsByRelationshipId = Maps.newHashMap();
    searcher.stream(Query.select(String[].class).from(SnomedRelationshipIndexEntry.class).fields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.TYPE_ID, SnomedRelationshipIndexEntry.Fields.DESTINATION_ID, SnomedRelationshipIndexEntry.Fields.VALUE_TYPE, SnomedRelationshipIndexEntry.Fields.NUMERIC_VALUE, SnomedRelationshipIndexEntry.Fields.STRING_VALUE).where(SnomedRelationshipIndexEntry.Expressions.ids(issuesByRelationshipId.keySet())).limit(SCROLL_SIZE).build()).forEach(hits -> {
        for (String[] hit : hits) {
            final String id = hit[0];
            final String sourceId = hit[1];
            final String typeId = hit[2];
            final String destinationId = hit[3];
            final String valueType = hit[4];
            final String numericValue = hit[5];
            final String stringValue = hit[6];
            String destination = "";
            conceptsToFetch.add(sourceId);
            conceptsToFetch.add(typeId);
            if (!Strings.isNullOrEmpty(destinationId)) {
                conceptsToFetch.add(destinationId);
                destination = destinationId;
            } else {
                if (RelationshipValueType.DECIMAL.name().equals(valueType) || RelationshipValueType.INTEGER.name().equals(valueType)) {
                    destination = DecimalUtils.decode(numericValue).toString();
                } else if (RelationshipValueType.STRING.name().equals(valueType)) {
                    destination = stringValue;
                }
            }
            relationshipFragmentsByRelationshipId.put(id, String.format("%s|%s|%s", sourceId, typeId, destination));
        }
    });
    Map<String, String> affectedComponentLabelsByConcept = getAffectedComponentLabels(context, ruleParameters, conceptsToFetch);
    if (!affectedComponentLabelsByConcept.isEmpty()) {
        issuesByRelationshipId.values().forEach(issue -> {
            final String[] relationshipFragments = relationshipFragmentsByRelationshipId.get(issue.getAffectedComponent().getComponentId()).split("[|]");
            final String sourceId = relationshipFragments[0];
            final String typeId = relationshipFragments[1];
            final String destinationIdOrValue = relationshipFragments[2];
            final String sourceTerm = affectedComponentLabelsByConcept.getOrDefault(sourceId, sourceId);
            final String typeTerm = affectedComponentLabelsByConcept.getOrDefault(typeId, typeId);
            final String destinationTerm = affectedComponentLabelsByConcept.getOrDefault(destinationIdOrValue, destinationIdOrValue);
            issue.setAffectedComponentLabels(ImmutableList.of(String.format("%s - %s - %s", sourceTerm, typeTerm, destinationTerm)));
        });
    }
}
Also used : EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) RelationshipValueType(com.b2international.snowowl.snomed.core.domain.RelationshipValueType) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) java.util(java.util) Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) QueryBuilder(com.b2international.index.query.Query.QueryBuilder) SET_MEMBER(com.b2international.snowowl.core.terminology.ComponentCategory.SET_MEMBER) ValidationIssueDetailExtension(com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtension) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedDescriptionUtils(com.b2international.snowowl.snomed.datastore.SnomedDescriptionUtils) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) com.b2international.snowowl.snomed.datastore.index.entry(com.b2international.snowowl.snomed.datastore.index.entry) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) com.google.common.collect(com.google.common.collect) CONCEPT(com.b2international.snowowl.core.terminology.ComponentCategory.CONCEPT) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) Collectors(java.util.stream.Collectors) SnomedIssueDetailFilterFields(com.b2international.snowowl.snomed.validation.detail.SnomedValidationIssueDetailExtension.SnomedIssueDetailFilterFields) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) DESCRIPTION(com.b2international.snowowl.core.terminology.ComponentCategory.DESCRIPTION) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Expressions(com.b2international.index.query.Expressions) DecimalUtils(com.b2international.index.util.DecimalUtils) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) ValidationConfiguration(com.b2international.snowowl.core.internal.validation.ValidationConfiguration) RELATIONSHIP(com.b2international.snowowl.core.terminology.ComponentCategory.RELATIONSHIP) Expression(com.b2international.index.query.Expression) Component(com.b2international.snowowl.core.plugin.Component) Builder(com.google.common.collect.ImmutableMultimap.Builder) BranchContext(com.b2international.snowowl.core.domain.BranchContext) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Aggregations

Hits (com.b2international.index.Hits)6 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)6 Query (com.b2international.index.query.Query)5 Expressions (com.b2international.index.query.Expressions)4 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)4 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)4 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)4 BranchContext (com.b2international.snowowl.core.domain.BranchContext)3 IOException (java.io.IOException)3 Logger (org.slf4j.Logger)3 LongCollection (com.b2international.collections.longs.LongCollection)2 LongCollections (com.b2international.collections.longs.LongCollections)2 LongIterator (com.b2international.collections.longs.LongIterator)2 CompareUtils (com.b2international.commons.CompareUtils)2 LongSets (com.b2international.commons.collect.LongSets)2 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)2 StagingArea (com.b2international.index.revision.StagingArea)2 RevisionPropertyDiff (com.b2international.index.revision.StagingArea.RevisionPropertyDiff)2 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)2 IComponent (com.b2international.snowowl.core.domain.IComponent)2