use of org.sonar.api.measures.Metric.ValueType in project sonarqube by SonarSource.
the class ComponentTreeSort method metricValueOrdering.
private static Ordering<ComponentDto> metricValueOrdering(ComponentTreeWsRequest wsRequest, List<MetricDto> metrics, Table<String, MetricDto, MeasureDto> measuresByComponentUuidAndMetric) {
if (wsRequest.getMetricSort() == null) {
return componentNameOrdering(wsRequest.getAsc());
}
Map<String, MetricDto> metricsByKey = Maps.uniqueIndex(metrics, MetricDto::getKey);
MetricDto metric = metricsByKey.get(wsRequest.getMetricSort());
boolean isAscending = wsRequest.getAsc();
ValueType metricValueType = ValueType.valueOf(metric.getValueType());
if (NUMERIC_VALUE_TYPES.contains(metricValueType)) {
return numericalMetricOrdering(isAscending, metric, measuresByComponentUuidAndMetric);
} else if (TEXTUAL_VALUE_TYPES.contains(metricValueType)) {
return stringOrdering(isAscending, new ComponentDtoToTextualMeasureValue(metric, measuresByComponentUuidAndMetric));
} else if (ValueType.LEVEL.equals(ValueType.valueOf(metric.getValueType()))) {
return levelMetricOrdering(isAscending, metric, measuresByComponentUuidAndMetric);
}
throw new IllegalStateException("Unrecognized metric value type: " + metric.getValueType());
}
use of org.sonar.api.measures.Metric.ValueType in project sonarqube by SonarSource.
the class ComponentTreeSort method metricPeriodOrdering.
private static Ordering<ComponentDto> metricPeriodOrdering(ComponentTreeWsRequest wsRequest, List<MetricDto> metrics, Table<String, MetricDto, MeasureDto> 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()));
}
use of org.sonar.api.measures.Metric.ValueType in project sonarqube by SonarSource.
the class QualityGateConditionsUpdater method checkOperator.
private static void checkOperator(MetricDto metric, String operator, List<String> errors) {
ValueType valueType = valueOf(metric.getValueType());
check(isOperatorAllowed(operator, valueType), errors, "Operator %s is not allowed for metric type %s.", operator, metric.getValueType());
}
use of org.sonar.api.measures.Metric.ValueType in project sonarqube by SonarSource.
the class ComponentTreeSort method metricValueOrdering.
private static Ordering<ComponentDto> metricValueOrdering(ComponentTreeRequest wsRequest, List<MetricDto> metrics, Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric) {
if (wsRequest.getMetricSort() == null) {
return componentNameOrdering(wsRequest.getAsc());
}
Map<String, MetricDto> metricsByKey = Maps.uniqueIndex(metrics, MetricDto::getKey);
MetricDto metric = metricsByKey.get(wsRequest.getMetricSort());
boolean isAscending = wsRequest.getAsc();
ValueType metricValueType = ValueType.valueOf(metric.getValueType());
if (NUMERIC_VALUE_TYPES.contains(metricValueType)) {
return numericalMetricOrdering(isAscending, metric, measuresByComponentUuidAndMetric);
} else if (TEXTUAL_VALUE_TYPES.contains(metricValueType)) {
return stringOrdering(isAscending, new ComponentDtoToTextualMeasureValue(metric, measuresByComponentUuidAndMetric));
} else if (ValueType.LEVEL.equals(ValueType.valueOf(metric.getValueType()))) {
return levelMetricOrdering(isAscending, metric, measuresByComponentUuidAndMetric);
}
throw new IllegalStateException("Unrecognized metric value type: " + metric.getValueType());
}
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()));
}