diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-12-09 11:17:59 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-12-10 09:21:16 +0100 |
commit | b64f82b908d80db32bb24cf3551c6071afcd4cf3 (patch) | |
tree | 1855229b6f49da107fd552f7481ec19f7765d175 | |
parent | 2967298579779ba6d781740b5594ec25c4e69119 (diff) | |
download | sonarqube-b64f82b908d80db32bb24cf3551c6071afcd4cf3.tar.gz sonarqube-b64f82b908d80db32bb24cf3551c6071afcd4cf3.zip |
SONAR-5898 Index issue tags
5 files changed, 32 insertions, 7 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java index 796039db8db..f3e0e476874 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java @@ -29,6 +29,8 @@ import org.sonar.server.search.BaseDoc; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -293,4 +295,13 @@ public class IssueDoc extends BaseDoc implements Issue { public void setModuleUuidPath(@Nullable String s) { setField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, s); } + + @CheckForNull + public Collection<String> tags() { + return getNullableField(IssueIndexDefinition.FIELD_ISSUE_TAGS); + } + + public void setTags(@Nullable Collection<String> tags) { + setField(IssueIndexDefinition.FIELD_ISSUE_TAGS, tags); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java index 57ab2fc0456..8cf12c7b20f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java @@ -74,6 +74,7 @@ public class IssueIndexDefinition implements IndexDefinition { public static final String FIELD_ISSUE_SEVERITY = "severity"; public static final String FIELD_ISSUE_SEVERITY_VALUE = "severityValue"; public static final String FIELD_ISSUE_STATUS = "status"; + public static final String FIELD_ISSUE_TAGS = "tags"; /** * Technical date */ @@ -134,6 +135,7 @@ public class IssueIndexDefinition implements IndexDefinition { issueMapping.stringFieldBuilder(FIELD_ISSUE_SEVERITY).build(); issueMapping.createByteField(FIELD_ISSUE_SEVERITY_VALUE); issueMapping.stringFieldBuilder(FIELD_ISSUE_STATUS).enableSorting().build(); + issueMapping.stringFieldBuilder(FIELD_ISSUE_TAGS).build(); issueMapping.createDateTimeField(FIELD_ISSUE_TECHNICAL_UPDATED_AT); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java index 620884bd84b..0130df59e59 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java @@ -19,18 +19,21 @@ */ package org.sonar.server.issue.index; -import com.google.common.collect.Maps; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Date; + import org.apache.commons.lang.StringUtils; import org.sonar.api.rule.RuleKey; import org.sonar.server.db.DbClient; import org.sonar.server.db.ResultSetIterator; import org.sonar.server.db.migrations.SqlUtil; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Date; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; /** * Scrolls over table ISSUES and reads documents to populate @@ -68,7 +71,8 @@ class IssueResultSetIterator extends ResultSetIterator<IssueDoc> { "p.uuid", "p.module_uuid", "p.module_uuid_path", - "p.path" + "p.path", + "i.tags" }; private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from issues i " + @@ -78,6 +82,8 @@ class IssueResultSetIterator extends ResultSetIterator<IssueDoc> { private static final String SQL_AFTER_DATE = SQL_ALL + " where i.updated_at>?"; + private static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); + static IssueResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) { try { String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL; @@ -129,6 +135,8 @@ class IssueResultSetIterator extends ResultSetIterator<IssueDoc> { doc.setModuleUuid(rs.getString(23)); doc.setModuleUuidPath(rs.getString(24)); doc.setFilePath(rs.getString(25)); + String tags = rs.getString(26); + doc.setTags(ImmutableList.copyOf(TAGS_SPLITTER.split(tags == null ? "" : tags))); return doc; } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java index 75431a8d797..9812bc1dde3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java @@ -61,6 +61,7 @@ public class IssueResultSetIteratorTest { assertThat(issue.assignee()).isNotEmpty(); assertThat(issue.componentUuid()).isNotEmpty(); assertThat(issue.projectUuid()).isNotEmpty(); + assertThat(issue.tags()).containsOnly("tag1", "tag2", "tag3"); assertThat(issue.debt().toMinutes()).isGreaterThan(0L); assertThat(it.hasNext()).isTrue(); @@ -69,6 +70,7 @@ public class IssueResultSetIteratorTest { assertThat(issue.assignee()).isNotEmpty(); assertThat(issue.componentUuid()).isNotEmpty(); assertThat(issue.projectUuid()).isNotEmpty(); + assertThat(issue.tags()).isEmpty(); assertThat(issue.debt().toMinutes()).isGreaterThan(0L); assertThat(it.hasNext()).isFalse(); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueResultSetIteratorTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueResultSetIteratorTest/shared.xml index 3341306e09d..ae9dbb951e6 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueResultSetIteratorTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueResultSetIteratorTest/shared.xml @@ -25,6 +25,7 @@ reporter="[null]" issue_attributes="JIRA=http://jira.com" action_plan_key="PLAN1" + tags="tag1,tag2,tag3" created_at="1400000000000" updated_at="1400000000000" issue_creation_date="2005-05-12 00:00:00.0" @@ -51,6 +52,7 @@ reporter="[null]" issue_attributes="JIRA=http://jira.com" action_plan_key="PLAN2" + tags="[null]" created_at="1400000000000" updated_at="1450000000000" issue_creation_date="2005-05-12 00:00:00.0" |