private void setAssigneesStatistics(DbSession dbSession, NewIssuesStatistics.Stats stats) { Metric metric = Metric.ASSIGNEE; List<Map.Entry<String, MetricStatsInt>> entries = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); Set<String> assigneeUuids = entries.stream().map(Map.Entry::getKey).filter(Objects::nonNull).collect(toSet()); Map<String, UserDto> userDtoByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, u -> u)); int i = 1; for (Map.Entry<String, MetricStatsInt> assigneeStats : entries) { String assigneeUuid = assigneeStats.getKey(); UserDto user = userDtoByUuid.get(assigneeUuid); String name = user == null ? assigneeUuid : user.getName(); setFieldValue(metric + DOT + i + LABEL, name); setFieldValue(metric + DOT + i + COUNT, String.valueOf(assigneeStats.getValue().getOnLeak())); i++; } }
private void setTagsStatistics(NewIssuesStatistics.Stats stats) { Metric metric = Metric.TAG; int i = 1; for (Map.Entry<String, MetricStatsInt> tagStats : fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak)) { setFieldValue(metric + DOT + i + COUNT, String.valueOf(tagStats.getValue().getOnLeak())); setFieldValue(metric + DOT + i + LABEL, tagStats.getKey()); i++; } }
private void setComponentsStatistics(DbSession dbSession, NewIssuesStatistics.Stats stats) { Metric metric = Metric.COMPONENT; int i = 1; List<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); Set<String> componentUuids = fiveBiggest .stream() .map(Map.Entry::getKey) .collect(MoreCollectors.toSet(fiveBiggest.size())); Map<String, ComponentDto> componentDtosByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids) .stream() .collect(MoreCollectors.uniqueIndex(ComponentDto::uuid)); for (Map.Entry<String, MetricStatsInt> componentStats : fiveBiggest) { String uuid = componentStats.getKey(); String componentName = Optional.ofNullable(componentDtosByUuid.get(uuid)) .map(ComponentDto::name) .orElseThrow(() -> new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid))); setFieldValue(metric + DOT + i + LABEL, componentName); setFieldValue(metric + DOT + i + COUNT, String.valueOf(componentStats.getValue().getOnLeak())); i++; } }
private void setRuleStatistics(DbSession dbSession, NewIssuesStatistics.Stats stats) { Metric metric = Metric.RULE; List<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); Set<RuleKey> ruleKeys = fiveBiggest .stream() .map(Map.Entry::getKey) .map(RuleKey::parse) .collect(MoreCollectors.toSet(fiveBiggest.size())); Map<String, RuleDefinitionDto> ruleByRuleKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys) .stream() .collect(MoreCollectors.uniqueIndex(s -> s.getKey().toString())); int i = 1; for (Map.Entry<String, MetricStatsInt> ruleStats : fiveBiggest) { String ruleKey = ruleStats.getKey(); RuleDefinitionDto rule = Optional.ofNullable(ruleByRuleKey.get(ruleKey)) .orElseThrow(() -> new RowNotFoundException(String.format("Rule with key '%s' does not exist", ruleKey))); String name = rule.getName() + " (" + rule.getLanguage() + ")"; setFieldValue(metric + DOT + i + LABEL, name); setFieldValue(metric + DOT + i + COUNT, String.valueOf(ruleStats.getValue().getOnLeak())); i++; } }
private void setTagsStatistics(NewIssuesStatistics.Stats stats) { Metric metric = Metric.TAG; int i = 1; for (Map.Entry<String, MetricStatsInt> tagStats : fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak)) { setFieldValue(metric + DOT + i + COUNT, String.valueOf(tagStats.getValue().getOnLeak())); setFieldValue(metric + DOT + i + LABEL, tagStats.getKey()); i++; } }
private void setAssigneesStatistics(DbSession dbSession, NewIssuesStatistics.Stats stats) { Metric metric = Metric.ASSIGNEE; List<Map.Entry<String, MetricStatsInt>> entries = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); Set<String> assigneeUuids = entries.stream().map(Map.Entry::getKey).filter(Objects::nonNull).collect(toSet()); Map<String, UserDto> userDtoByUuid = dbClient.userDao().selectByUuids(dbSession, assigneeUuids).stream().collect(toMap(UserDto::getUuid, u -> u)); int i = 1; for (Map.Entry<String, MetricStatsInt> assigneeStats : entries) { String assigneeUuid = assigneeStats.getKey(); UserDto user = userDtoByUuid.get(assigneeUuid); String name = user == null ? assigneeUuid : user.getName(); setFieldValue(metric + DOT + i + LABEL, name); setFieldValue(metric + DOT + i + COUNT, String.valueOf(assigneeStats.getValue().getOnLeak())); i++; } }
private void setComponentsStatistics(DbSession dbSession, NewIssuesStatistics.Stats stats) { Metric metric = Metric.COMPONENT; int i = 1; List<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); Set<String> componentUuids = fiveBiggest .stream() .map(Map.Entry::getKey) .collect(MoreCollectors.toSet(fiveBiggest.size())); Map<String, ComponentDto> componentDtosByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids) .stream() .collect(MoreCollectors.uniqueIndex(ComponentDto::uuid)); for (Map.Entry<String, MetricStatsInt> componentStats : fiveBiggest) { String uuid = componentStats.getKey(); String componentName = Optional.ofNullable(componentDtosByUuid.get(uuid)) .map(ComponentDto::name) .orElseThrow(() -> new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid))); setFieldValue(metric + DOT + i + LABEL, componentName); setFieldValue(metric + DOT + i + COUNT, String.valueOf(componentStats.getValue().getOnLeak())); i++; } }
private void setRuleStatistics(DbSession dbSession, NewIssuesStatistics.Stats stats) { Metric metric = Metric.RULE; List<Map.Entry<String, MetricStatsInt>> fiveBiggest = fiveBiggest(stats.getDistributedMetricStats(metric), MetricStatsInt::getOnLeak); Set<RuleKey> ruleKeys = fiveBiggest .stream() .map(Map.Entry::getKey) .map(RuleKey::parse) .collect(MoreCollectors.toSet(fiveBiggest.size())); Map<String, RuleDefinitionDto> ruleByRuleKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys) .stream() .collect(MoreCollectors.uniqueIndex(s -> s.getKey().toString())); int i = 1; for (Map.Entry<String, MetricStatsInt> ruleStats : fiveBiggest) { String ruleKey = ruleStats.getKey(); RuleDefinitionDto rule = Optional.ofNullable(ruleByRuleKey.get(ruleKey)) .orElseThrow(() -> new RowNotFoundException(String.format("Rule with key '%s' does not exist", ruleKey))); String name = rule.getName() + " (" + rule.getLanguage() + ")"; setFieldValue(metric + DOT + i + LABEL, name); setFieldValue(metric + DOT + i + COUNT, String.valueOf(ruleStats.getValue().getOnLeak())); i++; } }