use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class MeasureToMeasureDtoTest method toMeasureDto_maps_value_to_1_or_0_and_data_from_data_field_for_BOOLEAN_metric.
@Test
public void toMeasureDto_maps_value_to_1_or_0_and_data_from_data_field_for_BOOLEAN_metric() {
MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(true, SOME_DATA), SOME_BOOLEAN_METRIC, SOME_COMPONENT);
assertThat(trueMeasureDto.getValue()).isEqualTo(1d);
assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA);
MeasureDto falseMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(false, SOME_DATA), SOME_BOOLEAN_METRIC, SOME_COMPONENT);
assertThat(falseMeasureDto.getValue()).isEqualTo(0d);
assertThat(falseMeasureDto.getData()).isEqualTo(SOME_DATA);
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class ComponentTreeSortTest method setUp.
@Before
public void setUp() {
components = newArrayList(newComponentWithoutSnapshotId("name-1", "qualifier-2", "path-9"), newComponentWithoutSnapshotId("name-3", "qualifier-3", "path-8"), newComponentWithoutSnapshotId("name-2", "qualifier-4", "path-7"), newComponentWithoutSnapshotId("name-4", "qualifier-5", "path-6"), newComponentWithoutSnapshotId("name-7", "qualifier-6", "path-5"), newComponentWithoutSnapshotId("name-6", "qualifier-7", "path-4"), newComponentWithoutSnapshotId("name-5", "qualifier-8", "path-3"), newComponentWithoutSnapshotId("name-9", "qualifier-9", "path-2"), newComponentWithoutSnapshotId("name-8", "qualifier-1", "path-1"));
MetricDto violationsMetric = newMetricDto().setKey(NUM_METRIC_KEY).setValueType(ValueType.INT.name());
MetricDto sqaleIndexMetric = newMetricDto().setKey(TEXT_METRIC_KEY).setValueType(ValueType.DATA.name());
metrics = newArrayList(violationsMetric, sqaleIndexMetric);
measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), 2);
// same number than path field
double currentValue = 9;
for (ComponentDto component : components) {
measuresByComponentUuidAndMetric.put(component.uuid(), violationsMetric, new MeasureDto().setValue(currentValue).setVariation(-currentValue));
measuresByComponentUuidAndMetric.put(component.uuid(), sqaleIndexMetric, new MeasureDto().setData(String.valueOf(currentValue)));
currentValue--;
}
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class AppAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession session = dbClient.openSession(false)) {
ComponentDto component = componentFinder.getByUuidOrKey(session, request.param(PARAM_COMPONENT_ID), request.param(PARAM_COMPONENT), ParamNames.COMPONENT_ID_AND_COMPONENT);
userSession.checkComponentPermission(UserRole.USER, component);
JsonWriter json = response.newJsonWriter();
json.beginObject();
Map<String, MeasureDto> measuresByMetricKey = measuresByMetricKey(component, session);
appendComponent(json, component, userSession, session);
appendPermissions(json, component, userSession);
appendMeasures(json, measuresByMetricKey);
json.endObject();
json.close();
}
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class AppAction method measuresByMetricKey.
private Map<String, MeasureDto> measuresByMetricKey(ComponentDto component, DbSession session) {
MeasureQuery query = MeasureQuery.builder().setComponentUuid(component.uuid()).setMetricKeys(METRIC_KEYS).build();
List<MeasureDto> measures = dbClient.measureDao().selectByQuery(session, query);
Set<Integer> metricIds = measures.stream().map(MeasureDto::getMetricId).collect(Collectors.toSet());
List<MetricDto> metrics = dbClient.metricDao().selectByIds(session, metricIds);
Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
return Maps.uniqueIndex(measures, m -> metricsById.get(m.getMetricId()).getKey());
}
use of org.sonar.db.measure.MeasureDto in project sonarqube by SonarSource.
the class ComponentAction method searchMeasures.
private List<MeasureDto> searchMeasures(DbSession dbSession, ComponentDto component, @Nullable SnapshotDto analysis, List<MetricDto> metrics, @Nullable Long developerId) {
if (analysis == null) {
return emptyList();
}
List<Integer> metricIds = Lists.transform(metrics, MetricDto::getId);
MeasureQuery query = MeasureQuery.builder().setPersonId(developerId).setMetricIds(metricIds).setComponentUuid(component.uuid()).build();
List<MeasureDto> measures = dbClient.measureDao().selectByQuery(dbSession, query);
addBestValuesToMeasures(measures, component, metrics);
return measures;
}
Aggregations