});
}
+ /**
+ * Used by plugin Developer Cockpit
+ */
+ public List<MeasureDto> selectBySnapshotAndMetrics(final DbSession dbSession, final long snapshotId, Collection<Integer> metricIds) {
+ return DatabaseUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<MeasureDto>>() {
+ @Override
+ @Nonnull
+ public List<MeasureDto> apply(@Nonnull List<Integer> input) {
+ return mapper(dbSession).selectBySnapshotAndMetrics(snapshotId, input);
+ }
+ });
+ }
+
public void insert(DbSession session, MeasureDto measureDto) {
mapper(session).insert(measureDto);
}
List<MeasureDto> selectByDeveloperForSnapshotAndMetrics(@Param("developerId") long developerId, @Param("snapshotId") long snapshotId, @Param("metricIds") List<Integer> metricIds);
+ List<MeasureDto> selectBySnapshotAndMetrics(@Param("snapshotId") long snapshotId, @Param("metricIds") List<Integer> input);
+
@CheckForNull
MeasureDto selectByComponentAndMetric(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey);
</where>
</select>
+ <select id="selectBySnapshotAndMetrics" parameterType="map" resultType="Measure">
+ SELECT
+ <include refid="measureColumns"/>
+ FROM project_measures pm
+ <where>
+ pm.snapshot_id = #{snapshotId}
+ AND pm.rule_id is NULL
+ AND pm.characteristic_id is NULL
+ AND pm.person_id is NULL
+ AND
+ <foreach item="metricId" index="index" collection="metricIds" open="(" separator=" or " close=")">
+ pm.metric_id=#{metricId}
+ </foreach>
+ </where>
+ </select>
+
<select id="countByComponentAndMetric" parameterType="map" resultType="long">
SELECT count(pm.id)
FROM project_measures pm
assertThat(measureDtos).extracting("id").containsOnly(32L);
}
+ @Test
+ public void selectBySnapshotAndMetrics_returns_empty_when_single_metric_id_does_not_exist() {
+ db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
+
+ List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(),
+ SNAPSHOT_ID,
+ ImmutableList.of(666));
+
+ assertThat(measureDtos).isEmpty();
+ }
+
+ @Test
+ public void selectBySnapshotAndMetrics_returns_only_measures_not_for_developer() {
+ db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
+
+ List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(),
+ SNAPSHOT_ID,
+ ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
+
+ assertThat(measureDtos).extracting("id").containsOnly(20L, 21L, 22L);
+ }
+
+ @Test
+ public void selectBySnapshotAndMetrics_returns_only_measures_not_for_developer_and_with_specified_metric_id() {
+ db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
+
+ List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(),
+ SNAPSHOT_ID,
+ ImmutableList.of(NCLOC_METRIC_ID));
+
+ assertThat(measureDtos).extracting("id").containsOnly(22L);
+ }
+
@Test
public void selectByDeveloperForSnapshotAndMetrics_returns_empty_when_single_metric_id_does_not_exist() {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");