]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5898 Index issue tags
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 9 Dec 2014 10:17:59 +0000 (11:17 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 10 Dec 2014 08:21:16 +0000 (09:21 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexDefinition.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResultSetIterator.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueResultSetIteratorTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/index/IssueResultSetIteratorTest/shared.xml

index 796039db8db95e82f6468ceec9d3adf22d6bf3d4..f3e0e47687486df5b98f277fc1241bedcba6a6e4 100644 (file)
@@ -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);
+  }
 }
index 57ab2fc0456bb18ff510fd8281b276ed9cd4496b..8cf12c7b20f124ab008d92c80c146af19c6abdf1 100644 (file)
@@ -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);
   }
 }
index 620884bd84bac8aa6874d60c81909042de91d2cc..0130df59e590ed331fde205caef3b74764c1c4e6 100644 (file)
  */
 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;
   }
 }
index 75431a8d7971ada76a700e24fdfcfb15b7e777e9..9812bc1dde36eb20991d3820f52f805ed24a5202 100644 (file)
@@ -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();
index 3341306e09d54f386f4b5170bca2ad0a1d75af02..ae9dbb951e6837c732a5c70726f01ecdbffdbd57 100644 (file)
@@ -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"