aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-10-12 17:53:52 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-10-20 18:45:15 +1000
commit59c61bf59fd3778f723021f5710d27165901760f (patch)
tree6d6f7528e866839e3a14510787e9f9552fe478d4 /server/sonar-db-dao/src
parent777701594f14b0886684d1d81bf32539a7522146 (diff)
downloadsonarqube-59c61bf59fd3778f723021f5710d27165901760f.tar.gz
sonarqube-59c61bf59fd3778f723021f5710d27165901760f.zip
SONAR-9949 Copy all issue attributes when merging a short in a long living branch
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java31
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java17
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java9
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java3
8 files changed, 52 insertions, 25 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java b/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java
index 0e2f88f94b9..11095124c97 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/core/issue/ShortBranchIssue.java
@@ -27,20 +27,24 @@ import org.sonar.core.issue.tracking.Trackable;
@Immutable
public class ShortBranchIssue implements Trackable {
+ private final String key;
private final Integer line;
private final String message;
private final String lineHash;
private final RuleKey ruleKey;
private final String status;
- private final String resolution;
- public ShortBranchIssue(@Nullable Integer line, String message, @Nullable String lineHash, RuleKey ruleKey, String status, @Nullable String resolution) {
+ public ShortBranchIssue(String key, @Nullable Integer line, String message, @Nullable String lineHash, RuleKey ruleKey, String status) {
+ this.key = key;
this.line = line;
this.message = message;
this.lineHash = lineHash;
this.ruleKey = ruleKey;
this.status = status;
- this.resolution = resolution;
+ }
+
+ public String getKey() {
+ return key;
}
@CheckForNull
@@ -70,7 +74,24 @@ public class ShortBranchIssue implements Trackable {
return status;
}
- public String getResolution() {
- return resolution;
+ @Override
+ public int hashCode() {
+ return key.hashCode();
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ShortBranchIssue other = (ShortBranchIssue) obj;
+ return key.equals(other.key);
+ }
+
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
index 9a9fa026968..eb22bc65c71 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeDao.java
@@ -48,6 +48,10 @@ public class IssueChangeDao implements Dao {
return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssuesAndType(issueKeys1, changeType));
}
+ public List<IssueChangeDto> selectByIssueKeys(DbSession session, Collection<String> issueKeys) {
+ return executeLargeInputs(issueKeys, issueKeys1 -> mapper(session).selectByIssues(issueKeys1));
+ }
+
public Optional<IssueChangeDto> selectCommentByKey(DbSession session, String commentKey) {
return Optional.ofNullable(mapper(session).selectByKeyAndType(commentKey, IssueChangeDto.TYPE_COMMENT));
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
index 1d6db5b2994..3b6aef0cff8 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueChangeMapper.java
@@ -40,5 +40,7 @@ public interface IssueChangeMapper {
List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") List<String> issueKeys,
@Param("changeType") String changeType);
+ List<IssueChangeDto> selectByIssues(@Param("issueKeys") List<String> issueKeys);
+
List<IssueChangeDto> selectChangelogOfNonClosedIssuesByComponent(@Param("componentUuid") String componentUuid, @Param("changeType") String changeType);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java
index 3674cdc7af8..3a68ea03af2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/ShortBranchIssueDto.java
@@ -19,7 +19,6 @@
*/
package org.sonar.db.issue;
-import com.google.common.base.Preconditions;
import java.io.Serializable;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -27,9 +26,6 @@ import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rule.RuleKey;
import org.sonar.core.issue.ShortBranchIssue;
-import org.sonar.db.rule.RuleDefinitionDto;
-
-import static com.google.common.base.Preconditions.checkArgument;
public final class ShortBranchIssueDto implements Serializable {
@@ -38,7 +34,6 @@ public final class ShortBranchIssueDto implements Serializable {
private Integer line;
private String checksum;
private String status;
- private String resolution;
// joins
private String ruleKey;
@@ -83,16 +78,6 @@ public final class ShortBranchIssueDto implements Serializable {
}
@CheckForNull
- public String getResolution() {
- return resolution;
- }
-
- public ShortBranchIssueDto setResolution(@Nullable String s) {
- this.resolution = s;
- return this;
- }
-
- @CheckForNull
public String getChecksum() {
return checksum;
}
@@ -120,6 +105,6 @@ public final class ShortBranchIssueDto implements Serializable {
}
public static ShortBranchIssue toShortBranchIssue(ShortBranchIssueDto dto) {
- return new ShortBranchIssue(dto.getLine(), dto.getMessage(), dto.getChecksum(), dto.getRuleKey(), dto.getStatus(), dto.getResolution());
+ return new ShortBranchIssue(dto.getKey(), dto.getLine(), dto.getMessage(), dto.getChecksum(), dto.getRuleKey(), dto.getStatus());
}
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
index 46a732b0719..8b315466eb7 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueChangeMapper.xml
@@ -42,6 +42,16 @@
</foreach>
order by c.created_at
</select>
+
+ <select id="selectByIssues" parameterType="map" resultType="IssueChange">
+ select
+ <include refid="issueChangeColumns"/>
+ from issue_changes c
+ where c.issue_key in
+ <foreach collection="issueKeys" open="(" close=")" item="key" separator=",">
+ #{key,jdbcType=VARCHAR}
+ </foreach>
+ </select>
<select id="selectByKeyAndType" parameterType="map" resultType="IssueChange">
select
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
index fa9c34ec2d0..8c365703f9e 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/issue/IssueMapper.xml
@@ -219,7 +219,6 @@
i.message as message,
i.line as line,
i.status as status,
- i.resolution as resolution,
i.checksum as checksum,
r.plugin_rule_key as ruleKey,
r.plugin_name as ruleRepo
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
index a5b46eb3c15..7a0ffca2a48 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.issue;
+import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.junit.Rule;
@@ -49,6 +50,14 @@ public class IssueChangeDaoTest {
}
@Test
+ public void select_issue_changes_from_issues_key() {
+ db.prepareDbUnit(getClass(), "shared.xml");
+
+ List<IssueChangeDto> changelog = underTest.selectByIssueKeys(db.getSession(), Arrays.asList("1000", "1001"));
+ assertThat(changelog).hasSize(5);
+ }
+
+ @Test
public void selectChangelogOfNonClosedIssuesByComponent() {
db.prepareDbUnit(getClass(), "selectChangelogOfNonClosedIssuesByComponent.xml");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
index f44788c174f..8fc59751ee0 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
@@ -30,7 +30,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2;
-import org.sonar.core.issue.ShortBranchIssue;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.component.ComponentDto;
@@ -212,7 +211,6 @@ public class IssueDaoTest {
assertThat(fp.getChecksum()).isEqualTo(fpIssue.getChecksum());
assertThat(fp.getRuleKey()).isEqualTo(fpIssue.getRuleKey());
assertThat(fp.getStatus()).isEqualTo(fpIssue.getStatus());
- assertThat(fp.getResolution()).isEqualTo(fpIssue.getResolution());
assertThat(fp.getLine()).isNotNull();
assertThat(fp.getLine()).isNotZero();
@@ -221,7 +219,6 @@ public class IssueDaoTest {
assertThat(fp.getChecksum()).isNotEmpty();
assertThat(fp.getRuleKey()).isNotNull();
assertThat(fp.getStatus()).isNotNull();
- assertThat(fp.getResolution()).isNotNull();
}
private static IssueDto newIssueDto(String key) {