Search in sources :

Example 1 with ValueType

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());
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ValueType(org.sonar.api.measures.Metric.ValueType)

Example 2 with ValueType

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()));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ValueType(org.sonar.api.measures.Metric.ValueType)

Example 3 with ValueType

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());
}
Also used : ValueType(org.sonar.api.measures.Metric.ValueType)

Example 4 with ValueType

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());
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ValueType(org.sonar.api.measures.Metric.ValueType)

Example 5 with ValueType

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()));
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ValueType(org.sonar.api.measures.Metric.ValueType)

Aggregations

ValueType (org.sonar.api.measures.Metric.ValueType)6 MetricDto (org.sonar.db.metric.MetricDto)4