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