private List<LiveMeasureDto> searchMeasures() { return dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, projects.stream().map(ComponentDto::uuid).collect(MoreCollectors.toArrayList(projects.size())), metrics.stream().map(MetricDto::getId).collect(MoreCollectors.toArrayList(metrics.size()))); }
private List<LiveMeasureDto> searchMeasures(DbSession dbSession, ComponentDto component, List<MetricDto> metrics) { List<Integer> metricIds = Lists.transform(metrics, MetricDto::getId); List<LiveMeasureDto> measures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, singletonList(component.uuid()), metricIds); addBestValuesToMeasures(measures, component, metrics); return measures; }
private Map<String, LiveMeasureDto> loadMeasuresGroupedByMetricKey(ComponentDto component, DbSession dbSession) { List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, METRIC_KEYS); Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId); List<LiveMeasureDto> measures = dbClient.liveMeasureDao() .selectByComponentUuidsAndMetricIds(dbSession, Collections.singletonList(component.uuid()), metricsById.keySet()); return Maps.uniqueIndex(measures, m -> metricsById.get(m.getMetricId()).getKey()); }
private void verifyPersisted(LiveMeasureDto dto) { List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(dto.getComponentUuid()), singletonList(dto.getMetricId())); assertThat(selected).hasSize(1); assertThat(selected.get(0)).isEqualToComparingFieldByField(dto); } }
@Test public void selectByComponentUuidsAndMetricIds_returns_empty_list_if_component_does_not_match() { LiveMeasureDto measure = newLiveMeasure(); underTest.insert(db.getSession(), measure); List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList("_missing_"), singletonList(measure.getMetricId())); assertThat(selected).isEmpty(); }
.collect(uniqueIndex(MetricDto::getId)); List<String> componentUuids = components.stream().map(ComponentDto::uuid).collect(toArrayList(components.size())); List<LiveMeasureDto> dbMeasures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, componentUuids, metricsPerId.keySet());
@Test public void selectByComponentUuidsAndMetricIds_returns_empty_list_if_metric_does_not_match() { LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId()); underTest.insert(db.getSession(), measure); int otherMetricId = metric.getId() + 100; List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(measure.getComponentUuid()), singletonList(otherMetricId)); assertThat(selected).isEmpty(); }
@Test public void selectByComponentUuidsAndMetricIds() { LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId()); LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric.getId()); underTest.insert(db.getSession(), measure1); underTest.insert(db.getSession(), measure2); List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getId())); assertThat(selected) .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString) .containsExactlyInAnyOrder( tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricId(), measure1.getValue(), measure1.getDataAsString()), tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricId(), measure2.getValue(), measure2.getDataAsString())); assertThat(underTest.selectByComponentUuidsAndMetricIds(db.getSession(), emptyList(), singletonList(metric.getId()))).isEmpty(); assertThat(underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty(); }
@Test public void delete_live_measures_when_deleting_project() { MetricDto metric = db.measures().insertMetric(); ComponentDto project1 = db.components().insertPublicProject(); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project1)); db.measures().insertLiveMeasure(project1, metric); db.measures().insertLiveMeasure(module1, metric); ComponentDto project2 = db.components().insertPublicProject(); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project2)); db.measures().insertLiveMeasure(project2, metric); db.measures().insertLiveMeasure(module2, metric); underTest.deleteProject(dbSession, project1.uuid()); assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getId()))).isEmpty(); assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getId()))).hasSize(2); }
List<LiveMeasureDto> liveMeasureDtos = db.getDbClient().liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, ImmutableSet.of(srcFile.uuid(), dir.uuid(), project.uuid(), nonSelectedFile.uuid()), ImmutableSet.of(metric1.getId(), metric2.getId())); assertThat(liveMeasureDtos)
private List<LiveMeasureDto> searchMeasures() { return dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, projects.stream().map(ComponentDto::uuid).collect(MoreCollectors.toArrayList(projects.size())), metrics.stream().map(MetricDto::getId).collect(MoreCollectors.toArrayList(metrics.size()))); }
private List<LiveMeasureDto> searchMeasures(DbSession dbSession, ComponentDto component, List<MetricDto> metrics) { List<Integer> metricIds = Lists.transform(metrics, MetricDto::getId); List<LiveMeasureDto> measures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, singletonList(component.uuid()), metricIds); addBestValuesToMeasures(measures, component, metrics); return measures; }
private Map<String, LiveMeasureDto> loadMeasuresGroupedByMetricKey(ComponentDto component, DbSession dbSession) { List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, METRIC_KEYS); Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId); List<LiveMeasureDto> measures = dbClient.liveMeasureDao() .selectByComponentUuidsAndMetricIds(dbSession, Collections.singletonList(component.uuid()), metricsById.keySet()); return Maps.uniqueIndex(measures, m -> metricsById.get(m.getMetricId()).getKey()); }
.collect(uniqueIndex(MetricDto::getId)); List<String> componentUuids = components.stream().map(ComponentDto::uuid).collect(toArrayList(components.size())); List<LiveMeasureDto> dbMeasures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, componentUuids, metricsPerId.keySet());