private Table<String, MetricDto, MeasureDto> searchMeasuresByComponentUuidAndMetric( DbSession dbSession, ComponentDto baseComponent, List<ComponentDto> components, List<MetricDto> metrics, List<WsMeasures.Period> periods, @Nullable Long developerId) { List<String> componentUuids = new ArrayList<>(); componentUuids.add(baseComponent.uuid()); components.stream().forEach(c -> componentUuids.add(c.uuid())); Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDtoFunctions.toId()); MeasureQuery measureQuery = MeasureQuery.builder() .setPersonId(developerId) .setComponentUuids(componentUuids) .setMetricIds(metricsById.keySet()) .build(); List<MeasureDto> measureDtos = dbClient.measureDao().selectByQuery(dbSession, measureQuery); Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size()); for (MeasureDto measureDto : measureDtos) { measuresByComponentUuidAndMetric.put( measureDto.getComponentUuid(), metricsById.get(measureDto.getMetricId()), measureDto); } addBestValuesToMeasures(measuresByComponentUuidAndMetric, components, metrics, periods); return measuresByComponentUuidAndMetric; }
private String formatMeasure(@Nullable MeasureDto measure, Metric metric) { if (measure == null) { return null; } Metric.ValueType metricType = metric.getType(); Double value = getDoubleValue(measure, metric); String data = measure.getData(); if (value != null) { switch (metricType) { case FLOAT: return i18n.formatDouble(userSession.locale(), value); case INT: return i18n.formatInteger(userSession.locale(), value.intValue()); case PERCENT: return i18n.formatDouble(userSession.locale(), value) + "%"; case WORK_DUR: return durations.format( userSession.locale(), durations.create(value.longValue()), Durations.DurationFormat.SHORT); } } if ((metricType.equals(Metric.ValueType.STRING) || metricType.equals(Metric.ValueType.RATING)) && data != null) { return data; } return null; }
@CheckForNull private static Double getDoubleValue(MeasureDto measure, Metric metric) { Double value = measure.getValue(); if (BooleanUtils.isTrue(metric.isOptimizedBestValue()) && value == null) { value = metric.getBestValue(); } return value; }