return mapper(dbSession).selectByProjectUuid(projectUuid);
}
- /**
- * Retrieves all components with a specific customer measure, no other filtering is done by this method.
- *
- * Used by Views plugin
- */
- public List<ComponentDto> selectByCustomMeasure(String metricKey, String metricValue, DbSession dbSession) {
- return mapper(dbSession).selectByCustomMeasure(metricKey, metricValue);
- }
-
private static void addPartialQueryParameterIfNotNull(Map<String, Object> parameters, @Nullable String keyOrNameFilter) {
if (keyOrNameFilter != null) {
parameters.put("query", "%" + keyOrNameFilter.toUpperCase() + "%");
List<ComponentDto> selectByProjectUuid(@Param("projectUuid") String projectUuid);
- List<ComponentDto> selectByCustomMeasure(@Param("metricKey") String metricKey, @Param("metricValue") String metricValue);
-
List<String> selectExistingUuids(@Param("uuids") Collection<String> uuids);
/**
return mapper(session).selectByComponentUuid(componentUuid);
}
+ /**
+ * Used by Views plugin
+ */
+ public List<CustomMeasureDto> selectByMetricKeyAndTextValue(DbSession session, String metricKey, String textValue) {
+ return mapper(session).selectByMetricKeyAndTextValue(metricKey, textValue);
+ }
+
private CustomMeasureMapper mapper(DbSession session) {
return session.getMapper(CustomMeasureMapper.class);
}
package org.sonar.db.measure.custom;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
public class CustomMeasureDto {
+
private long id;
private int metricId;
private String componentUuid;
return this;
}
+ @CheckForNull
public String getTextValue() {
return textValue;
}
- public CustomMeasureDto setTextValue(String textValue) {
+ public CustomMeasureDto setTextValue(@Nullable String textValue) {
this.textValue = textValue;
return this;
}
List<CustomMeasureDto> selectByComponentUuid(String s, RowBounds rowBounds);
+ List<CustomMeasureDto> selectByMetricKeyAndTextValue(@Param("metricKey") String metricKey, @Param("textValue") String textValue);
+
int countByComponentUuid(String componentUuid);
int countByComponentIdAndMetricId(@Param("componentUuid") String componentUuid, @Param("metricId") int metricId);
</where>
</select>
- <select id="selectResourcesByCustomerMeasure" parameterType="String" resultType="Component">
- SELECT
- <include refid="componentColumns"/>
- FROM projects p, metric m, manual_measures mm
- <where>
- m.name=#{metricKey}
- and mm.metric_id = m.id
- and mm.text_value=#{metricValue}
- and p.id=mm.resourceId
- </where>
- </select>
-
<select id="countById" parameterType="long" resultType="long">
SELECT count(p.id)
FROM projects p
where m.component_uuid=#{componentUuid}
</select>
+ <select id="selectByMetricKeyAndTextValue" resultType="CustomMeasure">
+ SELECT
+ <include refid="selectColumns"/>
+ FROM manual_measures m
+ INNER JOIN metrics metric ON metric.id=m.metric_id AND metric.name=#{metricKey}
+ <where>
+ m.text_value=#{textValue}
+ </where>
+ </select>
+
<insert id="insert" parameterType="CustomMeasure" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
INSERT INTO manual_measures (
metric_id, component_uuid, value, text_value, user_login, description, created_at, updated_at
underTest.selectOrFail(session, 42L);
}
+ @Test
+ public void select_by_metric_key_and_text_value() throws Exception {
+ db.prepareDbUnit(getClass(), "select_by_metric_key_and_text_value.xml");
+
+ List<CustomMeasureDto> result = underTest.selectByMetricKeyAndTextValue(session, "customKey", "value1");
+
+ assertThat(result).extracting("id").containsOnly(20L, 21L);
+
+ assertThat(underTest.selectByMetricKeyAndTextValue(session, "customKey", "unknown")).isEmpty();
+ assertThat(underTest.selectByMetricKeyAndTextValue(session, "unknown", "value1")).isEmpty();
+ }
}
--- /dev/null
+<dataset>
+
+ <metrics id="10" name="ncloc"/>
+ <metrics id="11" name="customKey"/>
+
+ <manual_measures id="20" metric_id="11" component_uuid="ABCD" value="[null]" text_value="value1"
+ user_login="seb" description="" created_at="123456789" updated_at="123456789" />
+ <manual_measures id="21" metric_id="11" component_uuid="BCDE" value="[null]" text_value="value1"
+ user_login="seb" description="" created_at="123456789" updated_at="123456789" />
+ <manual_measures id="22" metric_id="11" component_uuid="CDEF" value="[null]" text_value="value2"
+ user_login="seb" description="" created_at="123456789" updated_at="123456789" />
+
+
+</dataset>