use of org.sonar.api.measures.Metric.ValueType in project sonarqube by SonarSource.
the class ComponentTreeSort method metricPeriodOrdering.
private static Ordering<ComponentDto> metricPeriodOrdering(ComponentTreeRequest wsRequest, List<MetricDto> metrics, Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric) {
if (wsRequest.getMetricSort() == null || wsRequest.getMetricPeriodSort() == null) {
return componentNameOrdering(wsRequest.getAsc());
}
Map<String, MetricDto> metricsByKey = Maps.uniqueIndex(metrics, MetricDto::getKey);
MetricDto metric = metricsByKey.get(wsRequest.getMetricSort());
ValueType metricValueType = ValueType.valueOf(metric.getValueType());
if (NUMERIC_VALUE_TYPES.contains(metricValueType)) {
return numericalMetricPeriodOrdering(wsRequest, metric, measuresByComponentUuidAndMetric);
}
throw BadRequestException.create(format("Impossible to sort metric '%s' by measure period.", metric.getKey()));
}