diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-06-19 13:49:56 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-06-19 13:58:07 +0200 |
commit | ef9cd055564036a2b5a1eebaafed4f0c8b637290 (patch) | |
tree | f04cd37606664adf8957909bfaa847c3043960df /sonar-core | |
parent | 569848e5c4aac2902d249fe7e7dbe279d5394c39 (diff) | |
download | sonarqube-ef9cd055564036a2b5a1eebaafed4f0c8b637290.tar.gz sonarqube-ef9cd055564036a2b5a1eebaafed4f0c8b637290.zip |
SONAR-6643 Fill measures with variations
Diffstat (limited to 'sonar-core')
4 files changed, 157 insertions, 4 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureMapper.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureMapper.java index 39a32c758ae..2bbded72760 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureMapper.java @@ -20,11 +20,9 @@ package org.sonar.core.measure.db; -import org.apache.ibatis.annotations.Param; - -import javax.annotation.CheckForNull; - import java.util.List; +import javax.annotation.CheckForNull; +import org.apache.ibatis.annotations.Param; public interface MeasureMapper { @@ -35,6 +33,9 @@ public interface MeasureMapper { @CheckForNull MeasureDto selectByComponentAndMetric(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey); + List<PastMeasureDto> selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds(@Param("componentUuid") String componentuuid, @Param("rootSnapshotId") long rootSnapshotId, + @Param("metricIds") List<Integer> metricIds, @Param("status") String status); + long countByComponentAndMetric(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey); void insert(MeasureDto measureDto); diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/PastMeasureDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/PastMeasureDto.java new file mode 100644 index 00000000000..cb8618aecdc --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/measure/db/PastMeasureDto.java @@ -0,0 +1,87 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.measure.db; + +import java.util.Objects; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class PastMeasureDto { + + private Double value; + private Integer metricId; + private Integer ruleId; + private Integer characteristicId; + private Integer personId; + + public double getValue() { + Objects.requireNonNull(value); + return value; + } + + public PastMeasureDto setValue(@Nullable Double value) { + this.value = value; + return this; + } + + public boolean hasValue() { + return value != null; + } + + public Integer getMetricId() { + return metricId; + } + + public PastMeasureDto setMetricId(Integer metricId) { + this.metricId = metricId; + return this; + } + + @CheckForNull + public Integer getCharacteristicId() { + return characteristicId; + } + + public PastMeasureDto setCharacteristicId(@Nullable Integer characteristicId) { + this.characteristicId = characteristicId; + return this; + } + + @CheckForNull + public Integer getPersonId() { + return personId; + } + + public PastMeasureDto setPersonId(@Nullable Integer personId) { + this.personId = personId; + return this; + } + + @CheckForNull + public Integer getRuleId() { + return ruleId; + } + + public PastMeasureDto setRuleId(@Nullable Integer ruleId) { + this.ruleId = ruleId; + return this; + } +} diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml index 4097f21dc31..e92e260144c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml @@ -70,6 +70,21 @@ </where> </select> + <select id="selectByComponentUuidAndProjectSnapshotIdAndStatusAndMetricIds" parameterType="map" resultType="org.sonar.core.measure.db.PastMeasureDto"> + SELECT pm.metric_id as metricId, pm.rule_id as ruleId, pm.characteristic_id as characteristicId, pm.person_id as personId, pm.value as value + FROM project_measures pm + INNER JOIN snapshots s ON s.id=pm.snapshot_id AND s.status=#{status} + INNER JOIN projects p ON p.id=s.project_id AND p.enabled=${_true} + <where> + AND p.uuid = #{componentUuid} + AND (s.root_snapshot_id=#{rootSnapshotId} OR s.id=#{rootSnapshotId}) + AND + <foreach item="metricId" index="index" collection="metricIds" open="(" separator=" or " close=")"> + pm.metric_id=#{metricId} + </foreach> + </where> + </select> + <insert id="insert" parameterType="Measure" useGeneratedKeys="false"> INSERT INTO project_measures ( value, metric_id, snapshot_id, rule_id, text_value, project_id, alert_status, alert_text, description, diff --git a/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java new file mode 100644 index 00000000000..85a3ada44a6 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.measure.db; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PastMeasureDtoTest { + + @Test + public void test_getter_and_setter() throws Exception { + PastMeasureDto dto = new PastMeasureDto() + .setValue(1d) + .setMetricId(2) + .setRuleId(3) + .setCharacteristicId(4) + .setPersonId(5); + + assertThat(dto.hasValue()).isTrue(); + assertThat(dto.getValue()).isEqualTo(1d); + assertThat(dto.getMetricId()).isEqualTo(2); + assertThat(dto.getRuleId()).isEqualTo(3); + assertThat(dto.getCharacteristicId()).isEqualTo(4); + assertThat(dto.getPersonId()).isEqualTo(5); + } + + @Test(expected = NullPointerException.class) + public void get_value_throw_a_NPE_if_value_is_null() throws Exception { + new PastMeasureDto().getValue(); + } +} |