Search in sources :

Example 1 with Builder

use of com.google.common.collect.ImmutableMultimap.Builder in project snow-owl by b2ihealthcare.

the class SnomedValidationIssueDetailExtension method extendConceptIssueLabels.

private void extendConceptIssueLabels(BranchContext context, Collection<ValidationIssue> issues, Map<String, Object> ruleParameters) {
    final RevisionSearcher searcher = context.service(RevisionSearcher.class);
    final List<ValidationIssue> conceptIssues = issues.stream().filter(issue -> SnomedConcept.TYPE == issue.getAffectedComponent().getComponentType()).collect(Collectors.toList());
    final Map<String, ValidationIssue> memberIssues = issues.stream().filter(issue -> SnomedReferenceSetMember.TYPE == issue.getAffectedComponent().getComponentType()).collect(Collectors.toMap(issue -> issue.getAffectedComponent().getComponentId(), issue -> issue, (issue1, issue2) -> issue1));
    if (conceptIssues.isEmpty() && memberIssues.isEmpty()) {
        return;
    }
    final Builder<String, ValidationIssue> issuesByConceptId = ImmutableMultimap.builder();
    conceptIssues.forEach(issue -> issuesByConceptId.put(issue.getAffectedComponent().getComponentId(), issue));
    searcher.stream(Query.select(String[].class).from(SnomedRefSetMemberIndexEntry.class).fields(SnomedRefSetMemberIndexEntry.Fields.ID, SnomedRefSetMemberIndexEntry.Fields.REFERENCED_COMPONENT_ID).where(Expressions.builder().filter(SnomedRefSetMemberIndexEntry.Expressions.active()).filter(SnomedRefSetMemberIndexEntry.Expressions.ids(memberIssues.keySet())).build()).limit(SCROLL_SIZE).build()).forEach(hits -> {
        for (String[] hit : hits) {
            final String memberId = hit[0];
            final String containerConcpetId = hit[1];
            issuesByConceptId.put(containerConcpetId, memberIssues.get(memberId));
        }
    });
    final Multimap<String, ValidationIssue> issuesByConceptMap = issuesByConceptId.build();
    final Map<String, String> affectedComponentLabelsByConcept = getAffectedComponentLabels(context, ruleParameters, issuesByConceptMap.keySet());
    if (!affectedComponentLabelsByConcept.isEmpty()) {
        issuesByConceptMap.keySet().forEach(conceptId -> {
            issuesByConceptMap.get(conceptId).forEach(issue -> {
                issue.setAffectedComponentLabels(ImmutableList.of(affectedComponentLabelsByConcept.get(conceptId)));
            });
        });
    }
}
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

ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Options (com.b2international.commons.options.Options)1 Hits (com.b2international.index.Hits)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 Query (com.b2international.index.query.Query)1 QueryBuilder (com.b2international.index.query.Query.QueryBuilder)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 DecimalUtils (com.b2international.index.util.DecimalUtils)1 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 ValidationConfiguration (com.b2international.snowowl.core.internal.validation.ValidationConfiguration)1 Component (com.b2international.snowowl.core.plugin.Component)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 CONCEPT (com.b2international.snowowl.core.terminology.ComponentCategory.CONCEPT)1 DESCRIPTION (com.b2international.snowowl.core.terminology.ComponentCategory.DESCRIPTION)1 RELATIONSHIP (com.b2international.snowowl.core.terminology.ComponentCategory.RELATIONSHIP)1 SET_MEMBER (com.b2international.snowowl.core.terminology.ComponentCategory.SET_MEMBER)1 ValidationIssue (com.b2international.snowowl.core.validation.issue.ValidationIssue)1