]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4383 Replace user by userLogin in IssueFilters table
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 13 Jun 2013 08:40:53 +0000 (10:40 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 13 Jun 2013 08:41:07 +0000 (10:41 +0200)
12 files changed:
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueFilter.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueFilterDto.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/test/java/org/sonar/core/issue/db/IssueFilterDaoTest.java
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/shared.xml
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_delete-result.xml
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_insert-result.xml
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_select_by_user.xml
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueFilterDaoTest/should_update-result.xml
sonar-server/src/main/webapp/WEB-INF/db/migrate/410_create_issue_filters.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/411_create_issue_filter_favourites.rb

index 639dafbb62d151aedaae0e07b459c22c3f4b85bb..e5047917679027176487f491c32c2b6b881f3cbc 100644 (file)
 
 package org.sonar.core.issue;
 
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
+
 import javax.annotation.CheckForNull;
 
 import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
 
 public class DefaultIssueFilter {
 
@@ -116,4 +127,68 @@ public class DefaultIssueFilter {
     return this;
   }
 
+  public Map<String, Object> dataAsMap(){
+    return dataAsMap(data);
+  }
+
+  @VisibleForTesting
+  Map<String, Object> dataAsMap(String data) {
+    Map<String, Object> map = newHashMap();
+
+    Iterable<String> keyValues = Splitter.on(DefaultIssueFilter.SEPARATOR).split(data);
+    for (String keyValue : keyValues) {
+      String[] keyValueSplit = StringUtils.split(keyValue, DefaultIssueFilter.KEY_VALUE_SEPARATOR);
+      if (keyValueSplit.length != 2) {
+        throw new IllegalArgumentException("Key value should be separate by a '"+ DefaultIssueFilter.KEY_VALUE_SEPARATOR + "'");
+      }
+      String key = keyValueSplit[0];
+      String value = keyValueSplit[1];
+      String[] listValues = StringUtils.split(value, DefaultIssueFilter.LIST_SEPARATOR);
+      if (listValues.length > 1) {
+        map.put(key, newArrayList(listValues));
+      } else {
+        map.put(key, value);
+      }
+    }
+    return map;
+  }
+
+  @VisibleForTesting
+  String mapAsdata(Map<String, Object> map) {
+    StringBuilder stringBuilder = new StringBuilder();
+
+    for (Map.Entry<String, Object> entries : map.entrySet()){
+      String key = entries.getKey();
+      Object value = entries.getValue();
+
+      stringBuilder.append(key);
+      stringBuilder.append(DefaultIssueFilter.KEY_VALUE_SEPARATOR);
+
+      List valuesList = newArrayList();
+      if (value instanceof List) {
+        // assume that it contains only strings
+        valuesList = (List) value;
+      } else if (value instanceof CharSequence) {
+        valuesList = Lists.newArrayList(Splitter.on(',').omitEmptyStrings().split((CharSequence) value));
+      } else {
+        stringBuilder.append(value);
+      }
+      for (Iterator<Object> valueListIter = valuesList.iterator(); valueListIter.hasNext();) {
+        Object valueList = valueListIter.next();
+        stringBuilder.append(valueList);
+        if (valueListIter.hasNext()) {
+          stringBuilder.append(DefaultIssueFilter.LIST_SEPARATOR);
+        }
+      }
+      stringBuilder.append(DefaultIssueFilter.SEPARATOR);
+    }
+
+    if (stringBuilder.length() > 0) {
+      // Delete useless last separator character
+      stringBuilder.deleteCharAt(stringBuilder.length() - 1);
+    }
+
+    return stringBuilder.toString();
+  }
+
 }
index 29093953dc9add909cb4d3a30fc7a4f5cef33546..9fe5c1e6291f789f1155e08fa66e4fd863478cd8 100644 (file)
@@ -32,7 +32,7 @@ public class IssueFilterDto {
 
   private Long id;
   private String name;
-  private String user;
+  private String userLogin;
   private Boolean shared;
   private String description;
   private String data;
@@ -57,12 +57,12 @@ public class IssueFilterDto {
     return this;
   }
 
-  public String getUser() {
-    return user;
+  public String getUserLogin() {
+    return userLogin;
   }
 
-  public IssueFilterDto setUser(@Nullable String user) {
-    this.user = user;
+  public IssueFilterDto setUserLogin(@Nullable String userLogin) {
+    this.userLogin = userLogin;
     return this;
   }
 
@@ -115,7 +115,7 @@ public class IssueFilterDto {
     return new DefaultIssueFilter()
       .setId(id)
       .setName(name)
-      .setUser(user)
+      .setUser(userLogin)
       .setDescription(description)
       .setShared(shared)
       .setData(data)
@@ -127,7 +127,7 @@ public class IssueFilterDto {
     return new IssueFilterDto()
       .setId(issueFilter.id())
       .setName(issueFilter.name())
-      .setUser(issueFilter.user())
+      .setUserLogin(issueFilter.user())
       .setDescription(issueFilter.description())
       .setShared(issueFilter.shared())
       .setData(issueFilter.data())
index c1a1090343a1bf946d2256d1e001efb9ff0aeea1..e9a0c5225723a00ed5b08873a2dd474e71763505 100644 (file)
@@ -7,7 +7,7 @@
   <sql id="issueFilterColumns">
     if.id,
     if.name as name,
-    if.user as user,
+    if.user_login as userLogin,
     if.shared as shared,
     if.description as description,
     if.data as data,
 
   <select id="selectByUser" parameterType="String" resultType="IssueFilter">
     select <include refid="issueFilterColumns"/>
-    from issue_filters if WHERE user=#{user}
+    from issue_filters if WHERE user_login=#{user}
   </select>
 
   <insert id="insert" parameterType="IssueFilter" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO issue_filters (name, user, shared, description, data, created_at, updated_at)
-    VALUES (#{name}, #{user}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
+    INSERT INTO issue_filters (name, user_login, shared, description, data, created_at, updated_at)
+    VALUES (#{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
   </insert>
 
   <!-- Oracle -->
     <selectKey order="BEFORE" resultType="Long" keyProperty="id">
       select issue_filters_seq.NEXTVAL from DUAL
     </selectKey>
-    INSERT INTO issue_filters (id, name, user, shared, description, data, created_at, updated_at)
-    VALUES (#{id}, #{name}, #{user}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
+    INSERT INTO issue_filters (id, name, user_login, shared, description, data, created_at, updated_at)
+    VALUES (#{id}, #{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
   </insert>
 
   <update id="update" parameterType="IssueFilter">
     update issue_filters set
     name=#{name},
-    user=#{user},
+    user_login=#{userLogin},
     shared=#{shared},
     description=#{description},
     data=#{data},
index 2a7f15231002b2a94e9cdef8d466dfd9b32cba40..d32ca781b6b4118eb86c17e88d2b49539780237f 100644 (file)
@@ -508,7 +508,7 @@ CREATE TABLE "ISSUE_FILTERS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "NAME" VARCHAR(100) NOT NULL,
   "SHARED" BOOLEAN NOT NULL DEFAULT FALSE,
-  "USER" VARCHAR(40),
+  "USER_LOGIN" VARCHAR(40),
   "DESCRIPTION" VARCHAR(4000),
   "DATA" CLOB(2147483647),
   "CREATED_AT" TIMESTAMP,
@@ -517,7 +517,7 @@ CREATE TABLE "ISSUE_FILTERS" (
 
 CREATE TABLE "ISSUE_FILTER_FAVOURITES" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "USER" VARCHAR(40)  NOT NULL,
+  "USER_LOGIN" VARCHAR(40)  NOT NULL,
   "ISSUE_FILTER_ID" INTEGER NOT NULL,
   "CREATED_AT" TIMESTAMP
 );
@@ -658,6 +658,6 @@ CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES" ("ISSUE_KEY");
 
 CREATE INDEX "ISSUE_FILTERS_NAME" ON "ISSUE_FILTERS" ("NAME");
 
-CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER");
+CREATE INDEX "ISSUE_FILTER_FAVS_USER" ON "ISSUE_FILTER_FAVOURITES" ("USER_LOGIN");
 
 CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS" ("LOGIN");
index 5d5f905716a41ba209b3f14a898a09673ea1c92f..b8619fae88b45d19aa393edcfe7d221da47e9823 100644 (file)
@@ -65,7 +65,7 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase {
 
     IssueFilterDto filterDto = new IssueFilterDto();
     filterDto.setName("Sonar Open issues");
-    filterDto.setUser("michael");
+    filterDto.setUserLogin("michael");
     filterDto.setShared(true);
     filterDto.setDescription("All open issues on Sonar");
     filterDto.setData("statuses=OPEN|componentRoots=org.codehaus.sonar");
@@ -82,7 +82,7 @@ public class IssueFilterDaoTest extends AbstractDaoTestCase {
     IssueFilterDto filterDto = new IssueFilterDto();
     filterDto.setId(2L);
     filterDto.setName("Closed issues");
-    filterDto.setUser("henry");
+    filterDto.setUserLogin("henry");
     filterDto.setShared(false);
     filterDto.setDescription("All closed issues");
     filterDto.setData("statuses=CLOSED");
index 9cc2014c4353f9638b649bbde78a1a2f48294908..cf3bab1115646ddfdaa5a8e73aa2dba84da15e1b 100644 (file)
@@ -3,7 +3,7 @@
   <issue_filters
       id="1"
       name="Sonar Issues"
-      user="stephane"
+      user_login="stephane"
       shared="[true]"
       description="All issues of Sonar"
       data="componentRoots=org.codehaus.sonar"
@@ -13,7 +13,7 @@
   <issue_filters
       id="2"
       name="Open issues"
-      user="michael"
+      user_login="michael"
       shared="[false]"
       description="All open issues"
       data="statuses=OPEN"
index d751cf7d2b707fe7236cbb392e9840b12a6f6fb9..2e1bae52ba33199902504def0d5f840fb17f74e7 100644 (file)
@@ -3,7 +3,7 @@
   <issue_filters
       id="2"
       name="Open issues"
-      user="michael"
+      user_login="michael"
       shared="[false]"
       description="All open issues"
       data="statuses=OPEN"
index ad5a2a52fa0352df4854eae5596c2aab226fdae1..4c33338e7185f06e83da6e97d10f79fc57f245dd 100644 (file)
@@ -3,7 +3,7 @@
   <issue_filters
       id="1"
       name="Sonar Issues"
-      user="stephane"
+      user_login="stephane"
       shared="[true]"
       description="All issues of Sonar"
       data="componentRoots=org.codehaus.sonar"
@@ -13,7 +13,7 @@
   <issue_filters
       id="2"
       name="Open issues"
-      user="michael"
+      user_login="michael"
       shared="[false]"
       description="All open issues"
       data="statuses=OPEN"
@@ -24,7 +24,7 @@
   <issue_filters
       id="3"
       name="Sonar Open issues"
-      user="michael"
+      user_login="michael"
       shared="[true]"
       description="All open issues on Sonar"
       data="statuses=OPEN|componentRoots=org.codehaus.sonar"
index e79b57c103bc4dd3c889cf943ed0ed9f5a65dce9..81741d7d0d03edaaba5b72aa1055b98dce4bdef7 100644 (file)
@@ -3,7 +3,7 @@
   <issue_filters
       id="1"
       name="Sonar Issues"
-      user="stephane"
+      user_login="stephane"
       shared="[true]"
       description="All issues of Sonar"
       data="componentRoots=org.codehaus.sonar"
@@ -13,7 +13,7 @@
   <issue_filters
       id="2"
       name="Open issues"
-      user="michael"
+      user_login="michael"
       shared="[false]"
       description="All open issues"
       data="statuses=OPEN"
@@ -23,7 +23,7 @@
   <issue_filters
       id="3"
       name="Sonar Open issues"
-      user="michael"
+      user_login="michael"
       shared="[true]"
       description="All open issues on Sonar"
       data="statuses=OPEN|componentRoots=org.codehaus.sonar"
index 9a233882bc7b5a13e058d58aacbb1ee94ae1c3f2..a3e7af9bda807e6b8ccf9e0882cb437e4fd13b86 100644 (file)
@@ -3,7 +3,7 @@
   <issue_filters
       id="1"
       name="Sonar Issues"
-      user="stephane"
+      user_login="stephane"
       shared="[true]"
       description="All issues of Sonar"
       data="componentRoots=org.codehaus.sonar"
@@ -13,7 +13,7 @@
   <issue_filters
       id="2"
       name="Closed issues"
-      user="henry"
+      user_login="henry"
       shared="[false]"
       description="All closed issues"
       data="statuses=CLOSED"
index 575d71fc90ba31a25880b0c83a4470488aa3aece..0105c42665162207bd3ce9407a8472113c6c656e 100644 (file)
 class CreateIssueFilters < ActiveRecord::Migration
 
   def self.up
-    create_table 'issue_filters' do |t|
-      t.column 'name',        :string,  :null => false,   :limit => 100
-      t.column 'user',        :string,  :null => true,   :limit => 40
-      t.column 'shared',      :boolean, :null => false,   :default => false
-      t.column 'description', :string,  :null => true,    :limit => 4000
-      t.column 'data',        :text,    :null => true
-      t.timestamps
+    create_table :issue_filters do |t|
+      t.column :name,        :string,  :null => false,   :limit => 100
+      t.column :user_login,  :string,  :null => true,     :limit => 40
+      t.column :shared,      :boolean, :null => false,   :default => false
+      t.column :description, :string,  :null => true,    :limit => 4000
+      t.column :data,        :text,    :null => true
+      t.column :created_at,  :datetime,  :null => true
+      t.column :updated_at,  :datetime,  :null => true
     end
-    add_index 'issue_filters', 'name', :name => 'issue_filters_name'
+    add_index :issue_filters, :name, :name => 'issue_filters_name'
   end
 
 end
\ No newline at end of file
index a45f1005f5747fb8f6eeb5fb219d6c37d2ce2bc6..20527c045b3a304e01e923e127d184687e21ba19 100644 (file)
 class CreateIssueFilterFavourites < ActiveRecord::Migration
 
   def self.up
-    create_table 'issue_filter_favourites' do |t|
-      t.column 'user',            :string,    :null => false,   :limit => 40
-      t.column 'issue_filter_id', :integer,   :null => false
-      t.column 'created_at',      :datetime
+    create_table :issue_filter_favourites do |t|
+      t.column :user_login,      :string,    :null => false,   :limit => 40
+      t.column :issue_filter_id, :integer,   :null => false
+      t.column :created_at,      :datetime
     end
-    add_index 'issue_filter_favourites', 'user', :name => 'issue_filter_favs_user'
+    add_index :issue_filter_favourites, :user_login, :name => 'issue_filter_favs_user'
   end
 
 end